GanttChart.vue 15 KB

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