docAddialog.vue 5.78 KB
<template>
  <div>
    <dee-dialog
      width="70%"
      :title="dialogTitle"
      :dialog-visible="dialogShow"
      @handleClose="cancel"
    >
      <dee-table class="dee-table" selection-row :columns="changeAffectedColumns" :data="changeAffectedData" @clickRowFun="changeNumber" @selection-change="getSelectionList" @cell-data-change="cellDataChange" />
      <div class="flexCenter" style="margin-top: 10px">
        <el-button type="primary" size="small" @click="submit">提交</el-button>
        <el-button size="small" @click="cancel">取消</el-button>
      </div>
    </dee-dialog>
  </div>
</template>

<script>

import { getLinkByNumber, addLinks, showMessage } from '@/utils/util'
export default {
// import引入的组件需要注入到对象中才能使用
  components: {},

  props: {
    rowData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    dialogShow: {
      type: Boolean,
      default: () => false
    },
    dialogTitle: {
      type: String,
      default: () => false
    }
  },

  data() {
    // 这里存放数据
    return {
      changeAffectedColumns: [
        {
          title: '编号',
          key: 'oriNumber'
        },
        {
          title: '名称',
          key: 'oriName'
        },
        {
          title: '版本',
          key: 'oriVersion',
          width: '70px'
        },
        {
          title: '更改方式',
          key: 'changeMode',
          width: '110px',
          component: {
            name: 'el-select',
            options: [
              {
                label: '升版',
                value: '升版'
              },
              {
                label: '换号',
                value: '换号'
              }
            ]
          }
        },
        {
          title: '改后编号',
          key: 'objNumber',
          component: {
            // name: setNumber
          }
        },
        {
          title: '改后版本',
          key: 'objVersion',
          width: '90px'
        },
        {
          title: '更改备注',
          key: 'comments',
          component: {
            name: 'el-input'
          }
        }
      ],
      changeAffectedData: [],
      value: '',
      options: [
        {
          label: '收集相关CAD文档',
          value: 'DxCADDocument'
        },
        {
          label: '收集相关文档',
          value: 'DxDocument'
        },
        {
          label: '收集相关部件',
          value: 'DxPart'
        }
      ],
      /* changeAffectedTools: [
        {
          type: 'icon',
          name: '收集相关CAD文档',
          icon: '/icons/o-CAD.png',
          handler: {
            click: () => {

            }
          }
        },
        {
          type: 'icon',
          name: '收集相关文档',
          icon: '/icons/o-doc.png',
          handler: {
            click: () => {

            }
          }
        },
        {
          type: 'icon',
          name: '收集相关部件',
          icon: '/icons/b-processmaterials.png',
          handler: {
            click: () => {

            }
          }
        }
      ],*/
      selectionList: [],
      links: {
        'DxPart': 'targetUsageLinks',
        'DxDocument': 'partDescribeLinks',
        'DxCADDocument': 'buildRules'
      },
      setChangeAffectedData: []
    }
  },
  // 监听属性 类似于data概念
  computed: {
    imId() {
      return this.$store.getters.getImId
    }
  },
  // 监控data中的数据变化
  watch: {
  },
  // 生命周期 - 创建完成(可以访问当前this实例)
  created() {

  },
  // 生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {

  },
  activated() {
  },
  // 方法集合
  methods: {
    selectType(modeType) {
      this.changeAffectedData = []
      this.setChangeAffectedData = []
      getLinkByNumber(modeType, this.rowData.target.oriNumber, this.links[modeType]).then(res => {
        this.changeAffectedData = JSON.parse(JSON.stringify(res)).map(item => {
          return {
            oriNumber: item.target.number,
            objNumber: '',
            oriName: item.target.name,
            objName: '',
            oriVersion: item.target.versionKey,
            objVersion: '',
            changeMode: '',
            comments: '',
            show: true,
            isOriginal: false,
            id: item.target.id
          }
        })
      })
    },
    getSelectionList(data) {
      this.selectionList = data
    },
    cellDataChange(data) {
      if (data.row.changeMode === '升版') {
        this.$set(data.row, 'objVersion', this.rowData.target.objVersion)
        this.$set(data.row, 'objNumber', '')
      } else {
        this.$set(data.row, 'objVersion', '')
      }
      this.changeAffectedData[data.rowIndex] = data.row
      this.setChangeAffectedData = this.setChangeAffectedData.filter(item => item.id !== data.row.id)
      this.setChangeAffectedData.push(data.row)
    },
    changeNumber(data) {
      this.changeAffectedData[data.index] = data.row
      this.setChangeAffectedData.push(data.row)
    },
    submit() {
      if (!this.setChangeAffectedData.length) return
      const data = JSON.parse(JSON.stringify(this.setChangeAffectedData)).map(item => {
        this.$delete(item, 'show')
        this.$delete(item, 'id')
        item.operator = 'ADD'
        return {
          target: item,
          operator: 'ADD'
        }
      })
      addLinks('DxChangeIM', this.imId, 'imRecordLinks', data).then(res => {
        this.$emit('refresh')
        showMessage('操作成功!', 'success')
        this.cancel()
      })
    },
    cancel() {
      this.$emit('close')
      this.value = ''
      this.changeAffectedData = []
      this.setChangeAffectedData = []
    }
  }
}
</script>
<style lang='scss'>
.flexCenter {
  display: flex;
  justify-content: center;
}
</style>