From e30795348373e277fe3d27f55ec800c0833e8733 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期一, 11 九月 2023 10:38:09 +0800
Subject: [PATCH] 1.人员管理导入实现

---
 src/views/systemSetting/dataImport.vue |  150 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 124 insertions(+), 26 deletions(-)

diff --git a/src/views/systemSetting/dataImport.vue b/src/views/systemSetting/dataImport.vue
index 6462bdf..3f6df8b 100644
--- a/src/views/systemSetting/dataImport.vue
+++ b/src/views/systemSetting/dataImport.vue
@@ -1,7 +1,7 @@
 <template>
   <div class="" :style="{height:mainHeight+'px'}">
 
-    <div style="display: flex;margin: 20px 10px;">
+    <div style="display: flex;margin: 20px 10px;align-items: center">
 
       <el-select
         v-model="excelCode"
@@ -22,6 +22,7 @@
         type="primary"
         style="margin-left: 20px"
         :disabled="excelCode===''"
+        icon="el-icon-download"
         @click="getExcel"
       >涓嬭浇妯℃澘
       </el-button>
@@ -36,17 +37,36 @@
         type="info"
         style="margin-left: 20px"
         :disabled="excelCode===''"
+        icon="el-icon-refresh"
         @click="reset"
       >閲嶇疆
       </el-button>
 
       <el-button
-        type="primary"
+        type="warning"
         style="margin-left: 20px"
-        :disabled="excelCode===''"
-        @click="submit"
-      >鎻愪氦
+        icon="el-icon-circle-plus-outline"
+        :disabled="excelCode===''||tableData.length===0"
+        @click="addRow"
+      >鏂板琛�
       </el-button>
+
+      <el-button
+        type="success"
+        style="margin-left: 20px"
+        :disabled="excelCode===''||tableData.length===0"
+        icon="el-icon-thumb"
+        @click="submit"
+      >鎻愪氦鏁版嵁
+      </el-button>
+
+      <!--      <el-button-->
+      <!--        type="danger"-->
+      <!--        style="margin-left: 20px"-->
+      <!--        :disabled="excelCode===''||tableData.length===0"-->
+      <!--        @click="batchDel"-->
+      <!--      >鎵归噺鍒犻櫎-->
+      <!--      </el-button>-->
 
     </div>
 
@@ -61,9 +81,9 @@
           :key="i+j"
           :label="i"
         >
-          <!--          height:(mainHeight-180)+'px',-->
           <el-table
-            ref="tableDataRef"
+            v-if="tableData[j].length>0"
+            :ref="'tableDataRef'+j"
             :data="tableData[j]"
             border
             :height="(mainHeight-180)+'px'"
@@ -73,17 +93,24 @@
             style="overflow-y: scroll;"
             highlight-current-row
           >
-            <!--          <el-table-column-->
-            <!--            type="selection"-->
-            <!--            width="55"-->
-            <!--          />-->
+            <!--            @selection-change="handleSelectionChange"-->
+
+            <!--            <el-table-column-->
+            <!--              type="selection"-->
+            <!--              width="55"-->
+            <!--              fixed-->
+            <!--            />-->
             <el-table-column
-              type="index"
               label="搴忓彿"
               width="55"
               fixed
               align="center"
-            />
+              :render-header="indexRender"
+            >
+              <template slot-scope="scope">
+                {{ scope.$index }}
+              </template>
+            </el-table-column>
 
             <el-table-column
               v-for="item of tableHeader[j]"
@@ -196,22 +223,37 @@
                 <div v-else> {{ row[item] }}</div>
               </template>
             </el-table-column>
+
             <el-table-column
               label="鎿嶄綔"
-              width="120"
+              width="55"
+              :render-header="operationRender"
               fixed="right"
-            />
+            >
+              <template slot-scope="{row}">
+                <div class="operationClass" style="padding-left: 10px">
+                  <el-tooltip v-del-tab-index class="item" effect="dark" content="鍒犻櫎" placement="top">
+                    <i
+                      class="el-icon-delete"
+                      :style="{color:$store.state.settings.theme}"
+                      @click="delRow(row)"
+                    />
+                  </el-tooltip>
+                </div>
+              </template>
+            </el-table-column>
           </el-table>
         </el-tab-pane>
       </el-tabs>
 
     </div>
 
-    <!--    <div v-for="(i,j) in tableHeader" :key="i">-->
-    <!--      <el-table :data="tableData[j]" border highlight-current-row style="width: 100%;margin-top:20px;">-->
-    <!--        <el-table-column v-for="item of tableHeader[j]" :key="item" :prop="item" :label="item" />-->
-    <!--      </el-table>-->
-    <!--    </div>-->
+    <el-empty v-if="tableData.length===0" :image-size="500">
+      <el-button type="text">1.璇烽�夋嫨妯℃澘涓嬭浇</el-button>
+      <el-button type="text" style="margin-left: 0;">2.璇峰~鍐欐ā鏉挎暟鎹�</el-button>
+      <el-button type="text" style="margin-left: 0;">3.璇蜂笂浼犳枃浠舵彁浜�</el-button>
+    </el-empty>
+
   </div>
 </template>
 
@@ -219,6 +261,7 @@
 import UploadExcelComponent from '@/components/UploadExcel/index.vue'
 import { DownLoadExcel, ExcelModelCheck, ExcelModelData } from '@/api/Excel'
 import { GroupsPermissions, PostPermissions, PrentOrganization, RolePermissions } from '@/api/GeneralBasicData'
+import { nanoid } from 'nanoid'
 
 export default {
   name: 'UploadExcel',
@@ -290,12 +333,17 @@
           j.鎵�灞炵彮缁勭紪鐮� = j.鎵�灞炵彮缁勭紪鐮�.split(',').filter(e => groupArr.includes(e))
           j['*鎵�灞炵粍缁囩紪鐮�'] = orgArr.includes(j['*鎵�灞炵粍缁囩紪鐮�']) ? j['*鎵�灞炵粍缁囩紪鐮�'] : ''
           j['*鍦ㄨ亴鐘舵��'] = this.statusArr.find(e => e.name === j['*鍦ㄨ亴鐘舵��']).code
+          j.uuid = nanoid()
         })
       }
     },
     async getExcelModelData() {
       const { data: res } = await ExcelModelData()
       this.excelArr = res
+
+      if (window.location.hash.indexOf('?') !== -1) {
+        this.excelCode = window.location.hash.split('?')[1].split('=')[1]
+      }
     },
     async getExcel() {
       const res = await DownLoadExcel({ FileCode: this.excelCode })
@@ -351,25 +399,62 @@
             j.鎵�灞炵彮缁勭紪鐮� = j.鎵�灞炵彮缁勭紪鐮�.join(',')
             j.鎵�灞炶鑹茬紪鐮� = j.鎵�灞炶鑹茬紪鐮�.join(',')
           })
+
+          this.tableData[0].map(item => {
+            delete (item.uuid)
+          })
         }
+
         const data = {
           fileCode: this.excelCode,
           tableData: this.tableData
         }
         // console.log(JSON.stringify(this.tableData))
         ExcelModelCheck(data).then(res => {
-          if (res.code === '200') {
-            this.$notify.success('鎻愪氦鎴愬姛!')
+          if (res.json1.code === '200' && res.json2.code === '200') {
+            this.$notify.success('鏁版嵁鎻愪氦鎴愬姛!')
             this.tableData = []
             this.tableHeader = []
             this.sheetName = []
             this.excelCode = ''
+          } else {
+
           }
         })
       }).catch(() => {
         this.$notify.info('宸插彇娑堟彁浜わ紒')
       })
     },
+
+    addRow() {
+      // 鐢ㄦ埛娓呭崟鏂板琛�
+      if (this.sheetName.indexOf('鐢ㄦ埛娓呭崟') !== -1) {
+        this.tableData[0].unshift({
+          uuid: nanoid(),
+          '*鐢ㄦ埛缂栧彿(鍞竴)': '',
+          '*鐢ㄦ埛濮撳悕': '',
+          '*瀵嗙爜': '',
+          '*鍦ㄨ亴鐘舵��': 'Y',
+          '鎵嬫満鍙�': '',
+          '閭': '',
+          '*鎵�灞炵粍缁囩紪鐮�': '',
+          '鎵�灞炲矖浣嶇紪鐮�': [],
+          '鎵�灞炶鑹茬紪鐮�': [],
+          '鎵�灞炵彮缁勭紪鐮�': []
+        })
+      }
+    },
+    delRow(row) {
+      // 鐢ㄦ埛娓呭崟鍒犻櫎琛�
+      if (this.sheetName.indexOf('鐢ㄦ埛娓呭崟') !== -1) {
+        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('蹇呴』瑕佹湁涓�鏉℃暟鎹紒')
+        }
+      }
+    },
+
     reset() {
       this.tableData = []
       this.tableHeader = []
@@ -414,6 +499,9 @@
       } else if (column.label.indexOf('*') === -1 && rowIndex === 0) {
         string = 'background:#00b0f0;'
       }
+      // else if (rowIndex === 0 && columnIndex === 0) {
+      //   string = 'background:red;color:#fff'
+      // }
       return string + 'padding: 5px 0; fontWeight: 500;'
     },
     cellStyle() {
@@ -421,6 +509,16 @@
         padding: '5px 0'
       }
       return option
+    },
+    indexRender(h, { column }) {
+      return [
+        h('span', { style: 'color:#FFF' }, column.label)
+      ]
+    },
+    operationRender(h, { column }) {
+      return [
+        h('span', { style: 'color:#FFF' }, column.label)
+      ]
     },
     addRedStar(h, { column }) {
       if (column.label.indexOf('*') !== -1) { // 蹇呭~瀛楁
@@ -442,10 +540,10 @@
 
 <style scoped lang="scss">
 //::v-deep .el-table__body-wrapper {
-  //overflow-y: auto;
-  //overflow-x: scroll !important;
-  //height: calc(100% - 34px);
-  //width: 100% !important;
+//overflow-y: auto;
+//overflow-x: scroll !important;
+//height: calc(100% - 34px);
+//width: 100% !important;
 //}
 
 </style>

--
Gitblit v1.9.3