From d476be7eda60a04e0cbbc28c5aa048dfceffd789 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 03 七月 2026 15:39:23 +0800
Subject: [PATCH] 新增采购退货后,如果对应的采购退货审批也通过,采购退货记录不能删除,删除按钮置灰

---
 src/views/financialManagement/receivable/receipt.vue |   89 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 82 insertions(+), 7 deletions(-)

diff --git a/src/views/financialManagement/receivable/receipt.vue b/src/views/financialManagement/receivable/receipt.vue
index 1c84594..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>
@@ -196,7 +196,7 @@
           <el-col :span="12">
             <el-form-item label="鍒涘缓鏃堕棿"
                           prop="createTime">
-              <el-date-picker v-model="form.createTime"
+              <el-date-picker v-model="formCreateTimeDate"
                               type="date"
                               placeholder="閫夋嫨鏃ユ湡"
                               value-format="YYYY-MM-DD"
@@ -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"
@@ -299,6 +305,7 @@
     nextTick,
     getCurrentInstance,
   } from "vue";
+  import dayjs from "dayjs";
   import { ElMessage, ElMessageBox } from "element-plus";
   import FormDialog from "@/components/Dialog/FormDialog.vue";
   import { listCustomer } from "@/api/basicData/customer.js";
@@ -361,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([]);
@@ -392,6 +400,52 @@
     remark: "",
     createTime: "",
   });
+  const formCreateTimeDate = computed({
+    get: () => (form.createTime ? String(form.createTime).split(" ")[0] : ""),
+    set: (value) => {
+      form.createTime = value ? `${value} ${dayjs().format("HH:mm:ss")}` : "";
+    },
+  });
+
+  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" }],
@@ -407,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" },
     ],
@@ -467,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 ??
@@ -477,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,
       };
     });
   };
@@ -528,6 +595,7 @@
         label: String(id),
         value: id,
         outboundAmount: 0,
+        amountLimitAvailable: false,
       });
     });
   };
@@ -630,6 +698,7 @@
     outboundSelectVisible.value = false;
     syncCollectionAmount();
     formRef.value?.validateField("stockOutRecordIds");
+    formRef.value?.validateField("amount");
   };
 
   const handleOutboundDialogClosed = () => {
@@ -691,6 +760,7 @@
       stockOutRecordIds,
       outboundBatches: formatOutboundBatches(row.outboundBatches),
       remark: row.remark ?? "",
+      createTime: row.createTime ?? "",
     });
   };
 
@@ -699,6 +769,7 @@
     outboundSelectVisible.value = false;
     isView.value = false;
     isEdit.value = false;
+    originalReceiptAmount.value = 0;
   };
 
   const handleExport = () => {
@@ -758,6 +829,7 @@
     isEdit.value = false;
     isView.value = false;
     dialogTitle.value = "鏂板鏀舵";
+    originalReceiptAmount.value = 0;
     Object.assign(form, {
       receiptCode: "",
       customerId: "",
@@ -767,7 +839,7 @@
       stockOutRecordIds: [],
       outboundBatches: "",
       remark: "",
-      createTime: new Date().toISOString().split("T")[0],
+      createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
     });
     outboundBatchList.value = [];
     outboundBatchOptions.value = [];
@@ -780,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