GanttChart.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <!-- 事项甘特图 -->
  2. <template>
  3. <div class="gantt-chart">
  4. <div class="condition-legend-bar">
  5. <Select
  6. class="system-select"
  7. width="217"
  8. :isReadOnly="true"
  9. tipPlace="top"
  10. caption="系统名称:"
  11. v-model="systemId"
  12. :selectdata="systemList"
  13. :placeholder="'请选择'"
  14. @change="getGanttChartData"
  15. />
  16. <div class="legend-container">
  17. <div v-for="(item) in legends" :key="'key_' + item.id" class="item-legend">
  18. <div :style="{'background': item.backgroundColor, 'border-color': item.borderColor}"></div>
  19. <div>{{item.text}}</div>
  20. </div>
  21. <div >
  22. <el-radio-group v-model="timeType">
  23. <el-radio style="line-height: 32px;margin-right: 16px;" label="month">月视图</el-radio>
  24. <el-radio style="line-height: 32px;" label="day">日视图</el-radio>
  25. </el-radio-group>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="main-gantt-container">
  30. <div class="task-title">
  31. <div class="title">任务标题</div>
  32. <div>
  33. <Tree :data="treeData" @openNode="toggleNode" />
  34. </div>
  35. </div>
  36. <div class="chart-container" id="chartContainer" ref="chartContainer">
  37. <div id="ganttContainer"></div>
  38. </div>
  39. <el-dialog :title="detailTitle" :visible.sync="showDetail" width="840px">
  40. <div class="dialog-container">
  41. <div class="row task-status">
  42. <div>
  43. <Task class="icon"/>
  44. <div class="title">任务状态</div>
  45. </div>
  46. <div>进行中</div>
  47. </div>
  48. <div class="row">
  49. <div>
  50. <PlanTime class="icon" />
  51. <div class="title">计划时间</div>
  52. </div>
  53. <div class="info">{{this.ganttDetail.planTime}}</div>
  54. </div>
  55. <div class="row">
  56. <div>
  57. <RealTime class="icon" />
  58. <div class="title">实际执行时间</div>
  59. </div>
  60. <div class="info">{{this.ganttDetail.realTime}}</div>
  61. </div>
  62. <div class="row picture">
  63. <div>
  64. <Picture class="icon" />
  65. <div class="title">照片</div>
  66. </div>
  67. <div>
  68. <div>
  69. <div class="num">12张</div>
  70. <div class="more">查看更多</div>
  71. </div>
  72. <div class="pictrue-container">
  73. <div v-for="(item) in pictures" :key="'id_' + item.id">
  74. <img :src="item.imgSrc" alt="" />
  75. <div class="info">{{item.title}}</div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="row picture">
  81. <div>
  82. <Report class="icon" />
  83. <div class="title">报告</div>
  84. </div>
  85. <div>
  86. <div>
  87. <div class="num">2张</div>
  88. </div>
  89. <div class="pictrue-container">
  90. <div v-for="(item) in reports" :key="'id_' + item.id">
  91. <img :src="item.imgSrc" alt="" />
  92. <div class="info">{{item.title}}</div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="row test-content">
  98. <div>
  99. <Menu class="icon" />
  100. <div class="title">检测内容</div>
  101. </div>
  102. <el-table :data="tableData">
  103. <el-table-column property="time" label="设备简称"></el-table-column>
  104. <el-table-column property="evenType" label="设备编号"></el-table-column>
  105. <el-table-column property="objid" label="设备数"></el-table-column>
  106. <el-table-column property="content" label="空间位置"></el-table-column>
  107. </el-table>
  108. </div>
  109. </div>
  110. </el-dialog>
  111. </div>
  112. </div>
  113. </template>
  114. <script>
  115. import { queryGanttChart, queryGanttDetail } from '../../api/ganttChart';
  116. import { querySystemList, queryDetailData } from '../../api/coreDeviceReport';
  117. import { Tree } from 'meri-design';
  118. import _ from 'lodash';
  119. import moment from 'moment';
  120. // import '../../utils/ganttChart/g.js';
  121. import { GanttChart } from '../../utils/ganttChart/GanttChart.js';
  122. import { parse } from 'path';
  123. import Task from '../../assets/svg/task.svg';
  124. import PlanTime from '../../assets/svg/plan_time.svg';
  125. import RealTime from '../../assets/svg/real_time.svg';
  126. import Picture from '../../assets/svg/picture.svg';
  127. import Report from '../../assets/svg/report.svg';
  128. import Menu from '../../assets/svg/menu.svg';
  129. export default {
  130. data () {
  131. return {
  132. systemList: [], // 系统列表
  133. systemId: '', // 系统名称
  134. legends: [
  135. {id: 1, text: '按时完成', backgroundColor: '#E7E9EA', borderColor: '#C3C7CB'},
  136. {id: 2, text: '未开始/进行中', backgroundColor: 'rgba(91, 143, 249, 0.2)', borderColor: '#5B8FF9'},
  137. {id: 3, text: '逾期完成', backgroundColor: '#FBCE99', borderColor: '#F58300'},
  138. {id: 4, text: '逾期未完成', backgroundColor: '#FBB8B5', borderColor: '#F54E45'},
  139. ], // 图例
  140. timeType: 'month', // 甘特图时间类型
  141. treeData: [], // 树结构数据
  142. // 弹窗相关
  143. showDetail: false, // 弹框显示状态
  144. detailTitle: '', // 弹窗标题
  145. pictures: [
  146. {id: 1, imgSrc: require('../../assets/imgs/analysis/picture.png'), title: '2019年5月高压用具检测报告.jpg'},
  147. {id: 2, imgSrc: require('../../assets/imgs/analysis/picture.png'), title: '2019年5月高压用具检测报告.jpg'},
  148. ], // 照片
  149. reports: [
  150. {id: 1, imgSrc: require('../../assets/imgs/analysis/report_pdf.png'), title: '2019年5月高压用具检测报告.pdf'},
  151. {id: 2, imgSrc: require('../../assets/imgs/analysis/report_word.png'), title: '2019年5月高压用具检测报告.docx'},
  152. ], // 报告
  153. ganttDetail: {}, // 甘特图明细
  154. tableData: [], // 表数据
  155. }
  156. },
  157. components: {
  158. Task,
  159. PlanTime,
  160. RealTime,
  161. Picture,
  162. Report,
  163. Menu
  164. },
  165. computed: {},
  166. mounted() {
  167. this.getSystemList();
  168. },
  169. methods: {
  170. /**
  171. * 获取系统列表数据
  172. */
  173. getSystemList() {
  174. querySystemList().then((res) => {
  175. if (res.result === 'success') {
  176. let data = res.data;
  177. let newData = [];
  178. _.forEach(data, (item) => {
  179. newData.push({
  180. id: item.code,
  181. name: item.name
  182. })
  183. })
  184. this.systemList = newData;
  185. const { query } = this.$route;
  186. if (!_.isEmpty(query) && query.smsxt) {
  187. this.systemId = query.smsxt;
  188. } else {
  189. this.systemId = newData[0].id;
  190. }
  191. this.getGanttChartData();
  192. }
  193. })
  194. },
  195. /**
  196. * 处理请求数据的时间
  197. */
  198. disQueryTime() {
  199. let startTime, endTime;
  200. let curTime = new Date(),
  201. curYear = curTime.getFullYear(),
  202. curMonth = curTime.getMonth() + 1;
  203. if (this.timeType === 'month') {
  204. startTime = `${curYear}0101000000`;
  205. endTime = `${curYear + 1}0101000000`;
  206. } else {
  207. startTime = `${curYear}${curMonth}01000000`;
  208. if (curMonth + 1 > 12) {
  209. endTime = `${curYear + 1}0101000000`;
  210. } else {
  211. endTime = `${curYear}${curMonth + 1}01000000`;
  212. }
  213. }
  214. return [startTime, endTime];
  215. },
  216. /**
  217. * 获取甘特图数据
  218. */
  219. getGanttChartData() {
  220. let time = this.disQueryTime();
  221. let param = {
  222. smsxt: this.systemId,
  223. plazaId: 1000423,
  224. startDate: 20000101000000, // time[0]
  225. endDate: 20200708000000, // time[1]
  226. }
  227. queryGanttChart('/data/base/queryGanttChart', param).then((res) => {
  228. const { dsfList, wbList, zwList, result } = res;
  229. console.log('res', res)
  230. if (result === 'success') {
  231. let newData = [],
  232. data = [wbList, zwList, dsfList],
  233. name = ['维保', '专维', '第三方检测'];
  234. _.forEach(data, (item, index) => {
  235. newData.push({
  236. id: index + 1,
  237. name: name[index],
  238. open: true,
  239. // children: name[index] === '专维'?[] : this.disGanttData(dsfList)
  240. children: this.disGanttData(data[index])
  241. })
  242. })
  243. this.treeData = newData;
  244. let taskData = _.map(_.cloneDeep(newData), (item) => {
  245. return {
  246. id: item.id,
  247. type: item.name,
  248. open: item.open,
  249. dataList: _.map(item.children, (_item) => {
  250. return {
  251. id: _item.id,
  252. title: _item.name,
  253. tasks: _item.originData
  254. }
  255. })
  256. }
  257. })
  258. console.log('taskData', taskData)
  259. let width = this.$refs.chartContainer.offsetWidth;
  260. window.gc = new GanttChart({
  261. chartParentContainer: 'chartContainer',
  262. chartContainer: 'ganttContainer',
  263. viewWidth: width,
  264. cWidth: 3*width,
  265. tasks: taskData,
  266. daysCount: parseInt(3*width/40),
  267. callback: this.showDialog
  268. });
  269. gc.main()
  270. }
  271. })
  272. },
  273. /**
  274. * 处理甘特图数据
  275. */
  276. disGanttData(arr) {
  277. let data = [];
  278. _.forEach(arr, (item) => {
  279. data.push({
  280. id: item.id,
  281. name: item.name,
  282. checked: 'uncheck',
  283. originData: _.map(item.data, (_item) => {
  284. _item.startDate = moment.unix((new Date().getTime() - 1000*60*60*24*7)/1000).format('YYYY-MM-DD HH:mm:ss');
  285. _item.endDate = moment.unix(new Date().getTime()/1000).format('YYYY-MM-DD HH:mm:ss');
  286. _item.description = _item.parentname;
  287. return _item
  288. })
  289. })
  290. })
  291. return data
  292. },
  293. /**
  294. * 展开收起节点
  295. */
  296. toggleNode(status) {
  297. console.log('status', status)
  298. },
  299. /**
  300. * 显示弹窗
  301. */
  302. showDialog(task) {
  303. this.showDetail = true;
  304. this.detailTitle = task._pdata.description;
  305. this.getGanttDetailData();
  306. this.getPictureOrReportData(0);
  307. this.getPictureOrReportData(1);
  308. },
  309. /**
  310. * 获取甘特图详情
  311. */
  312. getGanttDetailData() {
  313. let param = {
  314. plazaId: 1000423,
  315. type: 2,
  316. id: 1078467
  317. }
  318. queryGanttDetail('/data/base/queryGanttChartDetails', param).then((res) => {
  319. const { result, data } = res;
  320. if (result === 'success') {
  321. const { status, planStartDate, planEndDate, realStartDate, realEndDate } = data;
  322. let newData = {
  323. status,
  324. color: '',
  325. planTime: this.dealDetailTime(planStartDate, planEndDate),
  326. realTime: this.dealDetailTime(realStartDate, realEndDate)
  327. }
  328. this.ganttDetail = newData;
  329. }
  330. })
  331. },
  332. /**
  333. * 处理时间
  334. */
  335. dealDetailTime(startTime, endTime) {
  336. let start = moment.unix(startTime / 1000).format('YYYY.MM.DD HH:mm:ss'),
  337. end = moment.unix(endTime / 1000).format('YYYY.MM.DD HH:mm:ss');
  338. return `${start}-${end}`
  339. },
  340. /**
  341. * 获取甘特图的图片/报告详情
  342. */
  343. getPictureOrReportData(type) {
  344. let param = {
  345. file_type: 1,
  346. file_type_id: 1985,
  347. type: type
  348. }
  349. queryDetailData('/data/base/queryFileDetails', param).then((res) => {
  350. console.log('photo', res)
  351. })
  352. }
  353. }
  354. }
  355. </script>
  356. <style lang='less' scoped>
  357. .gantt-chart{
  358. padding-left: 16px;
  359. padding-right: 16px;
  360. padding-top: 12px;
  361. padding-bottom: 16px;
  362. width: 100%;
  363. height: 100%;
  364. background: #fff;
  365. .condition-legend-bar{
  366. margin-bottom: 12px;
  367. display: flex;
  368. justify-content: space-between;
  369. }
  370. .legend-container{
  371. display: flex;
  372. .item-legend{
  373. padding-left: 18px;
  374. position: relative;
  375. font-size: 14px;
  376. color: #646C73;
  377. line-height: 32px;
  378. &:not(:nth-of-type(4)){
  379. margin-right: 20px;
  380. }
  381. >div:first-child{
  382. position: absolute;
  383. left: 0;
  384. top: calc(50% - 6px);
  385. width: 12px;
  386. height: 12px;
  387. border: 1px solid;
  388. }
  389. &:nth-of-type(4){
  390. margin-right: 32px;
  391. }
  392. }
  393. }
  394. .main-gantt-container{
  395. width: 100%;
  396. height: calc(100% - 44px);
  397. background: #F2F5F7;
  398. border:1px solid rgba(239,240,241,1);
  399. border-radius:4px;
  400. display: flex;
  401. .task-title{
  402. width: 404px;
  403. height: 100%;
  404. border-right: 1px solid #EFF0F1;
  405. .title{
  406. padding-left: 32px;
  407. padding-top: 15px;
  408. padding-bottom: 15px;
  409. font-size: 14px;
  410. color: #646C73;
  411. line-height: 19px;
  412. border-bottom: 1px solid #EFF0F1;
  413. }
  414. >div:nth-of-type(2){
  415. max-height: calc(100% - 50px);
  416. overflow: auto;
  417. }
  418. }
  419. .chart-container{
  420. flex: 1;
  421. overflow: hidden;
  422. background: #fff;
  423. }
  424. }
  425. .dialog-container{
  426. max-height: 580px;
  427. overflow: auto ;
  428. .row{
  429. display: flex;
  430. >div:first-child{
  431. margin-right: 24px;
  432. display: flex;
  433. align-items: center;
  434. }
  435. &:not(:last-of-type){
  436. margin-bottom: 14px;
  437. }
  438. .info{
  439. font-size: 14px;
  440. color: #1F2429;
  441. line-height: 22px;
  442. }
  443. }
  444. .icon{
  445. margin-right: 6px;
  446. width: 16px;
  447. }
  448. .title{
  449. width: 84px;
  450. font-size: 14px;
  451. color: #646C73;
  452. line-height: 22px;
  453. font-weight: 400;
  454. }
  455. .task-status>div:nth-of-type(2){
  456. width: 58px;
  457. height: 24px;
  458. background: rgba(91,143,249,0.2);
  459. border-radius: 2px;
  460. color: #5B8FF9;
  461. line-height: 24px;
  462. text-align: center;
  463. }
  464. .picture{
  465. margin-bottom: 19px!important;
  466. >div:first-child{
  467. align-items: baseline;
  468. }
  469. >div:nth-of-type(2){
  470. flex: 1;
  471. }
  472. >div:nth-of-type(2)>div:first-child{
  473. margin-bottom: 12px;
  474. display: flex;
  475. }
  476. .num,
  477. .more{
  478. font-size: 14px;
  479. line-height: 22px;
  480. font-weight: 400;
  481. }
  482. .num{
  483. margin-right: 22px;
  484. color: #1F2429;
  485. }
  486. .more{
  487. color: #025BAA;
  488. cursor: pointer;
  489. }
  490. }
  491. .pictrue-container{
  492. >div{
  493. padding: 10px 16px;
  494. width: 100%;
  495. border-radius:4px;
  496. border:1px solid rgba(233,233,233,1);
  497. display: flex;
  498. align-items: center;
  499. >img{
  500. width: 24px;
  501. margin-right: 15px;
  502. }
  503. }
  504. >div:not(:last-child){
  505. margin-bottom: 8px;
  506. }
  507. }
  508. .test-content{
  509. display: block;
  510. >div:first-child{
  511. margin-bottom: 13px;
  512. }
  513. }
  514. }
  515. }
  516. </style>