From 01a6c87b789624165373efa455e0520a613a6114 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期四, 02 七月 2026 11:29:13 +0800
Subject: [PATCH] 收款单:表单中收款金额添加最大值校验

---
 src/views/financialManagement/receivable/receipt.vue |   77 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/src/views/financialManagement/receivable/receipt.vue b/src/views/financialManagement/receivable/receipt.vue
index ae7a763..29194e7 100644
--- a/src/views/financialManagement/receivable/receipt.vue
+++ b/src/views/financialManagement/receivable/receipt.vue
@@ -171,10 +171,10 @@
                           prop="amount">
               <el-input-number v-model="form.amount"
                                :min="0"
+                               :max="collectionAmountInputMax"
                                :precision="2"
                                style="width: 100%;"
-                               :disabled="isView"
-                               placeholder="鏍规嵁鍏宠仈鍗曟嵁鑷姩姹囨�伙紝鍙慨鏀�" />
+                               :disabled="isView" />
             </el-form-item>
           </el-col>
         </el-row>
@@ -274,6 +274,12 @@
                          align="right">
           <template #default="{ row }">楼{{ formatMoney(row.outboundAmount) }}</template>
         </el-table-column>
+        <el-table-column prop="amountReceived"
+                         label="宸叉敹娆鹃噾棰�"
+                         width="110"
+                         align="right">
+          <template #default="{ row }">楼{{ formatMoney(row.amountReceived) }}</template>
+        </el-table-column>
         <el-table-column prop="taxRate"
                          label="绋庣巼"
                          width="80"
@@ -362,6 +368,7 @@
   const isEdit = ref(false);
   const isView = ref(false);
   const currentId = ref(null);
+  const originalReceiptAmount = ref(0);
   const submitLoading = ref(false);
 
   const customerList = ref([]);
@@ -400,6 +407,46 @@
     },
   });
 
+  const maxCollectionAmount = computed(() => {
+    const selected = form.stockOutRecordIds || [];
+    const editAmount = isEdit.value ? Number(originalReceiptAmount.value) || 0 : 0;
+    if (!selected.length) return isEdit.value ? editAmount : undefined;
+    const selectedValueSet = new Set(selected.map(id => String(id)));
+    const selectedOptions = outboundBatchOptions.value.filter(
+      opt => opt.amountLimitAvailable && selectedValueSet.has(String(opt.value))
+    );
+    if (selectedOptions.length !== selectedValueSet.size) {
+      return isEdit.value ? Number(editAmount.toFixed(2)) : undefined;
+    }
+    const sum = selectedOptions.reduce(
+      (acc, opt) => acc + (Number(opt.outboundAmount) || 0),
+      0
+    );
+    return Number((sum + editAmount).toFixed(2));
+  });
+
+  const collectionAmountInputMax = computed(
+    () => maxCollectionAmount.value ?? Number.MAX_SAFE_INTEGER
+  );
+
+  const validateCollectionAmount = (rule, value, callback) => {
+    if (value === undefined || value === null || value === "") {
+      callback();
+      return;
+    }
+    const amount = Number(value);
+    if (Number.isNaN(amount)) {
+      callback(new Error("璇疯緭鍏ユ敹娆鹃噾棰�"));
+      return;
+    }
+    const max = maxCollectionAmount.value;
+    if (max !== undefined && amount - max > 0.000001) {
+      callback(new Error(`鏀舵閲戦涓嶈兘瓒呰繃${max.toFixed(2)}`));
+      return;
+    }
+    callback();
+  };
+
   const rules = {
     customerId: [{ required: true, message: "璇烽�夋嫨瀹㈡埛", trigger: "change" }],
     stockOutRecordIds: [
@@ -414,7 +461,10 @@
     receiptDate: [
       { required: true, message: "璇烽�夋嫨鏀舵鏃ユ湡", trigger: "change" },
     ],
-    amount: [{ required: true, message: "璇疯緭鍏ユ敹娆鹃噾棰�", trigger: "blur" }],
+    amount: [
+      { required: true, message: "璇疯緭鍏ユ敹娆鹃噾棰�", trigger: "blur" },
+      { validator: validateCollectionAmount, trigger: ["blur", "change"] },
+    ],
     receiptMethod: [
       { required: true, message: "璇烽�夋嫨鏀舵鏂瑰紡", trigger: "change" },
     ],
@@ -474,7 +524,12 @@
     return list.map((item, index) => {
       if (typeof item === "string" || typeof item === "number") {
         const text = String(item);
-        return { label: text, value: text, outboundAmount: 0 };
+        return {
+          label: text,
+          value: text,
+          outboundAmount: 0,
+          amountLimitAvailable: false,
+        };
       }
       const label =
         item.outboundBatches ??
@@ -484,10 +539,15 @@
         item.label ??
         `鍑哄簱鍗�${index + 1}`;
       const value = item.id ?? item.stockOutRecordId ?? label;
+      const outboundAmount = Number(item.outboundAmount) || 0;
+      const amountReceived = Number(item.amountReceived) || 0;
+      const availableAmount = outboundAmount - amountReceived;
       return {
         label: String(label),
         value,
-        outboundAmount: Number(item.outboundAmount) || 0,
+        outboundAmount:
+          availableAmount > 0 ? Number(availableAmount.toFixed(2)) : 0,
+        amountLimitAvailable: true,
       };
     });
   };
@@ -535,6 +595,7 @@
         label: String(id),
         value: id,
         outboundAmount: 0,
+        amountLimitAvailable: false,
       });
     });
   };
@@ -637,6 +698,7 @@
     outboundSelectVisible.value = false;
     syncCollectionAmount();
     formRef.value?.validateField("stockOutRecordIds");
+    formRef.value?.validateField("amount");
   };
 
   const handleOutboundDialogClosed = () => {
@@ -707,6 +769,7 @@
     outboundSelectVisible.value = false;
     isView.value = false;
     isEdit.value = false;
+    originalReceiptAmount.value = 0;
   };
 
   const handleExport = () => {
@@ -766,6 +829,7 @@
     isEdit.value = false;
     isView.value = false;
     dialogTitle.value = "鏂板鏀舵";
+    originalReceiptAmount.value = 0;
     Object.assign(form, {
       receiptCode: "",
       customerId: "",
@@ -788,13 +852,16 @@
     currentId.value = row.id;
     dialogTitle.value = "缂栬緫鏀舵";
     fillFormFromRow(row);
+    originalReceiptAmount.value = Number(form.amount || 0);
     dialogVisible.value = true;
+    loadOutboundBatches(form.customerId, true);
   };
 
   const view = row => {
     isView.value = true;
     isEdit.value = false;
     dialogTitle.value = "鏌ョ湅鏀舵";
+    originalReceiptAmount.value = 0;
     fillFormFromRow(row);
     dialogVisible.value = true;
   };

--
Gitblit v1.9.3