From 6bde59eb680d1978aad3f7270d7816210c559cfc Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期二, 01 四月 2025 19:54:04 +0800
Subject: [PATCH] fix: bug

---
 src/views/Home/BatchChange.vue |  207 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 154 insertions(+), 53 deletions(-)

diff --git a/src/views/Home/BatchChange.vue b/src/views/Home/BatchChange.vue
index fb48b4d..7de55f0 100644
--- a/src/views/Home/BatchChange.vue
+++ b/src/views/Home/BatchChange.vue
@@ -1,11 +1,11 @@
 <template>
-  <LoadingLayout :loading="state.loading">
+  <LoadingLayout>
     <AppScrollContainer>
       <ChunkCell title="1">
         <template #title>
           <div class="batch-change-title">
-            <el-text style="margin-right: 20px">{{ `淇濆崟鍙凤細${'958585860689'}` }}</el-text>
-            <el-text>{{ `鎶曚繚浜猴細${'浜哄姏鏃犲咖'}` }}</el-text>
+            <el-text style="margin-right: 20px">{{ `淇濆崟鍙凤細${insureBillNo ?? ''}` }}</el-text>
+            <el-text>{{ `鎶曚繚浜猴細${insurerName ?? ''}` }}</el-text>
           </div>
         </template>
         <ProForm :model="state.form" ref="formRef" label-width="120px">
@@ -21,6 +21,7 @@
                   type="date"
                   value-format="YYYY-MM-DD"
                   placeholder="璇烽�夋嫨鏃ユ湡"
+                  :disabled-date="disabledDate"
                 ></ProFormDatePicker>
               </ProFormItemV2>
             </ProFormColItem>
@@ -29,15 +30,16 @@
             <ProFormColItem :span="8">
               <ProFormItemV2 label="" prop="url" label-width="0">
                 <ProFormUpload
-                  v-model:file-url="state.form.url"
+                  v-model:file-url="state.form.addOrReduceUrl"
                   :limit="1"
                   :limitFileSize="10"
-                  accept="xlsx,xls"
+                  accept="xlsx"
                   :showTip="false"
                   :on-success="handleUploadAddOrReduce"
+                  :disabled="urlDisabled"
                 >
                   <template #default>
-                    <el-button type="primary">鍔犲噺浜�</el-button>
+                    <el-button type="primary" :disabled="urlDisabled">鍔犲噺浜�</el-button>
                     <el-button link type="primary" @click.stop="DownloadAddOrReducePersonTemplate"
                       >涓嬭浇妯℃澘</el-button
                     >
@@ -50,15 +52,16 @@
             <ProFormColItem :span="8">
               <ProFormItemV2 label="" prop="url" label-width="0">
                 <ProFormUpload
-                  v-model:file-url="state.form.url"
+                  v-model:file-url="state.form.replaceUrl"
                   :limit="1"
                   :limitFileSize="10"
-                  accept="xlsx,xls"
+                  accept="xlsx"
                   :showTip="false"
                   :on-success="handleUploadReplace"
+                  :disabled="urlDisabled"
                 >
                   <template #default>
-                    <el-button type="primary">鏇挎崲浜�</el-button>
+                    <el-button type="primary" :disabled="urlDisabled">鏇挎崲浜�</el-button>
                     <el-button link type="primary" @click.stop="downloadReplacePersonTemplate"
                       >涓嬭浇妯℃澘</el-button
                     >
@@ -108,13 +111,18 @@
   ProTableV2,
   ProFormUpload,
   UploadUserFile,
+  XLSXUtils,
 } from '@bole-core/components';
 import * as insuranceOrderServices from '@/services/api/InsuranceOrder';
 import * as insureBatchBillServices from '@/services/api/InsureBatchBill';
-import { downloadFileByUrl, Message, OrderInputType } from '@bole-core/core';
+import { downloadFile, downloadFileByUrl, Message, OrderInputType } from '@bole-core/core';
 import { InsuranceAddOrReduceTempPath, InsuranceChangeTempPath } from '@/constants';
 import { useRouteView } from '@/hooks';
 import { FormInstance } from 'element-plus';
+import { useQuery, useQueryClient } from '@tanstack/vue-query';
+import { paginateList } from '@/utils';
+import dayjs from 'dayjs';
+import _ from 'lodash';
 
 defineOptions({
   name: 'BatchChange',
@@ -123,7 +131,7 @@
 const column: API.CustomModuleColumnDto[] = [
   {
     id: '1',
-    enCode: 'name',
+    enCode: 'changeFlag',
     name: '鎵规敼绫诲瀷',
   },
   {
@@ -133,32 +141,32 @@
   },
   {
     id: '3',
-    enCode: 'name',
+    enCode: 'idNumber',
     name: '韬唤璇佸彿',
   },
   {
     id: '4',
-    enCode: 'idNumber',
+    enCode: 'workType',
     name: '闆囧憳宸ョ',
   },
   {
     id: '5',
-    enCode: 'idNumber',
+    enCode: 'gender',
     name: '鎬у埆',
   },
   {
     id: '6',
-    enCode: 'idNumber',
+    enCode: 'age',
     name: '骞撮緞',
   },
   {
     id: '7',
-    enCode: 'idNumber',
+    enCode: 'birthDay',
     name: '鍑虹敓鏃ユ湡',
   },
   {
     id: '8',
-    enCode: 'idNumber',
+    enCode: 'phoneNumber',
     name: '鎵嬫満鍙风爜',
   },
 ];
@@ -166,48 +174,43 @@
 const route = useRoute();
 const { closeViewPush } = useRouteView();
 const id = route.params.id as string;
+const insurerName = route.query.insurerName as string;
+const insureBillNo = route.query.insureBillNo as string;
+const effectEndTime = route.query.effectEndTime as string;
 const BaseState = {
   loading: true,
   form: {
     time: '',
-    url: [] as UploadUserFile[],
+    addOrReduceUrl: [] as UploadUserFile[],
+    replaceUrl: [] as UploadUserFile[],
   },
+  staffList: [] as any[],
 };
 
 const state = reactive({ ...BaseState });
 
-const {
-  getDataSource: getBatchRefundInfoDetail,
-  proTableProps,
-  paginationState,
-  extraParamState,
-  reset,
-} = useTable(
-  async ({ pageIndex, pageSize }, extraParamState) => {
-    try {
-      let params: API.QueryInsuranceOrderPageInput = {
-        pageModel: {
-          rows: pageSize,
-          page: pageIndex,
-          orderInput: extraParamState.orderInput,
-        },
-        condition: extraParamState.keyWord,
-        // insurePolicyOperateHistoryId: id,
-      };
-      let res = await insuranceOrderServices.getInsuranceOrderPage(params, {
-        showLoading: !state.loading,
-      });
-      return res;
-    } catch (error) {}
-  },
-  {
-    defaultExtraParams: {
-      keyWord: '',
-      orderInput: [{ property: 'id', order: OrderInputType.Asc }],
-    },
-    columnsRenderProps: {},
-  }
-);
+const disabledDate = computed(() => {
+  return (time: Date) => {
+    return dayjs(time).isBefore(dayjs(), 'day') || dayjs(time).isAfter(dayjs(effectEndTime), 'day');
+  };
+});
+
+const urlDisabled = computed(() => {
+  return state.form.addOrReduceUrl.length > 0 || state.form.replaceUrl.length > 0;
+});
+
+const { getDataSource: getList, proTableProps } = useTable(({ pageIndex, pageSize }) => {
+  try {
+    return Promise.resolve({
+      pageModel: {
+        rows: pageSize,
+        page: pageIndex,
+        totalCount: state.staffList.length,
+      },
+      data: paginateList(state.staffList, pageIndex, pageSize),
+    });
+  } catch (error) {}
+});
 
 async function handleUploadAddOrReduce(response: UploadUserFile) {
   try {
@@ -216,6 +219,34 @@
       insurePolicyId: id,
     };
     let res = await insureBatchBillServices.importBatchAddOrSubOrderData(params);
+    if (res?.error.length > 0) {
+      Message.tipMessage('瀛樺湪閿欒鏁版嵁锛屾槸鍚﹀鍑猴紵')
+        .then(() => {
+          XLSXUtils.exportToXLSX({
+            workbookDataList: res?.error,
+            fileName: '閿欒浜哄憳鍚嶅崟',
+            workbookHeaderMap: {
+              changeFlag: '鎵规敼鏍囧織',
+              insuranceScheme: '鏂规浠g爜',
+              name: '琚繚闄╀汉濮撳悕',
+              certType: '璇佷欢绫诲瀷',
+              idNumber: '璇佷欢鍙风爜',
+              age: '骞撮緞',
+              phoneNumber: '鎵嬫満鍙�',
+              workType: '鑱屼笟/宸ョ',
+              gender: '鎬у埆',
+              birthDay: '鍑虹敓鏃ユ湡',
+              note: '澶囨敞',
+            },
+          });
+        })
+        .catch(() => {
+          state.staffList = res.addOrSub;
+          getList();
+        });
+    }
+    state.staffList = res.addOrSub;
+    getList();
   } catch (error) {}
 }
 async function handleUploadReplace(response: UploadUserFile) {
@@ -224,11 +255,65 @@
       url: response.path,
       insurePolicyId: id,
     };
+    // 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(() => {
+          XLSXUtils.exportToXLSX({
+            workbookDataList: res?.error,
+            fileName: '閿欒浜哄憳鍚嶅崟',
+            workbookHeaderMap: {
+              orginName: '鍘熻淇濅汉濮撳悕',
+              orginIdNumber: '鍘熻淇濅汉璇佷欢鍙风爜',
+              name: '琚繚闄╀汉濮撳悕',
+              certType: '璇佷欢绫诲瀷',
+              idNumber: '璇佷欢鍙风爜',
+              phoneNumber: '鎵嬫満鍙�',
+              workType: '鑱屼笟/宸ョ',
+              gender: '鎬у埆',
+              age: '骞撮緞',
+              birthDay: '鍑虹敓鏃ユ湡',
+              note: '澶囨敞',
+            },
+          });
+        })
+        .catch(() => {
+          state.staffList = res.update;
+          getList();
+        });
+    }
+    state.staffList = res.update;
+    getList();
   } catch (error) {}
 }
 
-function handleClear() {}
+function handleClear() {
+  if (!state.staffList.length) {
+    Message.errorMessage('娌℃湁鏁版嵁鍙互娓呴櫎鍝�');
+    return;
+  }
+  state.staffList = [] as any[];
+  getList();
+}
 
 const formRef = ref<FormInstance>();
 function handleSubmit() {
@@ -244,7 +329,21 @@
 
 async function addOrUpdateInsureBatchBill() {
   try {
-    let params = {};
+    if (state.staffList.length === 0) {
+      Message.errorMessage('璇峰厛涓婁紶浜哄憳鍚嶅崟');
+      return;
+    }
+    let _addInsStaffList = _.uniqBy(state.staffList, 'idNumber');
+    let params: API.InsureBatchBillInput = {
+      insurancePolicyId: id,
+      effectTime: state.form.time,
+      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) {
       Message.successMessage('鎻愪氦鎴愬姛');
@@ -266,8 +365,10 @@
   });
 }
 
+const queryClient = useQueryClient();
+
 onMounted(async () => {
-  await getBatchRefundInfoDetail();
+  await getList();
   state.loading = false;
 });
 </script>

--
Gitblit v1.9.1