craftRoute.vue 9.13 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 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
<template>
  <div>
    <dee-table ref="historyTable" selection-row :options="options" :columns="columns" :data="tableData" @selection-change="selectionChange">
      <div slot="header" style="display: flex;width: 100%;justify-content: space-between;">
        <dee-tools v-if="linkId" :tools="tools" mode="normal" />
      </div>
    </dee-table>
    <dee-dialog :title="dialogTitle" :dialog-visible="dialogVisible" width="45%" @handleClose="cancel">
      <div style="display: flex;font-size: 14px">
        <div>
          <span>路线用于:</span>
        </div>
        <div style="margin-left: 15px">
          <div>{{ form.router }}</div>
          <div style="margin:30px 0 20px 50px">{{ form.router1 }}</div>
        </div>
      </div>
      <dee-table ref="historyTable" selection-row :options="options" :columns="dialogColumns" :data="dialogTableData" @cell-data-change="cellDataChange" @selection-change="dialogSelectionChange">
        <div v-if="dialogTitle==='添加'" slot="header" style="display: flex;width: 100%;justify-content: space-between;">
          <dee-tools :tools="dialogTools" mode="normal" />
        </div>
      </dee-table>
      <div class="flexCenter" style="margin-top: 20px">
        <el-button type="primary" size="small" @click="save">保存</el-button>
        <el-button size="small" @click="dialogVisible=false">取消</el-button>
      </div>
    </dee-dialog>
  </div>
</template>

<script>
import { getProcessRouteByUsagelinkId, addProcessRoute, deleteRoute } from '@/api/parts'
export default {
  name: 'CraftRoute',
  displayName: '工艺路线',
  modelRelationObjs: ['DxPart'],
  props: {
    businessData: {
      type: Object,
      default: () => null
    },
    basicData: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      options: {},
      index: 0,
      columns: [
        {
          title: '操作',
          key: 'operate',
          align: 'center',
          hideTip: true,
          width: '60px',
          component: {
            show: true,
            name: 'EditTableRow',
            props: {
              btns: [
                {
                  operation: '编辑',
                  handleClick: (row, index) => {
                    this.dialogTitle = '编辑'
                    this.dialogTableData = [row]
                    this.dialogVisible = true
                  },
                  icon: '/icons/c-edit.png',
                  showFun: (row) => {
                    return true
                  }
                }
              ]
            }
          }
        },
        {
          title: '装配编号',
          key: 'assemblyNumber'
        },
        {
          title: '装配版本',
          key: 'assemblyVersion'
        },
        {
          title: '视图',
          key: 'view'
        },
        {
          title: '路线',
          key: 'path'
        },
        {
          title: '上次修改时间',
          key: 'modifyTime'
        }
      ],
      tableData: [],
      dialogColumns: [
        {
          title: '路线',
          key: 'path',
          component: {
            name: 'el-input',
            size: 'small'
          }
        }
      ],
      dialogTableData: [],
      tools: [
        {
          type: 'icon',
          name: '添加',
          icon: '/icons/c-add.png',
          handler: {
            click: () => {
              this.dialogTitle = '添加'
              this.dialogVisible = true
            }
          }
        },
        {
          type: 'icon',
          name: '移除',
          icon: '/icons/c-delete.png',
          handler: {
            click: () => {
              if (!this.selection.length) return
              const id = this.selection.map(x => x.id)
              deleteRoute(id.join(',')).then(res => {
                this.getTableData()
                this.$utils.showMessage('操作成功!', 'success')
              })
            }
          }
        }
      ],
      dialogTools: [
        {
          type: 'icon',
          name: '添加',
          icon: '/icons/c-add.png',
          handler: {
            click: () => {
              this.dialogTableData.push({
                path: '',
                id: this.index++,
                show: true
              })
            }
          }
        },
        {
          type: 'icon',
          name: '移除',
          icon: '/icons/c-delete.png',
          handler: {
            click: () => {
              this.dialogSelection.forEach(item => {
                this.dialogTableData = this.dialogTableData.filter(x => x.id !== item.id)
              })
            }
          }
        }
      ],
      dialogTitle: '添加',
      dialogVisible: false,
      form: {
        router: '',
        router1: ''
      },
      formData: [
        {
          title: '路线用于',
          split: 1,
          data: [
            {
              title: '',
              key: 'router',
              component: {
                name: 'readable'
              }
            },
            {
              title: '',
              key: 'router1',
              component: {
                name: 'readable'
              },
              handler: {
                change: (value) => {
                  this.formData[0].data = this.formData[0].data.filter(x => x.key !== 'newViewParentId')
                  this.$set(this.form, 'newViewParentId', '')
                  if (!value) {
                    this.formData[0].data.push(this.newViewItem)
                    this.$set(this.formData[0].data.find(x => x.key === 'newViewParentId').component, 'options', [{ label: this.viewNode.data.$label, value: this.viewNode.data.id }])
                    this.$set(this.form, 'newViewParentId', this.viewNode.data.id)
                  }
                }
              }
            }
          ]
        }
      ],
      selection: [],
      dialogSelection: []
    }
  },
  computed: {
    linkId() {
      return this.businessData && this.businessData.nodeData && this.businessData.nodeData.id
    },
    parentNumber() {
      return this.businessData && this.businessData.nodeData && this.businessData.nodeData.source && this.businessData.nodeData.source.number
    },
    parentDisplayVersion() {
      return this.businessData && this.businessData.nodeData && this.businessData.nodeData.source && this.businessData.nodeData.source.displayVersion
    },
    parentDxViewName() {
      return this.businessData && this.businessData.nodeData && this.businessData.nodeData.source && this.businessData.nodeData.source.dxView && this.businessData.nodeData.source.dxView.name
    }
  },
  watch: {
    businessData: {
      deep: true,
      immediate: true,
      handler(val) {
        if (!val || !val.nodeData || !val.nodeData.id) {
          this.clearTable()
          return
        }
        this.init()
      }
    }
  },
  // 生命周期 - 创建完成(访问当前this实例)
  created() {},
  // 生命周期 - 挂载完成(访问DOM元素)
  mounted() {},
  methods: {
    clearTable() {
      this.form = {}
      this.tableData = []
    },
    init() {
      this.form = {
        router: `${this.businessData.nodeData.source.number} ${this.businessData.nodeData.source.name} ${this.businessData.nodeData.source.displayVersion}(${this.businessData.nodeData.source.dxView ? this.businessData.nodeData.source.dxView.name : ''})  ${this.businessData.nodeData.source.dxContext ? this.businessData.nodeData.source.dxContext.name : ''}`,
        router1: ` ${this.basicData.number} ${this.basicData.name} ${this.basicData.displayVersion}(${this.basicData['dxView.name'] || ''})  ${this.basicData['dxContext.name'] || ''}`
      }
      this.getTableData()
    },
    selectionChange(data) {
      this.selection = data
    },
    dialogSelectionChange(data) {
      this.dialogSelection = data
    },
    cellDataChange({ rowIndex, row }) {
      this.$set(this.dialogTableData, rowIndex, row)
    },
    save() {
      if (this.dialogTableData.length) {
        const list = []
        JSON.parse(JSON.stringify(this.dialogTableData)).map(x => {
          if (this.dialogTitle === '添加') {
            list.push({ path: x.path })
          } else {
            this.$delete(x, 'show')
            this.$delete(x, 'view')
            this.$delete(x, 'assemblyNumber')
            this.$delete(x, 'assemblyVersion')
            list.push(x)
          }
        })
        addProcessRoute({ list: list, usagelinkId: this.linkId }).then(res => {
          this.$utils.showMessage('操作成功!', 'success')
          this.getTableData()
          this.cancel()
        })
      }
    },
    cancel() {
      this.dialogVisible = false
      this.dialogTableData = []
    },
    getTableData() {
      if (!this.linkId) {
        return
      }
      getProcessRouteByUsagelinkId(this.linkId).then(res => {
        this.tableData = []
        if (res.items.length) {
          this.tableData = res.items.map(x => {
            x.assemblyNumber = this.parentNumber
            x.assemblyVersion = this.parentDisplayVersion
            x.view = this.parentDxViewName
            x.show = true
            return x
          })
        }
      })
    }
  }
}
</script>
<style lang="scss">
/* @import url(); 引入css类 */

</style>