CA-part-workflow.vue 18.4 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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
<template>
  <div class="CA-workflow-com">
    <div>
      <div class="participant-title">签审主对象(BOM结构请至产品中心查看)</div>
      <dee-table
        ref="reviewTable"
        class="com-table"
        :columns="tableColums"
        :data="tableData|capitalize(pagination)"
        :pagination="pagination"
        v-bind="workflowNode === 'Activity_1wd0gb5' || 'Activity_0glyimd' ? params : {}"
        style="margin-bottom: 22px"
        @selection-change="selectionChange"
      >
        <dee-tools v-if="workflowNode === 'Activity_1wd0gb5' || 'Activity_0glyimd'" slot="header" :tools="tools" />
      </dee-table>
    </div>
    <dee-add-model-case-dialog
      :show-sub-type="true"
      width="60%"
      title="添加对象"
      :show-dialog="dialogShow"
      :default-data="{latest:'LATEST',modelName: 'DxDocument'}"
      @close="cancel"
      @selection="submit"
    />
  </div>
</template>
<script>
import { saveCAData, getCAWorkflowData, batchCAData, getModelTree } from '@/api/workflow/config'
export default {
  name: 'CAWorkflow',
  filters: {
    capitalize: (list, pagination) => {
      if (!pagination || !pagination.pageSize) {
        return list
      }
      const start = (pagination.currentPage - 1) * pagination.pageSize
      const end = start + pagination.pageSize
      return list.slice(start, end)
    }
  },
  props: {
    basicData: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      pagination: { 'currentPage': 1, 'pageSize': 10, 'pageSizes': [10, 20, 50, 100, 200], 'total': 0 },
      objState: [],
      unitData: [],
      typeData: [],
      form: {
        propForm: {
          number: '',
          name: '',
          subTypeName: 'DxPart'
        },
        propFormData: [
          {
            title: '',
            split: 2,
            data: [
              {
                key: 'subTypeName',
                title: '类型 ',
                component: {
                  name: 'el-select',
                  options: [
                    {
                      label: '部件',
                      value: 'DxPart'
                    },
                    {
                      label: '文档',
                      value: 'DxDocument'
                    },
                    {
                      label: '图档',
                      value: 'DxCADDocument'
                    }
                  ]
                }
              },
              {
                key: 'number',
                title: '编号 ',
                component: {
                  name: 'el-input'
                }
              },
              {
                key: 'name',
                title: '名称 ',
                component: {
                  name: 'el-input'
                }
              }
            ]
          },
          {
            title: '',
            data: [
              {
                title: '',
                key: 'search',
                component: {
                  name: 'custom'
                }
              }
            ]
          },
          {
            title: '',
            data: [
              {
                title: '',
                key: 'table',
                component: {
                  name: 'custom'
                }
              }
            ]
          }
        ]
      },
      dialogShow: false,
      sectionData: [],
      tableData: [],
      params: {
        'selection-row': []
      },
      tools: [
        {
          name: '添加',
          icon: '/icons/c-batchc.png',
          handler: {
            click: () => {
              this.dialogShow = true
            }
          }
        },
        {
          name: '移除',
          icon: '/icons/c-batchd.png',
          handler: {
            click: () => {
              if (this.sectionData.length === 0) {
                this.$message.error('请至少选择一条数据')
              } else {
                this.$confirm('确定要删除选中的数据吗?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  const caRecordLinks = []
                  this.sectionData.forEach(v => {
                    caRecordLinks.push({
                      operator: 'REMOVE',
                      id: v.id,
                      target: {
                        id: v.target.id,
                        operator: 'REMOVE'
                      }
                    })
                  })
                  const params = {
                    id: this.basicData.businessObject.id,
                    operator: 'NO_CHANGE',
                    caRecordLinks: caRecordLinks
                  }
                  batchCAData(params).then(del => {
                    this.tableData = this.tableData.filter(t => {
                      return !caRecordLinks.some(s => {
                        return t.id === s.id
                      })
                    })
                    const pageSize = this.pagination.pageSize
                    this.pagination.total = this.tableData.length
                    let maxPage = parseInt(this.pagination.total / pageSize)
                    const mode = this.pagination.total % pageSize
                    if (mode) {
                      maxPage++
                    }
                    if (maxPage < this.pagination.currentPage) {
                      this.pagination.currentPage = maxPage
                    }
                    this.$message.success('删除成功')
                  }).catch(() => {
                    this.$message.error('删除失败')
                  })
                }
                ).catch(() => {
                  this.$message({
                    type: 'info',
                    message: '已取消删除'
                  })
                })
              }
            }
          }
        }
      ]
    }
  },
  computed: {
    workflowNode() {
      return this.basicData.basicInfo && this.basicData.basicInfo.taskDefinitionKey
    },
    tableColums() {
      let columns = [
        {
          title: '编号',
          key: 'target.objNumber',
          align: 'center',
          component: {
            render: (h, params) => {
              return h('div', [
                h('span', {
                  class: 'link-style',
                  on: {
                    click: () => {
                      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
                      this.$router.push({
wangdanlei's avatar
wangdanlei committed
227 228 229 230 231 232 233 234
                        // path: `/generalDetail/${params.target.afterAffected.id}/${params.target.afterAffectedIdType}/${params.target.afterAffectedIdType}`,
                        // query: {
                        //   layoutId: this.basicData.basicInfo.layoutId,
                        //   title: this.basicData.businessObject.name,
                        //   afterAffectedIdType: params.target.afterAffectedIdType
                        // }
                        path: `/configured-page/cd/${this.$utils.getModelName4dxClassName(params.target.afterAffected.dxClassname)}/${'defaultInfo'}/${params.target.afterAffected.id}`,
                        query: { title: (params.target.afterAffected.name || params.target.afterAffected.id) + '详情' }
wangdanlei's avatar
wangdanlei committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
                      })
                    }
                  }
                }, params.target.objNumber)
              ])
            }
          }
        },
        {
          title: '名称',
          key: 'target.objName',
          align: 'center'
        },
        {
          title: '更改方式',
wangdanlei's avatar
wangdanlei committed
250
          key: 'target.changeMode',
wangdanlei's avatar
wangdanlei committed
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 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
          align: 'center'
        },
        {
          title: '类型',
          key: 'target.afterAffected.subTypeDisplayName',
          align: 'center'
        },
        {
          title: '视图',
          key: 'target.afterAffected.dxView.name',
          align: 'center'
        },
        {
          title: '版本',
          key: 'target.afterAffected.displayVersion',
          align: 'center'
        },
        {
          title: '状态',
          key: 'target.afterAffected.state',
          align: 'center'
        },
        // {
        //   title: '设计部门',
        //   key: 'xxxx',
        //   align: 'center'
        // },
        // {
        //   title: '主管设计',
        //   key: 'xxxx',
        //   align: 'center'
        // },
        {
          title: '数量',
          key: 'target.objAmount',
          align: 'center'
        },
        {
          title: '单位',
          key: 'target.objUnit',
          align: 'center'
        },
        {
          title: '上次修改时间',
          key: 'target.modifyTime',
          align: 'center'
        },
        {
          title: '更改记录',
          key: 'target.afterAffected.name',
          align: 'center',
          component: {
            render: (h, params) => {
              return h('div', [
                h('span', {
                  class: 'link-style',
                  on: {
                    click: () => {
                      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
                      this.$router.push({
                        path: '/cc/newDcr',
                        query: {
                          id: params.target.afterAffected.id,
                          mode: 'edit'
                        }
                      })
                    }
                  }
                }, params.target.afterAffected ? params.target.afterAffected.name : '')
              ])
            }
          }
        }
      ]
      if (this.workflowNode === 'Activity_1hi1uxp') {
        columns.unshift({
          title: '操作',
          key: 'number',
          align: 'center',
          component: {
            render: (h, params) => {
              return h('div', [
                h('img', {
                  attrs: {
                    src: '../icons/components/new/add.png'
                  },
                  style: {
                    width: '20px',
                    marginTop: '6px',
                    cursor: 'pointer'
                  },
                  on: {
                    click: () => {
                      console.log(params)
                      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
                      this.$router.push({
                        path: '/cc/newDcr',
                        query: {
                          id: params.target.afterAffected.id,
                          body: JSON.stringify(params.target.afterAffected),
                          mode: 'new'
                        }
                      })
                    }
                  }
                })
              ])
            }
          }
        })
      // eslint-disable-next-line no-constant-condition
      } else if (this.workflowNode === 'Activity_1wd0gb5' || this.workflowNode === 'Activity_0glyimd') {
        columns = [
          {
            title: '编号',
            key: 'target.objNumber',
            align: 'center',
            component: {
              render: (h, params) => {
                return h('div', [
                  h('span', {
                    class: 'link-style',
                    on: {
                      click: () => {
                        // eslint-disable-next-line vue/no-side-effects-in-computed-properties
                        this.$router.push({
                          path: `/generalDetail/${params.target.afterAffected.id}/${params.target.afterAffectedIdType}/${params.target.afterAffectedIdType}`,
                          query: {
                            layoutId: this.basicData.basicInfo.layoutId,
                            title: this.basicData.businessObject.name
                          }
                        })
                      }
                    }
                  }, params.target.objNumber)
                ])
              }
            }
          },
          {
            title: '名称',
            key: 'target.objName',
            align: 'center'
          },
          {
            title: '更改方式',
wangdanlei's avatar
wangdanlei committed
397
            key: 'target.changeMode',
wangdanlei's avatar
wangdanlei committed
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 426 427 428 429 430 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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 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 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
            align: 'center'
          },
          {
            title: '类型',
            key: 'target.afterAffected.subTypeDisplayName',
            align: 'center'
          },
          {
            title: '视图',
            key: 'target.afterAffected.dxView.name',
            align: 'center'
          },
          {
            title: '版本',
            key: 'target.afterAffected.displayVersion',
            align: 'center'
          },
          {
            title: '状态',
            key: 'target.afterAffected.state',
            align: 'center'
          },
          // {
          //   title: '设计部门',
          //   key: 'xxxx',
          //   align: 'center'
          // },
          // {
          //   title: '主管设计',
          //   key: 'xxxx',
          //   align: 'center'
          // },
          {
            title: '上次修改时间',
            key: 'target.modifyTime',
            align: 'center'
          }
        ]
      }
      return columns
    },
    selectState() {
      return this.workflowNode === 'Activity_1hi1uxp'
    }
  },
  watch: {
    selectState(val) {
      if (val) {
        this.$set(this.params, 'selection-row', [])
      } else {
        this.params = {}
      }
    }
  },
  mounted() {
    this.getContextList()
    this.getCAData()
    this.getModelTree()
  },
  methods: {
    async getContextList() {
      const arr = this.$store.state.dictionaries && this.$store.state.dictionaries.ObjStatus ? this.$store.state.dictionaries.ObjStatus.default : await this.$utils.getDicListByCode('ObjStatus')
      const brr = this.$store.state.dictionaries && this.$store.state.dictionaries.PartUnit ? this.$store.state.dictionaries.PartUnit.default : await this.$utils.getDicListByCode('PartUnit')
      // const brr = this.$store.state.dictionaries && this.$store.state.dictionaries.PartUnit ? this.$store.state.dictionaries.PartUnit.default : await this.$utils.getDicListByCode('PartUnit')
      this.objState = arr
      this.unitData = brr
    },
    handleCancel() {
      this.dialogShow = false
    },
    selectionChange(section) {
      this.sectionData = section
    },
    cancel() {
      this.handleCancel()
    },
    getCAData() {
      const form = {
        'openProps': [
          {
            name: 'dxContext',
            'pageFrom': 1,
            'pageSize': 1000
          },
          {
            'name': 'caRecordLinks',
            'pageFrom': 1,
            'pageSize': 1000,
            'openProps': [
              {
                'name': 'target',
                'pageFrom': 1,
                'pageSize': 1000,
                'openProps': [
                  {
                    'name': 'afterAffected',
                    'pageFrom': 1,
                    'pageSize': 1000
                  }
                ]
              }
            ]
          }
        ],
        'pageFrom': 1,
        'pageSize': 1000,
        'searchItems': {
          'items': [
            {
              'fieldName': 'id',
              'operator': 'EQ',
              'value': this.basicData.businessObject.id
            }
          ],
          'operator': 'AND',
          'children': [

          ]
        }
      }
      getCAWorkflowData(form).then(res => {
        this.tableData = res.items.content[0].caRecordLinks ? res.items.content[0].caRecordLinks : []
        this.tableData = this.tableData.filter(t => {
          return t.target
        })
        // 关联的部件数据被删除则这条数据不展示
        this.tableData = this.tableData.filter(m => !!m.target.afterAffected)
        this.pagination.total = this.tableData.length
        this.tableData.forEach(t => {
          this.$set(t, 'show', true)
          const objState = this.objState.find(s => {
            return s.value === t.target.afterAffected.state
          })
          const unitData = this.unitData.find(o => {
            return o.value === t.target.objUnit
          })
          const typeData = this.typeData.find(f => {
            return f.name === t.target.afterAffected.subTypeName
          })
          t.target.afterAffected.state = t.target.afterAffected.state ? objState ? objState.label : t.target.afterAffected.state : ''
          t.target.objUnit = t.target.objUnit ? unitData ? unitData.label : t.target.objUnit : ''
          t.target.afterAffected.subTypeName = t.target.afterAffected.subTypeName ? typeData ? typeData.displayName : t.target.afterAffected.subTypeName : ''
        })
      })
    },
    submit(val) {
      const caRecordLinks = []
      const targetData = []
      val.forEach(v => {
        targetData.push({
          target: {
            ...v,
            objName: v.name,
            objNumber: v.number
          }
        })
        caRecordLinks.push({
          operator: 'ADD',
          target: {
            afterAffected: {
              ...v
            },
            objName: v.name,
            objNumber: v.number,
wangdanlei's avatar
wangdanlei committed
562
            changeMode: '改状态',
wangdanlei's avatar
wangdanlei committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
            recordType: 2
          }
        })
      })
      const cacheData = this.tableData.filter(t => {
        return targetData.some(a => {
          return t.target.id === a.target.id
        })
      })
      if (cacheData.length > 0) {
        this.$message.error('列表中包含要添加的数据,请重新选择')
      } else {
        const params = {
          id: this.basicData.businessObject.id,
          operator: 'NO_CHANGE',
          caRecordLinks: caRecordLinks
        }
        saveCAData(params).then(res => {
          this.getCAData()
          this.$message.success('添加成功')
        }).catch(() => {
          this.$message.error('添加失败')
        })
        this.handleCancel()
      }
    },
    getModelTree() {
wangdanlei's avatar
wangdanlei committed
590
      getModelTree({ packageId: 14 }).then(res => {
wangdanlei's avatar
wangdanlei committed
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
        this.typeData = this.treeToArray(res.items)
      })
    },
    treeToArray(tree) {
      const arr = []
      const expanded = datas => {
        if (datas && datas.length > 0) {
          datas.forEach(e => {
            arr.push(e)
            expanded(e.children)
          })
        }
      }
      expanded(tree)
      return arr
    }
  }
}
</script>
<style lang="scss">
@import "../styles/variables.scss";
.CA-workflow-com {
  font-size: 13px;
  padding-left: 20px;
  .com-table {
    padding-left: 20px
  }
  .link-style {
    color: $link-color;
    cursor: pointer;
  }
}
</style>