From d82fea569f9bb487364d667cdf3af626cf06f20e Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期三, 02 四月 2025 17:24:18 +0800
Subject: [PATCH] fix: bug

---
 src/views/Home/BatchChange.vue |  103 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 74 insertions(+), 29 deletions(-)

diff --git a/src/views/Home/BatchChange.vue b/src/views/Home/BatchChange.vue
index f966bba..98a6a85 100644
--- a/src/views/Home/BatchChange.vue
+++ b/src/views/Home/BatchChange.vue
@@ -111,6 +111,7 @@
   ProTableV2,
   ProFormUpload,
   UploadUserFile,
+  XLSXUtils,
 } from '@bole-core/components';
 import * as insuranceOrderServices from '@/services/api/InsuranceOrder';
 import * as insureBatchBillServices from '@/services/api/InsureBatchBill';
@@ -121,6 +122,7 @@
 import { useQuery, useQueryClient } from '@tanstack/vue-query';
 import { paginateList } from '@/utils';
 import dayjs from 'dayjs';
+import _ from 'lodash';
 
 defineOptions({
   name: 'BatchChange',
@@ -216,25 +218,35 @@
       url: response.path,
       insurePolicyId: id,
     };
-    let checkRes = await insureBatchBillServices.importCheckBatchAddOrSubOrderData(params, {
-      getResponse: true,
-      responseType: 'blob',
-    });
-    if (checkRes?.data?.size) {
+    let res = await insureBatchBillServices.importBatchAddOrSubOrderData(params);
+    if (res?.error.length > 0) {
       Message.tipMessage('瀛樺湪閿欒鏁版嵁锛屾槸鍚﹀鍑猴紵')
         .then(() => {
-          downloadFile(checkRes.data, `閿欒浜哄憳鍚嶅崟`, 'xlsx');
+          XLSXUtils.exportToXLSX({
+            workbookDataList: res?.error,
+            fileName: '閿欒浜哄憳鍚嶅崟',
+            workbookHeaderMap: {
+              changeFlag: '鎵规敼鏍囧織',
+              insuranceScheme: '鏂规浠g爜',
+              name: '琚繚闄╀汉濮撳悕',
+              certType: '璇佷欢绫诲瀷',
+              idNumber: '璇佷欢鍙风爜',
+              age: '骞撮緞',
+              phoneNumber: '鎵嬫満鍙�',
+              workType: '鑱屼笟/宸ョ',
+              gender: '鎬у埆',
+              birthDay: '鍑虹敓鏃ユ湡',
+              remark: '澶囨敞',
+            },
+          });
         })
         .catch(() => {
-          // getList(paginationState.pageIndex);
+          state.staffList = _.uniqBy(res.addOrSub, 'idNumber');
+          getList();
         });
-    } else {
-      let res = await insureBatchBillServices.importBatchAddOrSubOrderData(params);
-      if (res?.addOrSub?.length) {
-        state.staffList = res.addOrSub;
-        getList();
-      }
     }
+    state.staffList = _.uniqBy(res.addOrSub, 'idNumber');
+    getList();
   } catch (error) {}
 }
 async function handleUploadReplace(response: UploadUserFile) {
@@ -243,25 +255,54 @@
       url: response.path,
       insurePolicyId: id,
     };
-    let checkRes = await insureBatchBillServices.importCheckBatchUpdateOrderData(params, {
-      getResponse: true,
-      responseType: 'blob',
-    });
-    if (checkRes?.data?.size) {
+    // let checkRes = await insureBatchBillServices.importCheckBatchUpdateOrderData(params, {
+    //   getResponse: true,
+    //   responseType: 'blob',
+    // });
+    // if (checkRes?.data?.size) {
+    //   Message.tipMessage('瀛樺湪閿欒鏁版嵁锛屾槸鍚﹀鍑猴紵')
+    //     .then(() => {
+    //       downloadFile(checkRes.data, `閿欒浜哄憳鍚嶅崟`, 'xlsx');
+    //     })
+    //     .catch(() => {
+    //       // getList(paginationState.pageIndex);
+    //     });
+    // } else {
+    //   let res = await insureBatchBillServices.importBatchUpdateOrderData(params);
+    //   if (res?.update?.length) {
+    //     state.staffList = res.update;
+    //     getList();
+    //   }
+    // }
+    let res = await insureBatchBillServices.importBatchUpdateOrderData(params);
+    if (res?.error.length > 0) {
       Message.tipMessage('瀛樺湪閿欒鏁版嵁锛屾槸鍚﹀鍑猴紵')
         .then(() => {
-          downloadFile(checkRes.data, `閿欒浜哄憳鍚嶅崟`, 'xlsx');
+          XLSXUtils.exportToXLSX({
+            workbookDataList: res?.error,
+            fileName: '閿欒浜哄憳鍚嶅崟',
+            workbookHeaderMap: {
+              orginName: '鍘熻淇濅汉濮撳悕',
+              orginIdNumber: '鍘熻淇濅汉璇佷欢鍙风爜',
+              name: '琚繚闄╀汉濮撳悕',
+              certType: '璇佷欢绫诲瀷',
+              idNumber: '璇佷欢鍙风爜',
+              phoneNumber: '鎵嬫満鍙�',
+              workType: '鑱屼笟/宸ョ',
+              gender: '鎬у埆',
+              age: '骞撮緞',
+              birthDay: '鍑虹敓鏃ユ湡',
+              remark: '澶囨敞',
+            },
+          });
         })
         .catch(() => {
-          // getList(paginationState.pageIndex);
+          state.staffList = _.uniqBy(_.uniqBy(res.update, 'idNumber'), 'orginIdNumber');
+          getList();
         });
-    } else {
-      let res = await insureBatchBillServices.importBatchUpdateOrderData(params);
-      if (res?.update?.length) {
-        state.staffList = res.update;
-        getList();
-      }
     }
+    state.staffList = _.uniqBy(_.uniqBy(res.update, 'idNumber'), 'orginIdNumber');
+    getList();
   } catch (error) {}
 }
 
@@ -292,12 +333,16 @@
       Message.errorMessage('璇峰厛涓婁紶浜哄憳鍚嶅崟');
       return;
     }
+    let _addInsStaffList = _.uniqBy(state.staffList, 'idNumber');
     let params: API.InsureBatchBillInput = {
       insurancePolicyId: id,
       effectTime: state.form.time,
-      addInsStaffList: state.staffList.filter((x) => x.changeFlag.includes('澧炲姞')),
-      updateInsStaffList: state.staffList.filter((x) => x.changeFlag.includes('鏇挎崲')),
-      delInsStaffList: state.staffList.filter((x) => x.changeFlag.includes('鍒犻櫎')),
+      addInsStaffList: _addInsStaffList.filter((x) => x.changeFlag.includes('澧炲姞')),
+      updateInsStaffList: _.uniqBy(
+        _addInsStaffList.filter((x) => x.changeFlag.includes('鏇挎崲')),
+        'orginIdNumber'
+      ),
+      delInsStaffList: _addInsStaffList.filter((x) => x.changeFlag.includes('鍒犻櫎')),
     };
     let res = await insureBatchBillServices.addOrUpdateInsureBatchBill(params);
     if (res) {

--
Gitblit v1.9.1