Quellcode durchsuchen

蛇口人员比对子表增加导入导出

WuYi vor 51 Minuten
Ursprung
Commit
6e0b93b3e6
1 geänderte Dateien mit 106 neuen und 1 gelöschten Zeilen
  1. 106 1
      src/views/component/reagent/personnelComparison.vue

+ 106 - 1
src/views/component/reagent/personnelComparison.vue

@@ -13,6 +13,24 @@
             >
             >
               一键生成
               一键生成
             </el-button>
             </el-button>
+            <el-button
+              v-if="isImportExport"
+              type="primary"
+              size="mini"
+              icon="ibps-icon-import"
+              @click="handleImport"
+            >
+              导入
+            </el-button>
+            <el-button
+              v-if="isImportExport"
+              type="primary"
+              size="mini"
+              icon="ibps-icon-sign-out"
+              @click="handleExport"
+            >
+              导出
+            </el-button>
             <!--
             <!--
               <el-button
               <el-button
                 type="primary"
                 type="primary"
@@ -127,13 +145,25 @@
         </el-col>
         </el-col>
       </el-row>
       </el-row>
     </div>
     </div>
+    <import-table
+      :visible="importTableDialogVisible"
+      title="导入"
+      @close="(visible) => (importTableDialogVisible = visible)"
+      @action-event="handleImportTableActionEvent"
+    />
   </div>
   </div>
 </template>
 </template>
 
 
 <script>
 <script>
 import { cloneDeep } from 'lodash'
 import { cloneDeep } from 'lodash'
+import importTable from '@/business/platform/form/formrender/dynamic-form/components/import-table'
+import IbpsImport from '@/plugins/import'
+import IbpsExport from '@/plugins/export'
 
 
 export default {
 export default {
+  components: {
+    importTable
+  },
   props: {
   props: {
     formData: {
     formData: {
       type: Object,
       type: Object,
@@ -153,7 +183,10 @@ export default {
       nodeId: '',
       nodeId: '',
       userList: this.$store.getters.userList,
       userList: this.$store.getters.userList,
       isSyncing: false, // Flag to prevent watch deadlock
       isSyncing: false, // Flag to prevent watch deadlock
-      projectName: setting?.system?.projectName
+      projectName: setting?.system?.projectName,
+      importTableDialogVisible: false,
+      // 人员比对结果子表导入导出开关,全局配置 reagent.rybdjgImportExport
+      isImportExport: setting?.system?.comparison || false
     }
     }
   },
   },
   watch: {
   watch: {
@@ -273,6 +306,78 @@ export default {
     handleSelectionChange(val) {
     handleSelectionChange(val) {
       this.multipleSelection = val
       this.multipleSelection = val
     },
     },
+    // 导入
+    handleImport() {
+      this.importTableDialogVisible = true
+    },
+    // 导出
+    handleExport() {
+      IbpsExport.excel({
+        columns: this.getColumns(),
+        data: this.comparisonData.map((row) => ({
+          ...row,
+          renYuan: this.getUserName(row.renYuan)
+        })),
+        nameKey: 'name',
+        title: '人员比对结果'
+      })
+    },
+    getColumns() {
+      return [
+        { field_name: 'renYuan', label: '比对人员', name: 'renYuan' },
+        { field_name: 'jieGuo3', label: '比对项目', name: 'jieGuo3' },
+        { field_name: 'yangPinBianHao', label: '样品编号', name: 'yangPinBianHao' },
+        { field_name: 'jieGuo1', label: '结果(比对人员)', name: 'jieGuo1' },
+        { field_name: 'jieGuo2', label: '结果(基准人员)', name: 'jieGuo2' },
+        { field_name: 'shiFouYiZhi1', label: '是否一致', name: 'shiFouYiZhi1' },
+        { field_name: 'shiFouTongGuo', label: '是否通过', name: 'shiFouTongGuo' }
+      ]
+    },
+    getKeys(data) {
+      return Array.isArray(data)
+        ? data.reduce((acc, item) => ({ ...acc, [item.label]: item.name }), {})
+        : {}
+    },
+    // 比对人员姓名 → userId,匹配不到时原样保留
+    getUserId(userName) {
+      if (!userName) return ''
+      const name = String(userName).trim()
+      const user = this.userList.find((item) => item.userName === name)
+      return user ? user.userId : name
+    },
+    handleImportTableActionEvent(file, options) {
+      IbpsImport.xlsx(file, options).then(({ header, results }) => {
+        const keys = this.getKeys(this.getColumns())
+        const list = []
+        results.forEach((item) => {
+          const obj = {
+            renYuan: '',
+            jieGuo3: '',
+            yangPinBianHao: '',
+            jieGuo1: '',
+            jieGuo2: '',
+            shiFouYiZhi1: '是',
+            shiFouTongGuo: '通过'
+          }
+          Object.keys(item).forEach((key) => {
+            const field = keys[key]
+            if (!field) return
+            const value = item[key]
+            obj[field] = value === null || value === undefined ? '' : value
+          })
+          obj.shiFouYiZhi1 = obj.shiFouYiZhi1 || '是'
+          obj.shiFouTongGuo = obj.shiFouTongGuo || '通过'
+          obj.renYuan = this.getUserId(obj.renYuan)
+          list.push(obj)
+        })
+        this.comparisonData = list
+        this.importTableDialogVisible = false
+        this.$nextTick(() => {
+          this.$refs.comparison && this.$refs.comparison.doLayout()
+        })
+        this.$message.success('导入成功')
+      })
+    },
     onTongGuoChange(row, index, value) {
     onTongGuoChange(row, index, value) {
       // 找到同一人员同一项目的所有行
       // 找到同一人员同一项目的所有行
       const groupRows = this.comparisonData.filter(
       const groupRows = this.comparisonData.filter(