loulijun2021
2023-09-18 ac83abeeafb189a84e9f3ea52b57acee979a353c
src/views/systemSetting/dataImport.vue
@@ -70,13 +70,12 @@
      style="margin: 10px"
    >
      <el-tabs type="border-card">
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleTabClick">
        <el-tab-pane
          v-for="(i,j) in sheetName"
          :key="i+j"
          :label="i"
        >
          <el-table
            v-if="tableData[j].length>0"
            :ref="'tableDataRef'+i"
@@ -120,7 +119,12 @@
                    item.indexOf('手机号')!==-1||
                    item.indexOf('邮箱')!==-1||
                    item.indexOf('名称')!==-1||
                    item.indexOf('描述')!==-1
                    item.indexOf('描述')!==-1||
                    item.indexOf('上级编码')!==-1||
                    item.indexOf('类型编码')!==-1||
                    item.indexOf('联系人')!==-1||
                    item.indexOf('联系方式')!==-1||
                    item.indexOf('地址')!==-1
                  "
                >
                  <el-input v-model="row[item]" placeholder="请输入" />
@@ -337,7 +341,9 @@
      groupArr: [], // 班组
      dialogVisible: false,
      dialogTableData: []
      dialogTableData: [],
      activeName: '0'// tab选中值
    }
  },
@@ -378,15 +384,16 @@
      this.tableHeader = header
      this.sheetName = sheetName
      console.log(this.tableData)
      console.log(this.tableHeader)
      this.activeName = '0'
      // 人员管理导入判断
      if (this.sheetName.indexOf('人员管理') !== -1) {
        this.handlePersonListUploadTemplate(true)
      }
      if (this.sheetName.indexOf('角色管理') !== -1 || this.sheetName.indexOf('班组管理') !== -1) {
      if (this.sheetName.indexOf('角色管理') !== -1 || this.sheetName.indexOf('班组管理') !== -1 ||
        this.sheetName.indexOf('岗位管理') !== -1
      ) {
        this.statusArr = [
          { code: 'Y', name: '正常' },
          { code: 'N', name: '停用' }
@@ -396,6 +403,24 @@
          j.uuid = nanoid()
        })
      }
      if (this.sheetName.indexOf('往来单位') !== -1) {
        this.statusArr = [
          { code: 'Y', name: '正常' },
          { code: 'N', name: '停用' }
        ]
        this.tableData[0].forEach(j => {
          j.uuid = nanoid()
        })
        this.tableData[1].forEach(j => {
          j['*状态'] = j['*状态'] ? this.statusArr.find(e => e.name === j['*状态']).code : ''
          j.uuid = nanoid()
        })
      }
      // console.log(this.sheetName)
      // console.log(this.tableData)
      // console.log(this.tableHeader)
    },
    // 提交
    submit() {
@@ -420,6 +445,18 @@
          }
          if (this.sheetName.indexOf('班组管理') !== -1) {
            const res = this.handleGroupListSubmitData()
            if (res.code !== '200') {
              return this.$message.info(res.message)
            }
          }
          if (this.sheetName.indexOf('岗位管理') !== -1) {
            const res = this.handlePostListSubmitData()
            if (res.code !== '200') {
              return this.$message.info(res.message)
            }
          }
          if (this.sheetName.indexOf('往来单位类型') !== -1 && this.sheetName.indexOf('往来单位') !== -1) {
            const res = this.handleContactUnitListSubmitData()
            if (res.code !== '200') {
              return this.$message.info(res.message)
            }
@@ -618,7 +655,94 @@
      return { code: '200', message: '成功!' }
    },
    // 处理岗位管理提交数据
    handlePostListSubmitData() {
      let flag = true
      let msg = ''
      if ([...new Set(this.tableData[0].map(i => i['*岗位编号(唯一)']))].length !== this.tableData[0].length) {
        return this.$message.info('编码不能重复!')
      }
      this.tableData[0].forEach(j => {
        if (!j['*岗位编号(唯一)']) {
          flag = false
          msg = '*岗位编号(唯一)'
        }
        if (!j['*岗位名称']) {
          flag = false
          msg = '*岗位名称'
        }
        if (!j['*状态']) {
          flag = false
          msg = '*状态'
        }
      })
      if (!flag) {
        return { code: '301', message: msg + '不能为空!' }
      }
      this.tableData[0].map(item => {
        delete (item.uuid)
      })
      return { code: '200', message: '成功!' }
    },
    // 处理往来单位提交数据
    handleContactUnitListSubmitData() {
      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 = '*往来单位类型名称不能为空!'
        }
        if (j['*往来单位类型编号(唯一)'] === 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 (!flag) {
        return { code: '301', message: msg }
      }
      this.tableData[0].map(item => {
        delete (item.uuid)
      })
      this.tableData[1].map(item => {
        delete (item.uuid)
      })
      return { code: '200', message: '成功!' }
    },
    // 获取模板
    async getExcelModelData() {
      const { data: res } = await ExcelModelData()
@@ -695,6 +819,36 @@
          '描述': ''
        })
      }
      //  岗位管理新增行
      if (this.sheetName.indexOf('岗位管理') !== -1) {
        this.tableData[0].unshift({
          uuid: nanoid(),
          '*岗位编号(唯一)': '',
          '*岗位名称': '',
          '*状态': 'Y',
          '描述': ''
        })
      }
      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(),
          '*往来单位编号(唯一)': '',
          '*往来单位名称': '',
          '*状态': 'Y',
          '*往来单位类型编码': '',
          '联系人': '',
          '联系方式': '',
          '地址': ''
        })
      }
    },
    delRow(row) {
      // 针对单sheet
@@ -705,9 +859,24 @@
          return this.$message.info('必须要有一条数据!')
        }
      }
      // 针对多sheet
      // 针对两个 sheet
      if (this.sheetName.length === 2) {
        if (this.activeName === '0') {
          if (this.tableData[0].length > 1) {
            return this.tableData[0].splice(this.tableData[0].findIndex(i => i.uuid === row.uuid), 1)
          } else {
            return this.$message.info('必须要有一条数据!')
          }
        }
        if (this.activeName === '1') {
          if (this.tableData[1].length > 1) {
            return this.tableData[1].splice(this.tableData[1].findIndex(i => i.uuid === row.uuid), 1)
          } else {
            return this.$message.info('必须要有一条数据!')
          }
        }
      }
    },
    reset() {
      this.tableData = []
      this.tableHeader = []