view.vue 13 KB
Newer Older
arvin's avatar
arvin committed
1
<template>
2
  <div class="TfMomWebView-model">
arvin's avatar
arvin committed
3
    <div class="search-bar">
arvin's avatar
arvin committed
4 5
      <el-input v-model="AOname" size="small" placeholder="AO(号/名称)" class="input-with-select">
        <el-button slot="append" icon="el-icon-search" @click="search" />
arvin's avatar
arvin committed
6
      </el-input>
arvin's avatar
arvin committed
7

arvin's avatar
arvin committed
8
    </div>
9
    <div :id="ganttElId" :ref="ganttElId" class="gatt" @mouseleave="hideTooltip" />
arvin's avatar
arvin committed
10 11 12 13
  </div>
</template>

<script>
arvin's avatar
arvin committed
14
import CsvExportor from 'csv-exportor'
arvin's avatar
arvin committed
15 16
import config from './config'
import data from './data'
arvin's avatar
arvin committed
17 18
export default {
  name: 'TfMomWebView',
arvin's avatar
arvin committed
19 20 21 22 23 24 25 26 27 28 29
  mixins: [config, data],
  props: {
    node: {
      type: Object,
      default: () => null
    },
    showFlag: {
      type: Boolean,
      default: false
    }
  },
arvin's avatar
arvin committed
30 31
  data() {
    return {
arvin's avatar
arvin committed
32 33
      ganttElId: 'view-gantt',
      currentId: '',
arvin's avatar
arvin committed
34
      ganttData: [],
arvin's avatar
arvin committed
35
      loading: false,
arvin's avatar
arvin committed
36 37 38 39
      // eslint-disable-next-line no-undef
      gantt: Gantt.getGanttInstance(),
      initGanttFlag: false,
      params: null,
arvin's avatar
arvin committed
40 41 42
      AOname: ''
    }
  },
arvin's avatar
arvin committed
43
  computed: {
44

arvin's avatar
arvin committed
45
  },
arvin's avatar
arvin committed
46
  watch: {
arvin's avatar
arvin committed
47

arvin's avatar
arvin committed
48 49 50 51 52 53
  },

  mounted() {

  },
  methods: {
54 55 56 57 58
    hideTooltip() {
      setTimeout(() => {
        this.gantt.ext.tooltips.tooltip.hide()
      }, 100)
    },
arvin's avatar
arvin committed
59 60 61 62
    refreshGantt(val) {
      if (!val || !val.length) {
        return
      }
arvin's avatar
arvin committed
63
      this.params = {
arvin's avatar
arvin committed
64 65 66
        data: [],
        links: []
      }
arvin's avatar
arvin committed
67
      val.forEach((item) => {
arvin's avatar
arvin committed
68
        // 站点数据
arvin's avatar
arvin committed
69 70
        this.params.data.push(this.toExtPostion(item))
        this.addLink(item)
arvin's avatar
arvin committed
71 72 73 74
        // 单元数据
        if (item.extPositionLinks) {
          item.extPositionLinks.forEach(postLink => {
            if (postLink.target) {
arvin's avatar
arvin committed
75 76
              this.params.data.push(this.toUnit(postLink.target, item))
              this.addLink(postLink.target)
arvin's avatar
arvin committed
77

arvin's avatar
arvin committed
78 79 80 81 82 83 84
              // 配置方案
              if (postLink.target.sourceExtProcessUsageLink && postLink.target.sourceExtProcessUsageLink[0]) {
                const ExtCas = postLink.target.sourceExtProcessUsageLink[0].target
                if (ExtCas && ExtCas.sourceExtProcessUsageLink) {
                  ExtCas.sourceExtProcessUsageLink.forEach(AoLink => {
                    // AO AOR
                    if (AoLink.target) {
arvin's avatar
arvin committed
85 86
                      this.params.data.push(this.toAo(AoLink.target, postLink.target))
                      this.addLink(AoLink.target)
arvin's avatar
arvin committed
87 88 89 90 91 92 93 94 95 96 97
                    }
                  })
                }
              }
            }
          })
        }
      })
      this.gantt.parse(this.params)
    },
    toDuration(workHour) {
arvin's avatar
arvin committed
98 99 100
      return (Number(workHour || 0) * 3 * 60) || 0.01
    },
    addLink(item) {
arvin's avatar
arvin committed
101 102 103 104 105 106
      const links = item.extProcessExecutorRoutes
      if (links) {
        links.forEach(link => {
          this.params.links.push(this.toLink(link))
        })
      }
arvin's avatar
arvin committed
107
    },
arvin's avatar
arvin committed
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
    toLink(l) {
      return {
        cid: l.id,
        tid: l.currNodeId,
        source: l.prevNodeId,
        target: l.currNodeId,
        type: '0',
        isCritical: l.isCritical
      }
    },
    toExtPostion(m, p) {
      return {
        id: m.id,
        type: 'project',
        start_date: '2007-01-01',
        text: m.serialNumber,
        parent: p ? p.id : 0,
        edition: m.gaceVersion,
        right_text: m.name,
        duration: this.toDuration(m.workHour)
      }
    },
    toUnit(n, m) {
      return {
        id: n.id,
arvin's avatar
arvin committed
133
        type: 'project',
arvin's avatar
arvin committed
134 135 136 137
        start_date: '2007-01-01',
        text: n.serialNumber,
        edition: n.gaceVersion,
        parent: m.id,
arvin's avatar
arvin committed
138
        parenId: m.id,
arvin's avatar
arvin committed
139
        right_text: n.name,
arvin's avatar
arvin committed
140
        duration: this.toDuration(n.workHour)
arvin's avatar
arvin committed
141 142
      }
    },
arvin's avatar
arvin committed
143
    toAo(n, m) {
arvin's avatar
arvin committed
144
      return {
arvin's avatar
arvin committed
145 146
        id: n.id,
        type: 'task',
arvin's avatar
arvin committed
147
        start_date: '2007-01-01',
arvin's avatar
arvin committed
148
        text: n.serialNumber,
arvin's avatar
arvin committed
149
        parent: m.id,
arvin's avatar
arvin committed
150 151 152 153
        parenId: m.id,
        edition: n.gaceVersion,
        right_text: n.name,
        duration: this.toDuration(n.workHour)
arvin's avatar
arvin committed
154 155 156
      }
    },
    getData() {
157 158 159
      if (this.loading && (this.currentId === this.node.id)) {
        return
      }
arvin's avatar
arvin committed
160
      this.currentId = this.node.id
arvin's avatar
arvin committed
161
      this.gantt.clearAll()
arvin's avatar
arvin committed
162
      if (!this.node || !this.node.children || !this.node.children.length) {
arvin's avatar
arvin committed
163 164
        return
      }
arvin's avatar
arvin committed
165 166
      this.AOname = ''
      this.loading = true
arvin's avatar
arvin committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
      const ids = this.node.children.map(r => r.id)
      const params = {
        searchItems: { 'items': [{ 'fieldName': 'id', 'operator': 'IN', 'value': ids }] },
        'sortItem': [{ 'fieldName': 'serialNumber', 'sortOrder': 'asc' }],
        'openProps': [
          {
            'name': 'extProcessExecutorRoutes'
          }, {
            'name': 'extPositionLinks',
            openProps: [{
              'name': 'target',
              openProps: [{ 'name': 'extProcessExecutorRoutes' }, {
                'name': 'sourceExtProcessUsageLink', // sourceExtProcessUsageLink targetExtProcessUsageLink
                openProps: [{
                  'name': 'target',
                  openProps: [{
                    'name': 'sourceExtProcessUsageLink',
                    openProps: [{
                      'name': 'target',
                      openProps: [{ 'name': 'extProcessExecutorRoutes' }]
                    }]
                  }]
                }]
              }]
            }]
          }
        ]
      }
      // ExtProcessUsageLink ExtPosition
      this.$api.searchApi('ExtPosition', params).then(res => {
        this.refreshGantt(res.items.content || [])
arvin's avatar
arvin committed
198
        this.loading = false
arvin's avatar
arvin committed
199 200
      }).catch(() => {
        this.refreshGantt([])
arvin's avatar
arvin committed
201
        this.loading = false
arvin's avatar
arvin committed
202 203
      })
    },
arvin's avatar
arvin committed
204 205 206 207 208 209 210 211 212 213 214
    showTextBylevel(level) {
      if (level === 0) {
        return '站位'
      }
      if (level === 1) {
        return '装配单元'
      }
      if (level === 2) {
        return 'AO名称'
      }
    },
arvin's avatar
arvin committed
215 216 217
    configLayout() {
      const ganttIns = this.gantt
      const that = this
arvin's avatar
arvin committed
218
      this.usePlugins()
arvin's avatar
arvin committed
219 220 221
      ganttIns.config.scale_height = 70
      ganttIns.config.readonly = true
      ganttIns.templates.tooltip_text = function(start, end, task) {
arvin's avatar
arvin committed
222
        var text = that.showTextBylevel(task.$level)
arvin's avatar
arvin committed
223 224 225 226
        var html =
        '<b >站位:</b> ' +
        task.text +
        '<br><b>工期:</b> ' +
arvin's avatar
arvin committed
227
        Math.round((task.duration || 0) / (3 * 60)) +
arvin's avatar
arvin committed
228 229 230 231 232 233
        '小时<br><b>版本:</b> ' +
         (task.edition || ' ') +
         '<br><b>' + text + ':</b> ' +
         (task.right_text || ' ')
        return html
      }
arvin's avatar
arvin committed
234 235
      ganttIns.config.open_tree_initially = true

arvin's avatar
arvin committed
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 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 373 374 375 376 377 378 379
      ganttIns.config.date_format = '%Y-%m-%d %H:%i:%s'
      ganttIns.config.duration_unit = 'minute'
      ganttIns.config.autofit = false
      ganttIns.config.auto_scheduling_move_projects = true
      ganttIns.config.details_on_dblclick = false
      ganttIns.config.auto_scheduling = true
      ganttIns.config.scroll_on_click = true
      ganttIns.config.start_on_monday = true
      ganttIns.config.min_column_width = 60
      var zoomConfig = {
        levels: [
          [
            {
              unit: 'month',
              // step: 1,
              format: function(date) {
                var month = (new Date(date).getFullYear() - 2007) * 12 + new Date(date).getMonth() + 1
                return month + '月' // ganttAg.date.getWeek(date)
              }
            },
            {
              unit: 'week',
              format: function(date) {
                var newDate = new Date(date)
                var oldDate = new Date('2007/01/01')
                var days = (newDate - oldDate) / (1 * 24 * 60 * 60 * 7 * 1000)
                return Math.ceil(days + 1) + '周' // ganttIns.date.getWeek(date)
              }
            }
          ],
          [
            {
              unit: 'week',
              format: function(date) {
                var newDate = new Date(date)
                var oldDate = new Date('2007/01/01')
                var days = (newDate - oldDate) / (1 * 24 * 60 * 60 * 7 * 1000)
                return Math.ceil(days + 1) + '周' // ganttIns.date.getWeek(date)
              }
            },
            {
              unit: 'day',
              format: function(date) {
                var newDate = new Date(date)
                var oldDate = new Date('2007/01/01')
                var days = (newDate - oldDate) / (1 * 24 * 60 * 60 * 1000)
                return Math.ceil(days + 1) + '日' // ganttIns.date.getWeek(date)
              }
            }
          ],
          [
            {
              unit: 'day',
              format: function(date) {
                var newDate = new Date(date)
                var oldDate = new Date('2007/01/01')
                var days = (newDate - oldDate) / (1 * 24 * 60 * 60 * 1000)
                return Math.ceil(days + 1) + '日' // ganttIns.date.getWeek(date)
              }
            },
            {
              unit: 'hour',
              format: '%H'
            }
          ]
        ],
        startDate: new Date('2007/01/01'),
        useKey: 'ctrlKey',
        trigger: 'wheel',
        element: function() {
          return ganttIns.$root.querySelector('.gantt_task')
        }
      }
      ganttIns.config.columns = [
        {
          name: '',
          label: '节点',
          align: 'left',
          width: 60,
          resize: true,
          template: function(task) {
            return (
              "<span class='gantt_grid_wbs'>" + (ganttIns.getWBSCode(task) ||
            '') + '</span>'
            )
          }
        },
        {
          name: 'text',
          label: '站位号',
          align: 'left',
          width: 160,
          tree: true,
          resize: true
        },
        {
          name: 'edition',
          label: '版本',
          align: 'center',
          width: 50,
          resize: true
        },
        {
          name: 'duration',
          label: '工期(时)',
          align: 'center',
          width: 60,
          resize: true,
          template: function(task) {
            return Math.round((task.duration || 0) / (3 * 60))
          }
        },
        {
          name: 'predecessors',
          label: '前置',
          width: 60,
          align: 'center',
          template: function(task) {
            var links = task.$target
            var labels = []
            for (var i = 0; i < links.length; i++) {
              var link = ganttIns.getLink(links[i])
              var label = ganttIns.getWBSCode(ganttIns.getTask(link.source))
              if (!labels.includes(label)) { labels.push(label) }
            }
            return "<span class='gantt_grid_predecessors'>" + labels.join(', ') + '</span>'
          }
        }
      ]

      ganttIns.templates.link_class = function(link) {
        if (link.isCritical) {
          return 'critical_path'
        }
      }
      ganttIns.templates.rightside_text = function(start, end, task) {
        return '<b></b>' + (task.right_text || ' ')
      }
      ganttIns.templates.task_class = function(st, end, item) {
        return (item.$level === 0 ? 'workday_over' : item.$level === 1 ? 'workday_ok' : '')
      }
      ganttIns.config.drag_resize = false
      this.$nextTick(() => {
        ganttIns.ext.zoom.init(zoomConfig)
arvin's avatar
arvin committed
380
        ganttIns.init(this.ganttElId)
arvin's avatar
arvin committed
381 382 383 384 385 386 387
      })
      ganttIns.attachEvent('onBeforeTaskDisplay', function(id, task) {
        if (task.priority) {
          return false
        }
        return true
      })
arvin's avatar
arvin committed
388 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
    },
    export() {
      var dd = this.gantt.getTableData()
      const tableData = dd.data.data.filter(p => !p.priority).map(p => {
        return {
          _1: Object.values(p).filter(item => item && item.toString().includes('gantt_grid_wbs'))[0]
            .replace("<span class='gantt_grid_wbs'>", '')
            .replace('</span>', ''),
          text1: p.text,
          edition: p.edition || '',
          duration: (p.duration || 0) / (3 * 60),
          predecessors: Object.values(p).filter(item => item && item.toString().includes('gantt_grid_predecessors'))[0]
            .replace("<span class='gantt_grid_predecessors'>", '')
            .replace('</span>', '')
        }
      })
      const header = [
        '节点',
        '站位号',
        '版本',
        '工期(时)',
        '前置'
      ]
      CsvExportor.downloadCsv(tableData, { header }, '架次视图路线.csv')
    },
    search() {
arvin's avatar
arvin committed
414
      const tasks = this.params.data.filter(task => task.$level === 2 && (!this.AOname || task.right_text.includes(this.AOname) || task.text.includes(this.AOname)))
arvin's avatar
arvin committed
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
      const parentTasks = []
      if (tasks.length) {
        tasks.forEach(task => {
          if (task.parent) {
            const pTask = this.params.data.find(t => t.id === task.parent)
            if (pTask) {
              parentTasks.push(pTask)
              const gTask = this.params.data.find(t => t.id === pTask.parent)
              if (gTask) {
                parentTasks.push(gTask)
              }
            }
          }
        })
      }
      this.gantt.clearAll()
      this.gantt.parse({
        data: [...tasks, ...parentTasks]
arvin's avatar
arvin committed
433 434
      })
    }
arvin's avatar
arvin committed
435 436 437 438
  }
}
</script>

arvin's avatar
arvin committed
439 440 441 442 443 444 445 446 447 448
<style lang="scss" >
.TfMomWebView-model{
  .search-bar{
    width: 300px;
    margin-bottom: 8px;
  }
  height: 100%;
  .gatt{
      height: calc(100% - 40px );
  }
arvin's avatar
arvin committed
449 450 451 452
  .critical_path{
    .gantt_line_wrapper {
      div{
        background-color: #e63030;
arvin's avatar
arvin committed
453 454
      }
    }
arvin's avatar
arvin committed
455 456 457 458
    .gantt_link_arrow_right{
      border-left-color: #e63030;
    }
  }
arvin's avatar
arvin committed
459
}
arvin's avatar
arvin committed
460
</style>