From b42ca1e9ab197ce53828f4607610ae10f25965bb Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期五, 12 十二月 2025 19:59:13 +0800
Subject: [PATCH] feat: 新增渠道包

---
 src/views/EmploymentManage/components/AddOrEditEmploymentView.vue |  198 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 177 insertions(+), 21 deletions(-)

diff --git a/src/views/EmploymentManage/components/AddOrEditEmploymentView.vue b/src/views/EmploymentManage/components/AddOrEditEmploymentView.vue
index 073b80d..d130636 100644
--- a/src/views/EmploymentManage/components/AddOrEditEmploymentView.vue
+++ b/src/views/EmploymentManage/components/AddOrEditEmploymentView.vue
@@ -2,7 +2,7 @@
   <LoadingLayout :loading="isLoading && isEdit">
     <AppContainer>
       <PageFormLayout title="鍩烘湰淇℃伅">
-        <ProForm :model="form" ref="productFormRef" label-width="110px" :is-read="isDetail">
+        <ProForm :model="form" ref="productFormRef" label-width="120px" :is-read="isDetail">
           <ProFormItemV2
             label="渚涘簲鍟�:"
             prop="supplierEnterpriseId"
@@ -12,6 +12,8 @@
               v-model="form.supplierEnterpriseId"
               :value-enum="supplierEnterpriseSelect"
               placeholder="璇烽�夋嫨渚涘簲鍟�"
+              :disabled="isEdit"
+              @change="supplierEnterpriseChange"
             ></ProFormSelect>
           </ProFormItemV2>
           <ProFormCol>
@@ -38,7 +40,9 @@
                   placeholder="璇疯緭鍏ラ渶姹備汉鏁�"
                   :min="0"
                   :max="999999999999"
+                  :precision="0"
                   unit="浜�"
+                  @change="calcTaskTotalServiceFee"
                 ></ProFormInputNumber>
               </ProFormItemV2>
             </ProFormColItem>
@@ -68,6 +72,7 @@
                   :showExtra="true"
                   :button-style="false"
                   :disabled="feeCannotEdit"
+                  @change="calcTaskTotalServiceFee"
                 >
                   <template #extra>
                     <ProFormInputNumber
@@ -79,18 +84,14 @@
                       :max="999999999999"
                       :unit="EnumBillingMethodUnitText[form.billingMethod]"
                       :disabled="feeCannotEdit"
+                      @change="calcTaskTotalServiceFee"
                     ></ProFormInputNumber>
                   </template>
                 </RadioWithExtra>
               </ProFormItemV2>
             </ProFormColItem>
           </ProFormCol>
-          <template
-            v-if="
-              form.billingMethod === EnumBillingMethod.Hour ||
-              form.billingMethod === EnumBillingMethod.Day
-            "
-          >
+          <template v-if="form.billingMethod === EnumBillingMethod.Hour">
             <ProFormCol>
               <ProFormColItem :span="12">
                 <ProFormItemV2
@@ -108,6 +109,7 @@
                     :max="999999999999"
                     unit="灏忔椂/澶�"
                     :disabled="feeCannotEdit"
+                    @change="calcTaskTotalServiceFee"
                   ></ProFormInputNumber>
                 </ProFormItemV2>
               </ProFormColItem>
@@ -134,7 +136,26 @@
               </ProFormColItem>
             </ProFormCol>
           </template>
-
+          <ProFormCol v-if="form.billingMethod === EnumBillingMethod.Piece">
+            <ProFormColItem :span="12">
+              <ProFormItemV2
+                label="鎬讳欢鏁�:"
+                prop="totalPieceQuantity"
+                :check-rules="[{ message: '璇疯緭鍏ユ�讳欢鏁�' }]"
+              >
+                <ProFormInputNumber
+                  :controls="false"
+                  v-model="form.totalPieceQuantity"
+                  placeholder="璇疯緭鍏ユ�讳欢鏁�"
+                  :min="0"
+                  :max="999999999999"
+                  unit="浠�"
+                  :disabled="feeCannotEdit"
+                  @change="calcTaskTotalServiceFee"
+                ></ProFormInputNumber>
+              </ProFormItemV2>
+            </ProFormColItem>
+          </ProFormCol>
           <ProFormCol>
             <ProFormColItem :span="12">
               <ProFormItemV2
@@ -303,7 +324,20 @@
               <ProFormItemV2
                 label="浠诲姟鏃堕棿:"
                 prop="time"
-                :check-rules="[{ message: '璇烽�夋嫨浠诲姟鏃堕棿', type: 'array' }]"
+                :check-rules="[
+                  { message: '璇烽�夋嫨浠诲姟鏃堕棿', type: 'array' },
+                  {
+                    validator: (rule, value, callback) => {
+                      if (form.billingMethod === EnumBillingMethod.Month) {
+                        if (dayjs(form.time[1]).diff(dayjs(form.time[0]), 'month') < 1) {
+                          callback(new Error('鏈堢粨浠诲姟鏃朵换鍔℃椂闂撮渶澶т簬涓�涓湀'));
+                        }
+                        callback();
+                      }
+                      callback();
+                    },
+                  },
+                ]"
               >
                 <ProFormDatePicker
                   v-model="form.time"
@@ -339,17 +373,35 @@
             <ProFormColItem :span="12">
               <ProFormItemV2
                 label="楠屾敹鏂瑰紡:"
-                prop="checkReceiveMethod"
+                prop="checkReceiveMethods"
                 :check-rules="[{ message: '璇烽�夋嫨楠屾敹鏂瑰紡' }]"
               >
-                <ProFormRadio
-                  v-model="form.checkReceiveMethod"
+                <ProFormCheckbox
+                  v-model="form.checkReceiveMethods"
                   :value-enum="EnumTaskCheckReceiveMethodText"
-                  :button-style="false"
-                ></ProFormRadio>
+                  :disabled="isEdit"
+                ></ProFormCheckbox>
               </ProFormItemV2>
             </ProFormColItem>
           </ProFormCol>
+          <ProFormItemV2
+            label="淇濋櫓浜у搧:"
+            prop="insuranceProductId"
+            :check-rules="[{ message: '璇烽�夋嫨淇濋櫓浜у搧' }]"
+            v-if="
+              form.checkReceiveMethods.includes(EnumTaskCheckReceiveMethod.CheckIn) &&
+              form.isConfiguredInsurance
+            "
+          >
+            <ProFormSelect
+              v-model="form.insuranceProductId"
+              :value-enum="enterpriseInsuranceProductSelect"
+              @change="calcTaskTotalServiceFee"
+            ></ProFormSelect>
+          </ProFormItemV2>
+          <ProFormItemV2 label="棰勮鏈嶅姟璐规�婚:" prop="totalServiceFee">
+            {{ `${toThousand(form.totalServiceFee)}鍏僠 }}
+          </ProFormItemV2>
           <ProFormItemV2
             label="缁撶畻鏂瑰紡:"
             prop="settlementAccess"
@@ -404,9 +456,9 @@
   EnumSettlementCycleDateWeekArray,
   EnumSettlementCycle,
   EnumTaskCheckReceiveMethodText,
-  EnumEnterpriseWalletAccessText,
+  EnumTaskCheckReceiveMethod,
 } from '@/constants';
-import { format, FormValidator } from '@/utils';
+import { format, FormValidator, toThousand } from '@/utils';
 import dayjs from 'dayjs';
 
 defineOptions({
@@ -417,6 +469,7 @@
 };
 defineProps<Props>();
 const route = useRoute();
+const router = useRouter();
 const id = route.params.id as string;
 const isEdit = !!id;
 
@@ -468,6 +521,7 @@
   needPeopleNumber: null as number,
   billingMethod: EnumBillingMethod.Day,
   serviceFee: null,
+  totalPieceQuantity: null as number,
   settlementCycle: EnumSettlementCycle.Day,
   settlementDate: null as number,
   benefits: [] as string[],
@@ -481,13 +535,22 @@
   verifyWorkHours: null as number,
   timeoutServiceFee: null as number,
   description: '',
-  checkReceiveMethod: '' as any as EnumTaskCheckReceiveMethod,
+  checkReceiveMethods: [] as any as EnumTaskCheckReceiveMethod[],
   applyTime: [] as unknown as ModelValueType,
   settlementAccess: '' as any as EnumEnterpriseWalletAccess,
+  totalServiceFee: 0,
+
+  insuranceProductId: '',
+  isConfiguredInsurance: false,
 });
 
 const { settlementAccessList } = useEnterpriseWalletAccessSelect({
   supplierEnterpriseId: computed(() => form.supplierEnterpriseId),
+});
+
+const { enterpriseInsuranceProductSelect } = useEnterpriseInsuranceProductSelect({
+  supplierEnterpriseId: computed(() => form.supplierEnterpriseId),
+  isConfiguredInsurance: computed(() => form.isConfiguredInsurance),
 });
 
 const { isLoading } = useQuery({
@@ -506,6 +569,7 @@
     form.name = data.name;
     form.needPeopleNumber = data.needPeopleNumber;
     form.billingMethod = data.billingMethod;
+    form.totalPieceQuantity = data.totalPieceQuantity;
     form.serviceFee = data.serviceFee;
     form.settlementCycle = data.settlementCycle;
     form.settlementDate = data.settlementDate;
@@ -535,12 +599,17 @@
     form.verifyWorkHours = data.verifyWorkHours;
     form.timeoutServiceFee = data.timeoutServiceFee;
     form.description = data.description;
-    form.checkReceiveMethod = data.checkReceiveMethod;
+    form.checkReceiveMethods = data.checkReceiveMethods;
     form.applyTime = [
       format(data.applyBeginTime, 'YYYY-MM-DD 00:00:00'),
       format(data.applyEndTime, 'YYYY-MM-DD 23:59:59'),
     ];
     form.settlementAccess = data.settlementAccess;
+    form.totalServiceFee = data.estimatedServiceFee;
+
+    form.insuranceProductId = data.insuranceProductId ?? '';
+
+    supplierEnterpriseChange();
   },
   enabled: isEdit,
 });
@@ -551,6 +620,7 @@
 
 function handleTimeChange() {
   form.applyTime = [] as unknown as ModelValueType;
+  calcTaskTotalServiceFee();
 }
 
 function handleBack() {
@@ -558,6 +628,7 @@
     name: 'TaskManageList',
   });
 }
+
 const productFormRef = ref<FormInstance>();
 function handleConfirm() {
   if (!productFormRef.value) return;
@@ -569,13 +640,75 @@
     }
   });
 }
+
+// function calculateMonthInterval(startDate, endDate) {
+//   const diffInDays = dayjs(endDate).diff(startDate, 'day');
+//   const monthInterval = Math.ceil(diffInDays / 30);
+//   return monthInterval > 15 ? Math.ceil(monthInterval / 30) : monthInterval;
+// }
+
+// const totalServiceFee = computed(() => {
+//   const monthInterval = calculateMonthInterval(form.time[0], form.time[1]);
+//   const dayInterval = dayjs(form.time[1]).diff(dayjs(form.time[0]), 'day');
+//   switch (form.billingMethod) {
+//     case EnumBillingMethod.Month:
+//       return monthInterval * (form.serviceFee ?? 0) * (form.needPeopleNumber ?? 0);
+//     case EnumBillingMethod.Day:
+//       return dayInterval * (form.serviceFee ?? 0) * (form.needPeopleNumber ?? 0);
+//     case EnumBillingMethod.Hour:
+//       return (
+//         dayInterval *
+//         (form.verifyWorkHours ?? 0) *
+//         (form.serviceFee ?? 0) *
+//         (form.needPeopleNumber ?? 0)
+//       );
+//     case EnumBillingMethod.Piece:
+//       return (form.totalPieceQuantity ?? 0) * (form.serviceFee ?? 0);
+//     default:
+//       return form.totalServiceFee;
+//   }
+// });
+
+function supplierEnterpriseChange() {
+  if (form.supplierEnterpriseId) {
+    form.isConfiguredInsurance = supplierEnterpriseSelect.value?.find(
+      (item) => item.value === form.supplierEnterpriseId
+    )?.data?.isConfiguredInsurance;
+  }
+}
+
+async function calcTaskTotalServiceFee() {
+  try {
+    let params: API.CalcTaskTotalServiceFeeCommand = {
+      billingMethod: form.billingMethod,
+      serviceFee: form.serviceFee ?? 0,
+      verifyWorkHours: form.verifyWorkHours ?? 0,
+      totalPieceQuantity: form.totalPieceQuantity,
+      needPeopleNumber: form.needPeopleNumber ?? 0,
+      beginTime: dayjs(form.time[0]).format('YYYY-MM-DD 00:00:00'),
+      endTime: dayjs(form.time[1]).format('YYYY-MM-DD 23:59:59'),
+      supplierEnterpriseId: form.supplierEnterpriseId,
+      checkReceiveMethods: form.checkReceiveMethods,
+    };
+    if (form.insuranceProductId) {
+      params.insuranceProductId = form.insuranceProductId;
+    }
+    let res = await taskServices.calcTaskTotalServiceFee(params);
+    if (res) {
+      form.totalServiceFee = res.totalServiceFee;
+    }
+  } catch (error) {}
+}
+
 async function submit() {
   try {
+    await calcTaskTotalServiceFee();
     let params: API.SaveTaskInfoCommand = {
       supplierEnterpriseId: form.supplierEnterpriseId,
       name: form.name,
       needPeopleNumber: form.needPeopleNumber,
       billingMethod: form.billingMethod,
+      totalPieceQuantity: form.totalPieceQuantity,
       serviceFee: form.serviceFee,
       settlementCycle: form.settlementCycle,
       settlementDate: form.settlementDate ? form.settlementDate : 0,
@@ -597,19 +730,42 @@
       verifyWorkHours: form.verifyWorkHours,
       timeoutServiceFee: form.timeoutServiceFee,
       description: form.description,
-      checkReceiveMethod: form.checkReceiveMethod,
+      checkReceiveMethods: form.checkReceiveMethods,
       settlementAccess: form.settlementAccess,
+      insuranceProductId: form.insuranceProductId ? form.insuranceProductId : null,
     };
+    if (form.billingMethod !== EnumBillingMethod.Face) {
+      params.serviceFee = form.serviceFee;
+    }
     if (isEdit) {
       params.id = id;
     }
-    let res = await taskServices.saveTaskInfo(params);
+    let res = await taskServices.saveTaskInfo(params, {
+      skipErrorHandler: true,
+    });
     if (res) {
       Message.successMessage('鎿嶄綔鎴愬姛');
       eventContext.emit(isEdit ? 'taskManage:edit' : 'taskManage:add');
       handleBack();
     }
-  } catch (error) {}
+  } catch (error) {
+    if (error?.info?.errorCode == 'BalanceNotEnough') {
+      Message.tipMessage('鎮ㄥ綋鍓嶈处鎴蜂綑棰濅笉瓒筹紝鏆傛椂鏃犳硶鍙戝竷浠诲姟锛岃鍏呭�煎悗鎿嶄綔', {
+        confirmButtonText: '绔嬪嵆鍏呭��',
+        cancelButtonText: '鍙栨秷',
+        type: 'warning',
+        callback: (action) => {
+          if (action === 'confirm') {
+            router.push({
+              name: 'BalanceManageV2',
+            });
+          }
+        },
+      });
+    } else {
+      Message.errorMessage(error);
+    }
+  }
 }
 
 function handleCheckBenefitsAllChange(val: boolean) {

--
Gitblit v1.9.1