docAddialog.vue 5.79 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
<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: 'changeModeCode',
          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: '',
            changeModeCode: '',
            comments: '',
            show: true,
            isOriginal: false,
            id: item.target.id
          }
        })
      })
    },
    getSelectionList(data) {
      this.selectionList = data
    },
    cellDataChange(data) {
      if (data.row.changeModeCode === '升版') {
        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>