loulijun2021
2023-09-20 8b6eba58c666295de2f764dd7032afd36d7591fc
src/views/systemSetting/dataImport.vue
@@ -128,7 +128,7 @@
                    item.indexOf('所属仓库编码')!==-1||
                    item.indexOf('上级库位编码')!==-1||
                    item.indexOf('规格型号')!==-1||
                    item.indexOf('存货分类编码')!==-1||
                    item.indexOf('存货分类')!==-1||
                    item.indexOf('计量单位/组名称')!==-1
                  "
@@ -505,6 +505,22 @@
          j.uuid = nanoid()
        })
      }
      if (this.sheetName.indexOf('设备类型') !== -1) {
        this.statusArr = [
          { code: '0', name: '正常' },
          { code: '1', name: '停用' }
        ]
        const orgArr = this.orgArr.map(i => i.torg_code)
        this.tableData[0].forEach(j => {
          j.uuid = nanoid()
        })
        this.tableData[1].forEach(j => {
          j['*状态'] = j['*状态'] ? this.statusArr.find(e => e.name === j['*状态']).code : ''
          j['*所属组织编码'] = j['*所属组织编码'] ? (orgArr.includes(j['*所属组织编码']) ? this.findParent([], j['*所属组织编码'], this.orgOptions).reverse() : '') : ''
          j.uuid = nanoid()
        })
      }
    },
    // 提交
    submit() {
@@ -565,6 +581,12 @@
              return this.$message.info(res.message)
            }
          }
          if (this.sheetName.indexOf('设备类型') !== -1) {
            const res = this.handleDeviceListSubmitData()
            if (res.code !== '200') {
              return this.$message.info(res.message)
            }
          }
          const data = {
            fileCode: this.excelCode,
@@ -604,6 +626,15 @@
            if (this.sheetName.indexOf('人员管理') !== -1) {
              this.handlePersonListUploadTemplate(false)
            }
            if (this.sheetName.indexOf('设备类型') !== -1) {
              this.tableData[0].forEach(j => {
                j.uuid = nanoid()
              })
              this.tableData[1].forEach(j => {
                j['*所属组织编码'] = this.findParent([], j['*所属组织编码'], this.orgOptions).reverse()
                j.uuid = nanoid()
              })
            }
          })
        })
        .catch(e => {
@@ -624,7 +655,7 @@
      const orgArr = this.orgArr.map(i => i.torg_code)
      // this.sheetName.indexOf('人员管理')
      // 第一次提交
      // 第一次渲染
      if (isFirstUpload) {
        this.tableData[0].forEach(j => {
          j['所属岗位编码'] = j['所属岗位编码'] ? j['所属岗位编码'].split(',').filter(e => postArr.includes(e)) : []
@@ -636,7 +667,7 @@
        })
      }
      // 非第一次提交
      // 非第一次渲染
      if (!isFirstUpload) {
        this.tableData[0].forEach(j => {
          j.所属岗位编码 = typeof j.所属岗位编码 === 'string' ? j.所属岗位编码.split(',').filter(e => postArr.includes(e)) : []
@@ -991,6 +1022,67 @@
      return { code: '200', message: '成功!' }
    },
    // 处理设备清单提交数据
    handleDeviceListSubmitData() {
      let flag = true
      let msg = ''
      if ([...new Set(this.tableData[0].map(i => i['*设备类型编号(唯一)']))].length !== this.tableData[0].length) {
        return this.$message.info('设备类型编号不能重复!')
      }
      if ([...new Set(this.tableData[1].map(i => i['*设备编号(唯一)']))].length !== this.tableData[1].length) {
        return this.$message.info('设备编号不能重复!')
      }
      this.tableData[0].forEach(j => {
        if (!j['*设备类型编号(唯一)']) {
          flag = false
          msg = '*设备类型编号(唯一)不能为空!'
        }
        if (!j['*设备类型名称']) {
          flag = false
          msg = '*设备类型名称不能为空!'
        }
      })
      this.tableData[1].forEach(j => {
        if (!j['*设备编号(唯一)']) {
          flag = false
          msg = '*设备编号(唯一)不能为空!'
        }
        if (!j['*设备名称']) {
          flag = false
          msg = '*设备名称不能为空!'
        }
        if (!j['*所属组织编码']) {
          flag = false
          msg = '*所属组织编码不能为空!'
        }
        if (!j['*设备类型编码']) {
          flag = false
          msg = '*设备类型编码不能为空!'
        }
        if (!j['*状态']) {
          flag = false
          msg = '*状态不能为空!'
        }
      })
      if (!flag) {
        return { code: '301', message: msg }
      }
      this.tableData[1].forEach(j => {
        j['*所属组织编码'] = j['*所属组织编码'][j['*所属组织编码'].length - 1]
      })
      this.tableData[0].map(item => {
        delete (item.uuid)
      })
      this.tableData[1].map(item => {
        delete (item.uuid)
      })
      return { code: '200', message: '成功!' }
    },
    // parents:用于返回的数组,childNode:要查询的节点,treeData:json树形数据
    findParent(parents, childNode, treeData) {
      // console.log(parents, childNode, treeData, 2)
@@ -1104,10 +1196,10 @@
        })
      }
      // 存货档案
      if (this.sheetName.indexOf('存货类型') !== -1 && this.activeName === '0') {
      if (this.sheetName.indexOf('存货分类') !== -1 && this.activeName === '0') {
        this.tableData[0].unshift({
          uuid: nanoid(),
          '*存货分类编码(唯一)': '',
          '*存货分类编号(唯一)': '',
          '*存货分类名称': '',
          '上级编码': ''
        })
@@ -1115,7 +1207,7 @@
      if (this.sheetName.indexOf('存货') !== -1 && this.activeName === '1') {
        this.tableData[1].unshift({
          uuid: nanoid(),
          '*存货编码(唯一)': '',
          '*存货编号(唯一)': '',
          '*存货名称': '',
          '规格型号': '',
          '*存货分类编码': '',
@@ -1130,6 +1222,25 @@
          '是否委外': '0'
        })
      }
      // 设备清单
      if (this.sheetName.indexOf('设备类型') !== -1 && this.activeName === '0') {
        this.tableData[0].unshift({
          uuid: nanoid(),
          '*设备类型编号(唯一)': '',
          '*设备类型名称': '',
          '描述': ''
        })
      }
      if (this.sheetName.indexOf('设备清单') !== -1 && this.activeName === '1') {
        this.tableData[1].unshift({
          uuid: nanoid(),
          '*设备编号(唯一)': '',
          '*设备名称': '',
          '*所属组织编码': '',
          '设备类型编码': '',
          '*状态': '0'
        })
      }
    },
    delRow(row) {
      // 针对单sheet