loulijun2021
2023-09-14 f6379a640d6c580582ecf01b6293a5ed334f428d
1.导入数据   正在修改bug
已修改3个文件
140 ■■■■■ 文件已修改
src/components/UploadExcel/index.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/materialManager/inventoryList.vue 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/systemSetting/dataImport.vue 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/UploadExcel/index.vue
@@ -81,14 +81,14 @@
        const reader = new FileReader()
        reader.onload = e => {
          const data = e.target.result
          const workbook = XLSX.read(data, { type: 'array' })
          const workbook = XLSX.read(data, { type: 'array', cellDates: true })
          let worksheet = []
          const header = []
          const results = []
          workbook.SheetNames.forEach((item, index) => {
            worksheet = workbook.Sheets[item]
            header.push(this.getHeaderRow(worksheet))
            results.push(XLSX.utils.sheet_to_json(worksheet))
            results.push(XLSX.utils.sheet_to_json(worksheet, { defval: null, raw: false }))
          })
          this.excelData.sheetName = workbook.SheetNames
          // console.log(header)
src/views/materialManager/inventoryList.vue
@@ -863,6 +863,9 @@
    dialogVisibleConfirm() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          if (!(this.dialogForm.isPurchase || this.dialogForm.isSale || this.dialogForm.isMadeSelf || this.dialogForm.isMaterial || this.dialogForm.isMadeRequest)) {
            return this.$message.info('存货属性不能为空!')
          }
          this.dialogForm.isPurchase = this.dialogForm.isPurchase ? '1' : '0'
          this.dialogForm.isSale = this.dialogForm.isSale ? '1' : '0'
          this.dialogForm.isMadeSelf = this.dialogForm.isMadeSelf ? '1' : '0'
src/views/systemSetting/dataImport.vue
@@ -81,9 +81,10 @@
          :key="i+j"
          :label="i"
        >
          <!--          :key="tableKey"-->
          <el-table
            v-if="tableData[j].length>0"
            :ref="'tableDataRef'+j"
            :ref="'tableDataRef'+i"
            :data="tableData[j]"
            border
            :height="(mainHeight-180)+'px'"
@@ -119,13 +120,17 @@
                <div
                  v-if="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="请输入" />
                </div>
                <div
                  v-else-if="item.indexOf('用户姓名')!==-1"
                >
                  <el-input v-model="row[item]" placeholder="请输入" />
                </div>
@@ -223,21 +228,6 @@
                    :props="defaultProps"
                    :show-all-levels="false"
                  />
                  <!--                  <el-select-->
                  <!--                    v-model="row[item]"-->
                  <!--                    style="width: 100%;"-->
                  <!--                    placeholder="请选择"-->
                  <!--                    filterable-->
                  <!--                    clearable-->
                  <!--                  >-->
                  <!--                    <el-option-->
                  <!--                      v-for="item in orgArr"-->
                  <!--                      :key="item.torg_code"-->
                  <!--                      :label="item.torg_name"-->
                  <!--                      :value="item.torg_code"-->
                  <!--                    />-->
                  <!--                  </el-select>-->
                </div>
                <div v-else-if="item.indexOf('数据权限')!==-1">
                  <el-cascader
@@ -333,7 +323,9 @@
        { code: 'LEVEL', name: '本级' },
        { code: 'PERSON', name: '本人' },
        { code: 'CUSTOM', name: '自定义' }
      ]// 数据范围
      ], // 数据范围
      tableKey: new Date().getTime()
    }
  },
@@ -366,9 +358,17 @@
      return false
    },
    async handleSuccess({ results, header, sheetName }) {
      if (results[0].length === 0) {
        return this.$message.info('表格数据不能为空!')
      }
      this.tableData = results
      this.tableHeader = header
      this.sheetName = sheetName
      console.log(this.tableData)
      console.log(this.tableHeader)
      // this.tableHeader
      // 人员管理导入判断
      if (this.sheetName.indexOf('人员管理') !== -1) {
@@ -380,20 +380,29 @@
        const roleArr = this.roleArr.map(i => i.rolecode)
        const groupArr = this.groupArr.map(i => i.usergroupcode)
        const orgArr = this.orgArr.map(i => i.torg_code)
        this.tableData[this.sheetName.indexOf('人员管理')].forEach(j => {
        // this.sheetName.indexOf('人员管理')
        this.tableData[0].forEach(j => {
          // j.所属岗位编码 = typeof j.所属岗位编码 === 'undefined' ? new Set() : j.所属岗位编码.split(',').filter(e => postArr.includes(e))
          // j.所属角色编码 = typeof j.所属角色编码 === 'undefined' ? ''.split(',') : j.所属角色编码.split(',').filter(e => roleArr.includes(e))
          // j.所属班组编码 = typeof j.所属班组编码 === 'undefined' ? ''.split(',') : j.所属班组编码.split(',').filter(e => groupArr.includes(e))
          j.所属岗位编码 = j.所属岗位编码.split(',').filter(e => postArr.includes(e))
          j.所属角色编码 = j.所属角色编码.split(',').filter(e => roleArr.includes(e))
          j.所属班组编码 = j.所属班组编码.split(',').filter(e => groupArr.includes(e))
          j['*所属组织编码'] = orgArr.includes(j['*所属组织编码']) ? j['*所属组织编码'] : ''
          j['*在职状态'] = this.statusArr.find(e => e.name === j['*在职状态']).code
          j['所属岗位编码'] = j['所属岗位编码'] ? j['所属岗位编码'].split(',').filter(e => postArr.includes(e)) : []
          j['所属角色编码'] = j['所属角色编码'] ? j['所属角色编码'].split(',').filter(e => roleArr.includes(e)) : []
          j['所属班组编码'] = j['所属班组编码'] ? j['所属班组编码'].split(',').filter(e => groupArr.includes(e)) : []
          j['*所属组织编码'] = j['*所属组织编码'] ? (orgArr.includes(j['*所属组织编码']) ? j['*所属组织编码'] : '') : ''
          j['*在职状态'] = j['*在职状态'] ? this.statusArr.find(e => e.name === j['*在职状态']).code : 'Y'
          // j['手机号'] = j['手机号'] ? j['手机号'] : ''
          // j['邮箱'] = j['邮箱'] ? j['邮箱'] : ''
          // j['*密码'] = j['*密码'] ? j['*密码'] : ''
          // j['*用户姓名'] = j['*用户姓名'] ? j['*用户姓名'] : ''
          // j['*用户编号(唯一)'] = j['*用户编号(唯一)'] ? j['*用户编号(唯一)'] : ''
          j.uuid = nanoid()
        })
        console.log(this.tableData[0])
        // console.log(JSON.stringify(this.tableData[0]))
        // this.tableKey = 'asd'
        // this.$forceUpdate()
      }
      if (this.sheetName.indexOf('角色管理') !== -1) {
@@ -404,13 +413,14 @@
        this.tableData[0].forEach(j => {
          // j.所属岗位编码 = j.所属岗位编码.split(',').filter(e => postArr.includes(e))
          console.log(j['数据权限'], 1) // 级联多选回显  待研究  下次写
          // console.log(j['数据权限'], 1) // 级联多选回显  待研究  下次写
          j['数据范围'] = this.powerArr.find(e => e.name === j['数据范围']).code
          j['*状态'] = this.statusArr.find(e => e.name === j['*状态']).code
          j.uuid = nanoid()
        })
      }
    },
    // 获取模板
    async getExcelModelData() {
      const { data: res } = await ExcelModelData()
@@ -426,11 +436,6 @@
      window.location.href = res.data
    },
    submit() {
      // console.log(this.excelCode)
      // console.log(JSON.stringify(this.sheetName))
      // console.log(JSON.stringify(this.tableHeader))
      // console.log(JSON.stringify(this.tableData))
      this.$confirm('是否确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
@@ -472,9 +477,12 @@
            }
            this.tableData[0].forEach(j => {
              j.所属岗位编码 = j.所属岗位编码.join(',')
              j.所属班组编码 = j.所属班组编码.join(',')
              j.所属角色编码 = j.所属角色编码.join(',')
              // j['所属岗位编码'] = typeof j['所属岗位编码'] === 'string' ? j['所属岗位编码'] : j['所属岗位编码'].join(',')
              // j['所属班组编码'] = typeof j['所属班组编码'] === 'string' ? j['所属班组编码'] : j['所属班组编码'].join(',')
              // j['所属角色编码'] = typeof j['所属角色编码'] === 'string' ? j['所属角色编码'] : j['所属角色编码'].join(',')
              j['所属岗位编码'] = j['所属岗位编码'].join(',')
              j['所属班组编码'] = j['所属班组编码'].join(',')
              j['所属角色编码'] = j['所属角色编码'].join(',')
              j['*所属组织编码'] = j['*所属组织编码'][j['*所属组织编码'].length - 1]
            })
@@ -487,36 +495,49 @@
            fileCode: this.excelCode,
            tableData: this.tableData
          }
          // console.log(JSON.stringify(this.tableData))
          ExcelModelCheck(data).then(res => {
            if (res.json1.code === '301' || res.json1.code === '300') {
              if (this.sheetName.indexOf('人员管理') !== -1) {
                const postArr = this.postArr.map(i => i.postcode)
                const roleArr = this.roleArr.map(i => i.rolecode)
                const groupArr = this.groupArr.map(i => i.usergroupcode)
                const orgArr = this.orgArr.map(i => i.torg_code)
                this.tableData[0].forEach(j => {
                  j.所属岗位编码 = j.所属岗位编码.split(',').filter(e => postArr.includes(e))
                  j.所属角色编码 = j.所属角色编码.split(',').filter(e => roleArr.includes(e))
                  j.所属班组编码 = j.所属班组编码.split(',').filter(e => groupArr.includes(e))
                  // j['*在职状态'] = this.statusArr.find(e => e.name === j['*在职状态']).code
                  // j['*所属组织编码'] = j['*所属组织编码'][j['*所属组织编码'].length - 1]
                  j['*所属组织编码'] = this.findParent([], j['*所属组织编码'], this.orgOptions).reverse()
                  j.uuid = nanoid()
                })
              }
              return this.$message.error(res.json1.message)
          ExcelModelCheck(data).then(res => {
            // 返回的json1、json2、json3   json1为模板校验、json2为数据校验、json3为导入数据库校验(可能会有系统报错产生)
            if (res.json1.code !== '200' && res.json2 === null && res.json3 === null) {
              this.$message.error(res.json1.message)
            }
            if (res.json1.code === '200' && res.json2 !== '200' && res.json3 === null) {
              this.$message.error(res.json2.message)
            }
            if (res.json1.code === '200' && res.json2 === '200' && res.json3 !== '200') {
              this.$message.error(res.json3.message)
            }
            if (res.json1.code === '200' && res.json2.code === '200') {
            // if (res.json1.code !== '200' && res.json2.code !== '200') {
            // if (res.json2.code !== '200') {
            if (this.sheetName.indexOf('人员管理') !== -1) {
              const postArr = this.postArr.map(i => i.postcode)
              const roleArr = this.roleArr.map(i => i.rolecode)
              const groupArr = this.groupArr.map(i => i.usergroupcode)
              const orgArr = this.orgArr.map(i => i.torg_code)
              this.tableData[0].forEach(j => {
                j.所属岗位编码 = j.所属岗位编码.split(',').filter(e => postArr.includes(e))
                j.所属角色编码 = j.所属角色编码.split(',').filter(e => roleArr.includes(e))
                j.所属班组编码 = j.所属班组编码.split(',').filter(e => groupArr.includes(e))
                // j['*在职状态'] = this.statusArr.find(e => e.name === j['*在职状态']).code
                // j['*所属组织编码'] = j['*所属组织编码'][j['*所属组织编码'].length - 1]
                j['*所属组织编码'] = this.findParent([], j['*所属组织编码'], this.orgOptions).reverse()
                j.uuid = nanoid()
              })
            }
            // return this.$message.error(res.json1.message + ',' + res.json2.message)
            // }
            if (res.json1.code === '200' && res.json2 === '200' && res.json3 === '200') {
              this.$notify.success('数据提交成功!')
              this.tableData = []
              this.tableHeader = []
              this.sheetName = []
              this.excelCode = ''
            } else {
              this.$notify.success('数据提交失败!')
              this.$notify.error('数据提交失败!')
            }
          })
        })