content.vue 20.9 KB
Newer Older
arvin's avatar
arvin committed
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  <div class="tf-mom-web-content">
    <header>
      <div class="left">
        <el-button
          :disabled="disabledGenerateUpdates"
          @click="generateOrUpdate"
        >装配计划生成及更新
        </el-button>
        <span>提示:双击站位查看站位计划</span>
      </div>
      <div class="right">
        <!-- <el-button @click="exportGantt">导出</el-button> -->
        <div class="legnd">
          <div v-for="item in planStatusData" :key="item.id">
            <span />
            <span>{{ item.label }}</span>
          </div>
        </div>
      </div>
    </header>
22 23 24 25 26
    <main>
      <div v-show="loading" class="load">
        <i class="el-icon-loading" />
        <span>数据加载中···</span>
      </div>
27
      <div :id="onlyUuid" :ref="onlyUuid" class="gannt" style="height: calc(100vh - 100px)" @mouseleave="hideTooltip" />
28 29
    </main>
  </div>
arvin's avatar
arvin committed
30 31 32
</template>

<script>
33 34
// import CsvExportor from 'csv-exportor'
import { post } from '@/utils/http'
arvin's avatar
arvin committed
35 36 37 38 39
export default {
  name: 'TfMomWebContent',

  data() {
    return {
40 41
      disabledGenerateUpdates: true,
      planStatusData: [],
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
      planStatusLoading: true,
      generateOrUpdateShow: false,
      onlyUuid: 'assemblyPlan-gantt',
      ganttAssembling: '',
      tasks: {},
      loading: false,
      // eslint-disable-next-line no-undef
      gantt: Gantt.getGanttInstance(),
      tooltipId: null,
      tooltipLoading: true,
      tooltipData: {},
      planLoading: false,
      openTree: [],
      project: null,
      searchData: {}
arvin's avatar
arvin committed
57 58
    }
  },
59 60
  created() {
  },
arvin's avatar
arvin committed
61
  mounted() {
62 63
    this.initGantt()
    this.getPlanStatus()
64
    this.$bus.$on('getGantData', (data, planData, selectData) => {
65 66
      this.project = planData[0]
      this.disabledGenerateUpdates = false
67 68
      this.searchData = selectData
      this.getAllData(selectData)
69
    })
arvin's avatar
arvin committed
70 71 72
  },

  methods: {
73 74 75 76 77
    hideTooltip() {
      setTimeout(() => {
        this.gantt.ext.tooltips.tooltip.hide()
      }, 100)
    },
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
    // 初始化甘特图
    initGantt() {
      const that = this
      const ganttStm = this.gantt
      ganttStm.plugins({
        tooltip: true
      })
      var zoomConfig = {
        levels: [
          [
            {
              unit: 'month',
              step: 1,
              format: '%Y-%m'
            },
            {
              unit: 'day',
              step: 1,
              format: '%m-%d'
            }
          ],
          [
            {
              unit: 'day',
              step: 1,
              format: '%Y-%m-%d'
            },
            {
              unit: 'hour',
              step: 1,
              format: '%H:%i:%s'
            }
          ]
        ],
        useKey: 'ctrlKey',
        trigger: 'wheel',
        element: function() {
          return ganttStm.$root.querySelector('.gantt_task')
        }
      }
      ganttStm.templates.tooltip_text = function(start, end, task) {
        var html = null
        if (task.$level === 0) {
          html =
            '<b>站位/装配单元:</b> ' +
              task.text +
              '<br><b>工期:</b> ' +
              task.constPeriod +
              '天' +
              '<br/><b>计划开工时间:</b> ' +
              that.formatDate(task.start_date) +
              '<br/><b>计划完工时间:</b> ' +
              that.formatDate(task.end_date)
          //     + '<br><b>齐套率:</b> ' +
          //     task.fitRates || 0
          // '<br><b>状态:</b> ' + task.status
          // '<br><b>问题状态:</b> ' + task.problemStatus
          return html
        } else {
          html =
              '<br><b>站位/装配单元:</b> ' +
              task.text +
              '<br><b>工期:</b> ' +
              task.constPeriod +
              '天' +
              '<br/><b>计划开工时间:</b> ' +
              that.formatDate(task.start_date) +
              '<br/><b>计划完工时间:</b> '
          //     + that.formatDate(task.end_date) +
          //     '<br><b>齐套率:</b> ' +
          //     task.fitRates || 0
          // '<br><b>状态:</b> ' + task.status
          // '<br><b>问题状态:</b> ' + task.problemStatus
          return html
          // }
          // return html
        }
      }
      ganttStm.config.scroll_on_click = true
      ganttStm.templates.link_class = function(link) {
        if (link.isCritical) {
          return 'critical_path'
        }
      }
      ganttStm.templates.rightside_text = function(start, end, task) {
        return '<b></b>' + (task.right_text || ' ')
      }
      ganttStm.templates.progress_text = function(start, end, task) {
        return (
          "<span style='text-align:left;'>" +
          Math.round(task.progress * 100) +
          '% </span>'
        )
      }
      ganttStm.templates.timeline_cell_class = function(task, date) {
        var isWorkTime =
          new Date(date).getDay() === 0 || new Date(date).getDay() === 6
        if (isWorkTime) {
          return 'week_end'
        }
        return ''
      }
      ganttStm.templates.task_class = function(st, end, item) {
        if (item.$level === 0) {
“lixuyan”'s avatar
“lixuyan” committed
182
          return item.status || ''
183 184 185 186 187 188 189
        } else {
          return item.status || ''
        }
      }
      ganttStm.attachEvent('onLinkDblClick', function(id, e) {
        return false
      })
190 191 192 193 194 195 196
      // ganttStm.attachEvent('onAfterTaskUpdate', function(id, item) {
      //   var data = {
      //     id: item.tooltipId,
      //     scheduledStart: that.formatDate(item.start_date)
      //   }
      //   that.updatePlanTime(data)
      // })
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
      // 当分支被打开时触发
      ganttStm.attachEvent('onTaskOpened', function(id) {
        that.openTree.push(Number(id))
      })
      // 当分支关闭时触发
      ganttStm.attachEvent('onTaskClosed', function(id) {
        var arr = that.openTree
        arr.splice(
          arr.findIndex((item) => item === Number(id)),
          1
        )
      })
      ganttStm.attachEvent('onTaskClick', function(id, e) {
        if (e.target.classList[0] === 'seepdf') {
          that.seePdf(id)
        }
        return true
      })
      // ganttStm.attachEvent('onBeforeTaskDrag', function(id, new_item) {
      //   // eslint-disable-next-line eqeqeq
      //   var links = ganttStm.getTableData().data.links.filter(p => p.target == id)
      //   links.forEach(p => {
      //     that.ganttStm.getLink(p.id).lag = 0
      //     that.ganttStm.refreshLink(p.id)
      //   })

      //   // 设置链接可修改
      //   return true
      // })
      // ganttStm.attachEvent('onAfterAutoSchedule', function(id, item) {
      //   that.diffLinks()
      // })

      ganttStm.config.columns = [
        {
          name: 'id',
          label: '节点',
          width: 80,
          align: 'center',
          resize: true,
          template: function(task) {
            return (
              "<span class='gantt_grid_wbs'>" +
              (ganttStm.getWBSCode(task) || '') +
              '</span>'
            )
          }
        },
        // {
        //   name: 'fitRates',
        //   label: '齐套率',
        //   align: 'center',
        //   width: 60,
        //   resize: true
        // },
        // {
        //   name: 'status',
        //   label: '状态',
        //   align: 'center',
        //   width: 80,
        //   resize: true,
        //   template: function(task) {
        //     if (task.$level === 0) {
        //       const state = that.planStateOptions.find(r => r.value === task.status)
        //       return (
        //         "<div class='ca color " +
        //         task.status +
        //         "'>" +
        //         (state && state.label || task.status) +
        //         '</div>'
        //       )
        //     } else {
        //       const state = that.stateOptions.find(r => r.value === task.status)
        //       return (
        //         "<div class='ao color " +
        //         task.status +
        //         "'>" +
        //         (state && state.label || task.status) +
        //         '</div>'
        //       )
        //     }
        //   }
        // },
        // {
        //   name: 'problemStatus',
        //   label: '问题状态',
        //   align: 'center',
        //   width: 80,
        //   resize: true
        // },
        {
          name: 'text',
          label: '站位/装配单元',
          align: 'left',
          width: 200,
          tree: true,
          resize: true,
          template: function(obj) {
            if (obj.$level === 1) {
              return (
                "<div class='seepdf'>" +
                obj.text +
                '</div>'
              )
            }
            return obj.text
          }
        },
        {
          name: 'constPeriod',
          label: '工期(时)',
          align: 'center',
          width: 60,
          resize: true
        },
        {
“lixuyan”'s avatar
“lixuyan” committed
313
          name: 'scheduledStart',
314 315 316 317 318
          label: '计划开工时间',
          align: 'center',
          width: 120,
          resize: true,
          template: function(obj) {
“lixuyan”'s avatar
“lixuyan” committed
319
            return that.formatDate(obj.scheduledStart)
320 321
          }
        },
“lixuyan”'s avatar
“lixuyan” committed
322 323 324 325 326 327 328 329 330 331
        // {
        //   name: 'start_date',
        //   label: '计划开工时间',
        //   align: 'center',
        //   width: 120,
        //   resize: true,
        //   template: function(obj) {
        //     return that.formatDate(obj.start_date)
        //   }
        // },
332
        {
“lixuyan”'s avatar
“lixuyan” committed
333
          name: 'scheduledEnd',
334 335 336 337 338
          label: '计划完工时间',
          align: 'center',
          width: 120,
          resize: true,
          template: function(obj) {
“lixuyan”'s avatar
“lixuyan” committed
339
            return that.formatDate(obj.scheduledEnd)
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
          }
        },
        {
          name: 'predecessors',
          label: '前置节点',
          width: 100,
          align: 'center',
          resize: true,
          template: function(task) {
            var links = task.$target
            var labels = []
            for (var i = 0; i < links.length; i++) {
              var link = ganttStm.getLink(links[i])
              var label = ganttStm.getWBSCode(ganttStm.getTask(link.source))
              labels.push(label)
            }
            return (
              "<span class='gantt_grid_predecessors'>" +
              labels.join(', ') +
              '</span>'
            )
          }
        }
      ]
      ganttStm.config.date_format = '%Y-%m-%d %H:%i:%s'
      ganttStm.config.duration_unit = 'minute'
      ganttStm.config.scale_height = 70
      ganttStm.config.min_column_width = 60
      ganttStm.config.drag_progress = false
      ganttStm.config.drag_resize = false
      ganttStm.config.drag_links = false
      ganttStm.config.details_on_dblclick = false
      ganttStm.config.show_task_cells = true
373
      ganttStm.config.readonly = true
374 375 376 377 378 379 380 381 382 383 384
      // ganttStm.config.auto_scheduling = true
      // ganttStm.config.auto_scheduling_initial = false
      ganttStm.config.open_split_tasks = true
      ganttStm.config.autoscroll = true
      this.$nextTick(() => {
        ganttStm.ext.zoom.init(zoomConfig)
        ganttStm.init(this.$refs[this.onlyUuid])
      })
    },
    // 获取甘特图数据
    getAllData(val) {
385
      // const sortiesId = val.sorties
“lixuyan”'s avatar
“lixuyan” committed
386
      // const sortiesTypeId = val.sorties.split(':').slice(-1)[0]
387
      const params = {
388
        'searchItems': { 'items': [{ 'fieldName': 'extPositionPlans.oRProductionId', 'operator': 'EQ', 'value': val.id }] },
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
        'openProps': [
          {
            'name': 'extProcessExecutorRoutes'
          },
          {
            'name': 'extPositionPlans'
          },
          {
            'name': 'extPositionLinks',
            'openProps': [
              {
                'name': 'target',
                'openProps': [
                  {
                    'name': 'extProcessExecutorRoutes'
                  },
                  {
                    'name': 'wrProduction'
                  }
                ]
              }
            ]
          }],
        'sortItem': [{ 'fieldName': 'serialNumber', 'sortOrder': 'asc' }]
      }
      this.planLoading = true
      this.$api.searchApi('ExtPosition', params).then(res => {
        if (res.items && res.items.content) {
          this.refrehGantt(res.items.content)
        }
      }).catch((err) => {
        console.log(err)
        this.planLoading = false
      })
    },
    refrehGantt(data) {
      if (!data.length) {
426 427 428 429 430
        this.gantt.clearAll()
        this.gantt.parse({
          links: [],
          data: []
        })
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
        return
      }
      const params = {
        links: [],
        data: []
      }
      data.forEach(p => {
        this.addwrProduction(p, params)
        this.addLink(p, params)
        if (p.extPositionLinks) {
          p.extPositionLinks.forEach(t => {
            this.addAO(p, t, params)
            this.addLink(t, params)
          })
        }
      })
      this.$nextTick(() => {
        this.gantt.clearAll()
        this.gantt.parse(params)
        // this.start_date = this.getLongTime()
      })
    },
    addLink(item, params) {
      const links = item.extProcessExecutorRoutes
      if (links) {
        links.forEach(link => {
          params.links.push(this.toLink(link))
        })
      }
    },
    toLink(l) {
      return {
        cid: l.id,
        tid: l.currNodeId,
        source: l.prevNodeId,
        target: l.currNodeId,
        type: '0',
        isCritical: l.isCritical
      }
    },
    addAO(m, p, params) {
“lixuyan”'s avatar
“lixuyan” committed
472
      if (p.target && p.target.wrProduction) {
473 474 475 476 477 478 479 480 481 482 483 484 485
        params.data.push(this.toAO(m, p.target))
      }
    },
    addwrProduction(p, params) {
      if (p.extPositionPlans && p.extPositionPlans[0]) {
        params.data.push(this.toWrProduction(p))
      }
    },
    toWrProduction(p) {
      return {
        type: 'project',
        id: p.id,
        start_date: p.extPositionPlans[0].scheduledStart,
“lixuyan”'s avatar
“lixuyan” committed
486 487
        scheduledStart: p.extPositionPlans[0].scheduledStart,
        scheduledEnd: p.extPositionPlans[0].scheduledEnd,
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
        text: p.serialNumber,
        right_text: p.name,
        isLeaf: true,
        materNo: p.materNo,
        status: p.extPositionPlans[0].planState,
        // 齐套率
        // fitRates: Math.round((p.fitRates || 0) * 1000) / 10 + '%',
        // 问题状态
        // problemStatus: p.problemStatus,
        // progress: Math.round((p.extPositionPlans[0].percentage || 0) * 10) / 1000,
        wrStateCode: p.extPositionPlans[0].planState,
        airModelId: p.extPositionPlans[0].aircraftTypeId,
        sortiesId: p.extPositionPlans[0].aircraftSortiesId,
        constPeriod: Number(p.extPositionPlans[0].costHours) || 0,
        open: this.openTree.includes(p.id),
        duration:
                      (new Date(p.extPositionPlans[0].scheduledEnd) -
                        new Date(p.extPositionPlans[0].scheduledStart)) /
                      1000 /
                      60
      }
    },
    toAO(m, p) {
      return {
        id: p.id,
        start_date: p.wrProduction[0].scheduledStart,
“lixuyan”'s avatar
“lixuyan” committed
514 515
        scheduledStart: p.wrProduction[0].scheduledStart,
        scheduledEnd: p.wrProduction[0].scheduledEnd,
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
        status: p.wrProduction[0].planState,
        text: p.serialNumber,
        parent: m.id,
        right_text: p.name,
        // 齐套率
        // fitRates: Math.round(p.fitRates * 1000) / 10 + '%',
        // 问题状态
        // problemStatus: p.problemStatus,
        tooltipId: p.wrProduction[0].id,
        // progress: p.joExecutePlan[0].percentage,
        constPeriod: Number(p.wrProduction[0].costHours) || 0,
        open: this.openTree.includes(p.id),
        duration:
                        (new Date(p.wrProduction[0].scheduledEnd) -
                          new Date(p.wrProduction[0].scheduledStart)) /
                        1000 /
                        60
      }
    },
535 536 537 538
    /**
     * 装配计划生成及更新
     */
    generateOrUpdate() {
539 540 541 542 543 544 545 546 547 548 549 550 551 552
      if (this.generateOrUpdateShow) {
        this.$message({
          showClose: true,
          message: '正在更新,请稍后再试',
          type: 'warning'
        })
      } else {
        this.generateOrUpdateShow = true
      }
      // 生成
      this.generateProject()
    },
    generateProject() {
      const that = this
553
      post(`/ExtPositionPlan/generateOrUpdate?id=${that.searchData.id}`, {},)
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
      // post(`/ExtPositionPlan/generateOrUpdate?id=220731108341000`, {},)
        .then((res) => {
          if (res) {
            if (res && res.message && res.message.includes('成功')) {
              that.generateOrUpdateShow = false
              that.getAllData(this.searchData)
            }
          } else {
            that.$message({
              showClose: true,
              message: res.message,
              type: 'error'
            })
          }
        })
        .catch((err) => console.error(err))
        .finally(() => {
          that.loading = false
        })
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
    },
    /**
     * 获取站位/装配单元计划状态
     */
    getPlanStatus() {
      this.$utils.getDicListByCode('WRProductionState')
        .then((res) => {
          this.planStatusData = []
          if (res) {
            this.planStatusData = res
          } else {
            this.$message({
              showClose: true,
              message: res.message,
              type: 'error'
            })
          }
        })
        .catch((err) => console.error(err))
        .finally(() => {
          this.$nextTick(() => {
            this.planStatusLoading = false
          })
        })
597 598 599 600 601 602 603
    },
    formatDate(date) {
      var text =
        new Date(date).toLocaleDateString().split('/').join('-') +
        ' ' +
        new Date(date).toTimeString().split(' ')[0]
      return text
604
    }
arvin's avatar
arvin committed
605 606 607 608
  }
}
</script>

“lixuyan”'s avatar
“lixuyan” committed
609
<style lang="scss">
610
.tf-mom-web-content{
611
  header{
612
    display: flex;
613 614 615 616 617 618 619 620 621 622 623
    justify-content: space-between;
    padding: 8px;
    .left {
      > button > span > i {
        margin-left: 10px;
        font-size: 14px;
        font-weight: bold;
        color: rgb(30, 110, 214);
      }

      > span {
624
        margin-left: 20px;
625 626 627 628 629 630 631
        font-size: 10px;
        color: red;
      }
    }
    .right {
      display: flex;
      > .legnd {
632
        display: flex;
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
        position: relative;
        > div {
          align-items: center;
          margin-left: 20px;
          display: flex;
          > span {
            &:first-child {
              display: inline-block;
              width: 22px;
              height: 16px;
              margin-right: 6px;
            }
            &:last-child {
              font-size: 10px;
            }
648
          }
649 650 651 652 653 654 655 656 657 658 659
          &:nth-child(1) > span:first-child {
            background: #59c4e6;
          }
          &:nth-child(2) > span:first-child {
            background: #fcce10;
          }
          &:nth-child(3) > span:first-child {
            background: #97b552;
          }
          &:nth-child(4) > span:first-child {
            background: rgb(230, 193, 31);
660 661 662 663 664
          }
        }
      }
    }
  }
665 666
  main{
    padding: 0 8px;
“lixuyan”'s avatar
“lixuyan” committed
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
    .gannt{
      margin-top: 15px;
      flex-grow: 1;
      height: 20px;
      position: relative;
      > div {
        position: relative;
        height: 100%;
        &.load {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          z-index: 99;
          background-color: #ffffffc7;
          > i {
            font-size: 40px;
            color: #589ce3;
          }
          > span {
            display: block;
          }
        }
      }

      .gantt_link_control {
        z-index: 10;
      }
      .gantt_task_link.critical_path {
        .gantt_line_wrapper {
          z-index: 8;
          div {
            background-color: red;
          }
        }
        .gantt_link_arrow_right {
          border-left-color: red;
        }
      }
      .gantt_tooltip {
        font-size: 14px;
      }
      .gantt_bars_area .gantt_task_line {
        //  background: #F39C4F;
        //  border: 1px solid #F39C4F;
        z-index: 15;
      }
      .gantt_task_link.critical_path {
        > .gantt_line_wrapper > div {
          background-color: #ff1111;
        }
        > .gantt_link_arrow_right {
          border-left-color: #ff1111;
        }
      }
      .gantt_task_line.New {
        background-color: #59c4e6;
        border: 1px solid #59c4e6;
      }
      .gantt_task_line.Finish {
        background-color: #97b552;
        border: 1px solid #97b552;
      }
      .gantt_task_line.Run {
        background-color: #fcce10;
        border: 1px solid #fcce10;
      }
      .gantt_task_cell.week_end {
        background-color: #eff5fd;
      }
      .gantt_task
        .gantt_task_scale
        .gantt_scale_line
        > div:first-child.gantt_scale_cell {
        color: #f3f6f7;
      }
      .gantt_grid_scale,
      .gantt_task_scale,
      .gantt_task_vscroll {
        background-color: #f3f6f7;
      }
      .gantt_grid_scale .gantt_grid_head_cell,
      .gantt_task .gantt_task_scale .gantt_scale_cell {
        color: #2e2e2e;
        font-weight: 700;
        font-size: 14px;
        border-right: 1px solid rgb(206, 206, 206);
      }
    }
760
  }
761
}
arvin's avatar
arvin committed
762 763

</style>