From baddb052ccd4a91ef1881ba663e6a4e55b05f4fb Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 14 十月 2026 15:51:55 +0800
Subject: [PATCH] feat(hrm): 社保公积金方案表单加「适用部门」与默认缴费基数,修比例输入精度

---
 src/views/erp/purchase/request/modules/item-form.vue |  137 +++++++++++++++++++++++++++++----------------
 1 files changed, 88 insertions(+), 49 deletions(-)

diff --git a/src/views/erp/purchase/request/modules/item-form.vue b/src/views/erp/purchase/request/modules/item-form.vue
index 14b2713..0f4af30 100644
--- a/src/views/erp/purchase/request/modules/item-form.vue
+++ b/src/views/erp/purchase/request/modules/item-form.vue
@@ -1,5 +1,4 @@
 <script lang="ts" setup>
-import type { MdmItemApi } from '#/api/mdm/item';
 import type { ErpPurchaseRequestApi } from '#/api/erp/purchase/request';
 
 import { computed, nextTick, onMounted, ref, watch } from 'vue';
@@ -8,12 +7,12 @@
   erpCountInputFormatter,
   erpPriceInputFormatter,
   erpPriceMultiply,
-} from '../../../../../packages/utils/src';
+} from '@vben/utils';
 
-import { Input, InputNumber, Select, DatePicker } from 'ant-design-vue';
+import { Input, InputNumber, DatePicker, Switch } from 'ant-design-vue';
 
 import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
-import { getItemPage } from '#/api/mdm/item';
+import { MdmItemSelect } from '#/views/basicData/mdm/components';
 
 import { useFormItemColumns } from '../data';
 
@@ -30,21 +29,23 @@
 const emit = defineEmits(['update:items']);
 
 const tableData = ref<ErpPurchaseRequestApi.PurchaseRequestItem[]>([]);
-const productOptions = ref<MdmItemApi.Item[]>([]);
 
-/** 鑾峰彇琛ㄦ牸鍚堣鏁版嵁 */
+/** 鑾峰彇琛ㄦ牸鍚堣鏁版嵁锛堣涓� totalPrice 涓轰笉鍚◣閲戦锛屽惈绋庡悎璁¢渶鍔犱笂绋庨锛� */
 const summaries = computed(() => {
   return {
-    count: tableData.value.reduce((sum, item) => sum + (item.requestCount || 0), 0),
+    count: tableData.value.reduce((sum, item) => sum + (item.count || 0), 0),
     totalPrice: tableData.value.reduce(
-      (sum, item) => {
-        const price = erpPriceMultiply(item.estimatedPrice || 0, item.requestCount || 0) ?? 0;
-        return sum + price;
-      },
+      (sum, item) => sum + (item.totalPrice || 0),
       0,
     ),
+    taxPrice: tableData.value.reduce((sum, item) => sum + (item.taxPrice || 0), 0),
   };
 });
+
+/** 鍚◣鍚堣 = 涓嶅惈绋庨噾棰� + 绋庨 */
+const totalTaxInclusivePrice = computed(
+  () => summaries.value.totalPrice + summaries.value.taxPrice,
+);
 
 /** 琛ㄦ牸閰嶇疆 */
 const [Grid, gridApi] = useVbenVxeGrid({
@@ -89,13 +90,16 @@
   const newRow = {
     id: undefined,
     productId: undefined,
+    productUnitId: undefined,
     productUnitName: undefined,
     productBarCode: undefined,
-    requestCount: 1,
-    estimatedPrice: undefined,
-    requiredDate: undefined,
+    count: 1,
+    productPrice: undefined,
+    taxPercent: undefined,
+    demandTime: undefined,
     remark: undefined,
     totalPrice: 0,
+    qcCheckFlag: false,
   };
   tableData.value.push(newRow);
   emit('update:items', [...tableData.value]);
@@ -111,39 +115,53 @@
 }
 
 /** 澶勭悊浜у搧鍙樻洿 */
-async function handleProductChange(productId: any, row: any) {
-  const product = productOptions.value.find((p) => p.id === productId);
+function handleProductChange(product: any, row: any) {
   if (!product) {
     return;
   }
-  row.productId = productId;
+  row.productId = product.id;
   row.productBarCode = product.barCode;
+  row.productUnitId = product.unitMeasureId;
   row.productUnitName = product.unitMeasureName;
   row.productName = product.name;
-  row.estimatedPrice = product.purchasePrice || 0;
-  row.requestCount = row.requestCount || 1;
+  row.productPrice = product.purchasePrice || 0;
+  row.count = row.count || 1;
   handleRowChange(row);
+}
+
+/**
+ * 閲嶇畻琛岄噾棰濓紙鍗曚环涓�**鍚◣**鍗曚环锛�
+ * 鍚◣閲戦 = 鍚◣鍗曚环 脳 鏁伴噺锛涚◣棰� = 鍚◣閲戦 脳 绋庣巼锛涗笉鍚◣閲戦 = 鍚◣閲戦 - 绋庨
+ */
+function recalcRow(row: ErpPurchaseRequestApi.PurchaseRequestItem) {
+  if (row.productPrice && row.count) {
+    const taxInclusivePrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
+    row.taxPrice =
+      erpPriceMultiply(taxInclusivePrice, (row.taxPercent || 0) / 100) ?? 0;
+    row.totalPrice = taxInclusivePrice - row.taxPrice;
+  }
 }
 
 /** 澶勭悊琛屾暟鎹彉鏇� */
 function handleRowChange(row: any) {
+  recalcRow(row);
   const index = tableData.value.findIndex((item) => item.seq === row.seq);
   if (index === -1) {
     tableData.value.push(row);
   } else {
     tableData.value[index] = row;
   }
-  // 璁$畻棰勪及閲戦
-  if (row.estimatedPrice && row.requestCount) {
-    row.totalPrice = erpPriceMultiply(row.estimatedPrice, row.requestCount) ?? 0;
-  }
   emit('update:items', [...tableData.value]);
 }
 
-/** 鍒濆鍖栬鏁版嵁 */
+/**
+ * 鍒濆鍖栬鏁版嵁
+ * 宸叉湁鍗曟嵁鐨勬槑缁嗚锛堝甫 id锛夋部鐢ㄥ悗绔繑鍥炵殑閲戦锛岄伩鍏嶅巻鍙插崟鎹鏂板彛寰勮鐩栵紱
+ * 鍙湁鏈繚瀛樼殑鏂板琛屾墠鎸夋柊鍙e緞閲嶇畻銆�
+ */
 function initRow(row: ErpPurchaseRequestApi.PurchaseRequestItem) {
-  if (row.estimatedPrice && row.requestCount) {
-    row.totalPrice = erpPriceMultiply(row.estimatedPrice, row.requestCount) ?? 0;
+  if (!row.id) {
+    recalcRow(row);
   }
 }
 
@@ -155,8 +173,8 @@
       if (!item.productId) {
         throw new Error(`绗� ${i + 1} 琛岋細浜у搧涓嶈兘涓虹┖`);
       }
-      if (!item.requestCount || item.requestCount <= 0) {
-        throw new Error(`绗� ${i + 1} 琛岋細鐢宠鏁伴噺涓嶈兘涓虹┖`);
+      if (!item.count || item.count <= 0) {
+        throw new Error(`绗� ${i + 1} 琛岋細鏁伴噺涓嶈兘涓虹┖`);
       }
     }
   }
@@ -167,9 +185,7 @@
 });
 
 /** 鍒濆鍖� */
-onMounted(async () => {
-  const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 });
-  productOptions.value = res.list || [];
+onMounted(() => {
   if (tableData.value.length === 0) {
     handleAdd();
   }
@@ -179,51 +195,72 @@
 <template>
   <Grid class="w-full">
     <template #productId="{ row }">
-      <Select
+      <MdmItemSelect
         v-if="!disabled"
-        v-model:value="row.productId"
-        :options="productOptions"
-        :field-names="{ label: 'name', value: 'id' }"
-        class="w-full"
+        :model-value="row.productId"
         placeholder="璇烽�夋嫨浜у搧"
-        show-search
+        @update:model-value="row.productId = $event"
         @change="handleProductChange($event, row)"
       />
       <span v-else>{{ row.productName || '-' }}</span>
     </template>
-    <template #requestCount="{ row }">
+    <template #count="{ row }">
       <InputNumber
         v-if="!disabled"
-        v-model:value="row.requestCount"
+        v-model:value="row.count"
         :min="0"
         :precision="3"
         @change="handleRowChange(row)"
       />
-      <span v-else>{{ erpCountInputFormatter(row.requestCount) || '-' }}</span>
+      <span v-else>{{ erpCountInputFormatter(row.count) || '-' }}</span>
     </template>
-    <template #estimatedPrice="{ row }">
+    <template #productPrice="{ row }">
       <InputNumber
         v-if="!disabled"
-        v-model:value="row.estimatedPrice"
+        v-model:value="row.productPrice"
         :min="0"
         :precision="2"
         @change="handleRowChange(row)"
       />
-      <span v-else>{{ erpPriceInputFormatter(row.estimatedPrice) || '-' }}</span>
+      <span v-else>{{ erpPriceInputFormatter(row.productPrice) || '-' }}</span>
     </template>
-    <template #requiredDate="{ row }">
+    <template #taxPercent="{ row }">
+      <InputNumber
+        v-if="!disabled"
+        v-model:value="row.taxPercent"
+        :min="0"
+        :max="100"
+        :precision="2"
+        @change="handleRowChange(row)"
+      />
+      <span v-else>{{ row.taxPercent ? `${row.taxPercent}%` : '-' }}</span>
+    </template>
+    <template #totalTaxInclusivePrice="{ row }">
+      <span>{{ erpPriceInputFormatter((row.totalPrice || 0) + (row.taxPrice || 0)) }}</span>
+    </template>
+    <template #demandTime="{ row }">
       <DatePicker
         v-if="!disabled"
-        v-model:value="row.requiredDate"
+        v-model:value="row.demandTime"
         valueFormat="YYYY-MM-DD"
         class="w-full"
         @change="handleRowChange(row)"
       />
-      <span v-else>{{ row.requiredDate || '-' }}</span>
+      <span v-else>{{ row.demandTime || '-' }}</span>
     </template>
     <template #remark="{ row }">
       <Input v-if="!disabled" v-model:value="row.remark" class="w-full" @change="handleRowChange(row)" />
       <span v-else>{{ row.remark || '-' }}</span>
+    </template>
+    <template #qcCheckFlag="{ row }">
+      <Switch
+        v-if="!disabled"
+        v-model:checked="row.qcCheckFlag"
+        checked-children="鏄�"
+        un-checked-children="鍚�"
+        @change="handleRowChange(row)"
+      />
+      <span v-else>{{ row.qcCheckFlag ? '鏄�' : '鍚�' }}</span>
     </template>
     <template #actions="{ row }">
       <TableAction
@@ -246,8 +283,10 @@
         <div class="flex justify-between text-sm text-muted-foreground">
           <span class="font-medium text-foreground">鍚堣锛�</span>
           <div class="flex space-x-4">
-            <span>鐢宠鏁伴噺锛歿{ erpCountInputFormatter(summaries.count) }}</span>
-            <span>棰勪及閲戦锛歿{ erpPriceInputFormatter(summaries.totalPrice) }}</span>
+            <span>鏁伴噺锛歿{ erpCountInputFormatter(summaries.count) }}</span>
+            <span>涓嶅惈绋庨噾棰濓細{{ erpPriceInputFormatter(summaries.totalPrice) }}</span>
+            <span>绋庨锛歿{ erpPriceInputFormatter(summaries.taxPrice) }}</span>
+            <span>鍚◣鍚堣锛歿{ erpPriceInputFormatter(totalTaxInclusivePrice) }}</span>
           </div>
         </div>
       </div>
@@ -264,4 +303,4 @@
       />
     </template>
   </Grid>
-</template>
\ No newline at end of file
+</template>

--
Gitblit v1.9.3