GanttChart.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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.systemId = newData[0].id;
  183. this.systemList = newData;
  184. this.getGanttChartData();
  185. }
  186. })
  187. },
  188. /**
  189. * 处理请求数据的时间
  190. */
  191. disQueryTime() {
  192. let startTime, endTime;
  193. let curTime = new Date(),
  194. curYear = curTime.getFullYear(),
  195. curMonth = curTime.getMonth() + 1;
  196. if (this.timeType === 'month') {
  197. startTime = `${curYear}0101000000`;
  198. endTime = `${curYear + 1}0101000000`;
  199. } else {
  200. startTime = `${curYear}${curMonth}01000000`;
  201. if (curMonth + 1 > 12) {
  202. endTime = `${curYear + 1}0101000000`;
  203. } else {
  204. endTime = `${curYear}${curMonth + 1}01000000`;
  205. }
  206. }
  207. return [startTime, endTime];
  208. },
  209. /**
  210. * 获取甘特图数据
  211. */
  212. getGanttChartData() {
  213. let time = this.disQueryTime();
  214. let param = {
  215. smsxt: this.systemId,
  216. plazaId: 1000423,
  217. startDate: 20000101000000, // time[0]
  218. endDate: 20200708000000, // time[1]
  219. }
  220. queryGanttChart('/data/base/queryGanttChart', param).then((res) => {
  221. const { dsfList, wbList, zwList, result } = res;
  222. console.log('res', res)
  223. if (result === 'success') {
  224. let newData = [],
  225. data = [wbList, zwList, dsfList],
  226. name = ['维保', '专维', '第三方检测'];
  227. _.forEach(data, (item, index) => {
  228. newData.push({
  229. id: index + 1,
  230. name: name[index],
  231. open: true,
  232. children: name[index] === '专维'?[] : this.disGanttData(dsfList)
  233. })
  234. })
  235. this.treeData = newData;
  236. let taskData = _.map(_.cloneDeep(newData), (item) => {
  237. return {
  238. id: item.id,
  239. type: item.name,
  240. open: item.open,
  241. dataList: _.map(item.children, (_item) => {
  242. return {
  243. id: _item.id,
  244. title: _item.name,
  245. tasks: _item.originData
  246. }
  247. })
  248. }
  249. })
  250. console.log('taskData', taskData)
  251. let width = this.$refs.chartContainer.offsetWidth;
  252. window.gc = new GanttChart({
  253. viewWidth: width,
  254. cWidth: 3*width,
  255. tasks: taskData,
  256. chartContainer: 'chartContainer',
  257. daysCount: parseInt(3*width/40),
  258. callback: this.showDialog
  259. });
  260. gc.main()
  261. }
  262. })
  263. },
  264. /**
  265. * 处理甘特图数据
  266. */
  267. disGanttData(arr) {
  268. let data = [];
  269. _.forEach(arr, (item) => {
  270. data.push({
  271. id: item.id,
  272. name: item.name,
  273. checked: 'uncheck',
  274. originData: _.map(item.data, (_item) => {
  275. _item.startDate = moment.unix((new Date().getTime() - 1000*60*60*24*7)/1000).format('YYYY-MM-DD HH:mm:ss');
  276. _item.endDate = moment.unix(new Date().getTime()/1000).format('YYYY-MM-DD HH:mm:ss');
  277. _item.description = _item.parentname;
  278. return _item
  279. })
  280. })
  281. })
  282. return data
  283. },
  284. /**
  285. * 展开收起节点
  286. */
  287. toggleNode(status) {
  288. console.log('status', status)
  289. },
  290. /**
  291. * 显示弹窗
  292. */
  293. showDialog(task) {
  294. this.showDetail = true;
  295. this.detailTitle = task._pdata.description;
  296. this.getGanttDetailData();
  297. this.getPictureOrReportData(0);
  298. this.getPictureOrReportData(1);
  299. },
  300. /**
  301. * 获取甘特图详情
  302. */
  303. getGanttDetailData() {
  304. let param = {
  305. plazaId: 1000664,
  306. type: 1,
  307. id: 1117
  308. }
  309. queryGanttDetail('/data/base/queryGanttChartDetails', param).then((res) => {
  310. console.log('res', res)
  311. const { result, data } = res;
  312. if (result === 'success') {
  313. const { status, planStartDate, planEndDate, realStartDate, realEndDate } = data;
  314. let newData = {
  315. status,
  316. color: '',
  317. planTime: this.dealDetailTime(planStartDate, planEndDate),
  318. realTime: this.dealDetailTime(realStartDate, realEndDate)
  319. }
  320. console.log('newData', newData)
  321. this.ganttDetail = newData;
  322. }
  323. })
  324. },
  325. /**
  326. * 处理时间
  327. */
  328. dealDetailTime(startTime, endTime) {
  329. let start = moment.unix(startTime / 1000).format('YYYY.MM.DD HH:mm:ss'),
  330. end = moment.unix(endTime / 1000).format('YYYY.MM.DD HH:mm:ss');
  331. return `${start}-${end}`
  332. },
  333. /**
  334. * 获取甘特图的图片/报告详情
  335. */
  336. getPictureOrReportData() {
  337. let param = {
  338. file_type: 1,
  339. file_type_id: 1985,
  340. type: 0
  341. }
  342. queryDetailData('/data/base/queryFileDetails', param).then((res) => {
  343. console.log('photo', res)
  344. })
  345. }
  346. }
  347. }
  348. </script>
  349. <style lang='less' scoped>
  350. .gantt-chart{
  351. padding-left: 16px;
  352. padding-right: 16px;
  353. padding-top: 12px;
  354. padding-bottom: 16px;
  355. width: 100%;
  356. height: 100%;
  357. background: #fff;
  358. .condition-legend-bar{
  359. margin-bottom: 12px;
  360. display: flex;
  361. justify-content: space-between;
  362. }
  363. .legend-container{
  364. display: flex;
  365. .item-legend{
  366. padding-left: 18px;
  367. position: relative;
  368. font-size: 14px;
  369. color: #646C73;
  370. line-height: 32px;
  371. &:not(:nth-of-type(4)){
  372. margin-right: 20px;
  373. }
  374. >div:first-child{
  375. position: absolute;
  376. left: 0;
  377. top: calc(50% - 6px);
  378. width: 12px;
  379. height: 12px;
  380. border: 1px solid;
  381. }
  382. &:nth-of-type(4){
  383. margin-right: 32px;
  384. }
  385. }
  386. }
  387. .main-gantt-container{
  388. width: 100%;
  389. height: calc(100% - 44px);
  390. background: #F2F5F7;
  391. border:1px solid rgba(239,240,241,1);
  392. border-radius:4px;
  393. display: flex;
  394. .task-title{
  395. width: 404px;
  396. height: 100%;
  397. border-right: 1px solid #EFF0F1;
  398. .title{
  399. padding-left: 32px;
  400. padding-top: 15px;
  401. padding-bottom: 15px;
  402. font-size: 14px;
  403. color: #646C73;
  404. line-height: 19px;
  405. border-bottom: 1px solid #EFF0F1;
  406. }
  407. }
  408. .chart-container{
  409. flex: 1;
  410. overflow: hidden;
  411. }
  412. }
  413. .dialog-container{
  414. max-height: 580px;
  415. overflow: auto ;
  416. .row{
  417. display: flex;
  418. >div:first-child{
  419. margin-right: 24px;
  420. display: flex;
  421. align-items: center;
  422. }
  423. &:not(:last-of-type){
  424. margin-bottom: 14px;
  425. }
  426. .info{
  427. font-size: 14px;
  428. color: #1F2429;
  429. line-height: 22px;
  430. }
  431. }
  432. .icon{
  433. margin-right: 6px;
  434. width: 16px;
  435. }
  436. .title{
  437. width: 84px;
  438. font-size: 14px;
  439. color: #646C73;
  440. line-height: 22px;
  441. font-weight: 400;
  442. }
  443. .task-status>div:nth-of-type(2){
  444. width: 58px;
  445. height: 24px;
  446. background: rgba(91,143,249,0.2);
  447. border-radius: 2px;
  448. color: #5B8FF9;
  449. line-height: 24px;
  450. text-align: center;
  451. }
  452. .picture{
  453. margin-bottom: 19px!important;
  454. >div:first-child{
  455. align-items: baseline;
  456. }
  457. >div:nth-of-type(2){
  458. flex: 1;
  459. }
  460. >div:nth-of-type(2)>div:first-child{
  461. margin-bottom: 12px;
  462. display: flex;
  463. }
  464. .num,
  465. .more{
  466. font-size: 14px;
  467. line-height: 22px;
  468. font-weight: 400;
  469. }
  470. .num{
  471. margin-right: 22px;
  472. color: #1F2429;
  473. }
  474. .more{
  475. color: #025BAA;
  476. cursor: pointer;
  477. }
  478. }
  479. .pictrue-container{
  480. >div{
  481. padding: 10px 16px;
  482. width: 100%;
  483. border-radius:4px;
  484. border:1px solid rgba(233,233,233,1);
  485. display: flex;
  486. align-items: center;
  487. >img{
  488. width: 24px;
  489. margin-right: 15px;
  490. }
  491. }
  492. >div:not(:last-child){
  493. margin-bottom: 8px;
  494. }
  495. }
  496. .test-content{
  497. display: block;
  498. >div:first-child{
  499. margin-bottom: 13px;
  500. }
  501. }
  502. }
  503. }
  504. </style>