From 342439b018786854ec0b49a2cf26fe422ca9121d Mon Sep 17 00:00:00 2001
From: ZN <zhang_12370@163.com>
Date: 星期一, 23 三月 2026 09:43:21 +0800
Subject: [PATCH] feat(采购退货): 增加删除采购退货单功能并优化相关操作

---
 src/views/procurementManagement/purchaseReturnOrder/New.vue |   86 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/src/views/procurementManagement/purchaseReturnOrder/New.vue b/src/views/procurementManagement/purchaseReturnOrder/New.vue
index f130733..17e36dc 100644
--- a/src/views/procurementManagement/purchaseReturnOrder/New.vue
+++ b/src/views/procurementManagement/purchaseReturnOrder/New.vue
@@ -334,12 +334,17 @@
             label="鏁村崟鎶樻墸鐜囷細"
             prop="totalDiscountAmount"
         >
-          <el-input-number v-model="formState.totalDiscountRate"
+          <el-input v-model="formState.totalDiscountRate"
                            controls-position="right"
                            :step="0.01"
                            :precision="2"
                            style="width: 100%;"
-                           placeholder="璇疯緭鍏ユ暣鍗曟姌鎵g巼"/>
+                           @change="totalDiscount"
+                           placeholder="璇疯緭鍏ユ暣鍗曟姌鎵g巼">
+            <template #append>
+                %
+            </template>
+          </el-input>
         </el-form-item>
 
         <el-form-item
@@ -412,7 +417,24 @@
   }
 });
 let { proxy } = getCurrentInstance()
-const { payment_methods } = proxy.useDict("payment_methods");
+const payment_methods  = [
+    {
+        "label": "鐜伴噾",
+        "value": "0",
+    },
+    {
+        "label": "鏀エ",
+        "value": "1",
+    },
+    {
+        "label": "閾惰杞处",
+        "value": "2",
+    },
+    {
+        "label": "鍏朵粬",
+        "value": "3",
+    },
+]
 const emit = defineEmits(['update:visible', 'completed']);
 
 // 鍝嶅簲寮忔暟鎹紙鏇夸唬閫夐」寮忕殑 data锛�
@@ -509,6 +531,26 @@
   row.taxInclusiveTotalPrice = getReturnTotal(row)
 }
 
+const getBaseAmount = () => {
+  const rows = formState.value.purchaseReturnOrderProductsDtos || []
+  return rows.reduce((sum, item) => {
+    return sum + toNumber(item.taxInclusiveTotalPrice)
+  }, 0)
+}
+
+// 鍚屾鎶樻墸棰�
+const totalDiscount = () => {
+  const discountRate = toNumber(formState.value.totalDiscountRate)
+  if (discountRate < 0 || discountRate > 100) {
+    proxy.$modal.msgError("璇疯緭鍏�0-100涔嬮棿鐨勬姌鎵g巼")
+    return
+  }
+  const baseAmount = getBaseAmount()
+  // 鎶樻墸棰� = 浜у搧閫�璐ф�讳环鍚堣 * 鎶樻墸鐜�
+  formState.value.totalDiscountAmount = Number((baseAmount * (discountRate / 100)).toFixed(2))
+  syncTotalAmount()
+}
+
 const getReturnQtyMax = (row) => {
   const max = Number(row?.availableQuality)
   if (Number.isNaN(max) || max < 0) {
@@ -541,14 +583,39 @@
 };
 
 const handleChangeTotalDiscountAmount= () => {
+  const discountAmount = toNumber(formState.value.totalDiscountAmount)
+  if (discountAmount < 0) {
+    proxy.$modal.msgError("鏁村崟鎶樻墸棰濅笉鑳藉皬浜�0")
+    formState.value.totalDiscountAmount = 0
+  }
+
+  const baseAmount = getBaseAmount()
+  const normalizedAmount = toNumber(formState.value.totalDiscountAmount)
+  if (baseAmount <= 0) {
+    formState.value.totalDiscountRate = 0
+    syncTotalAmount()
+    return
+  }
+
+  if (normalizedAmount > baseAmount) {
+    proxy.$modal.msgError("鏁村崟鎶樻墸棰濅笉鑳藉ぇ浜庝骇鍝侀��璐ф�讳环鍚堣")
+    formState.value.totalDiscountAmount = Number(baseAmount.toFixed(2))
+  }
+
+  const discountRate = (toNumber(formState.value.totalDiscountAmount) / baseAmount) * 100
+  formState.value.totalDiscountRate = Number(discountRate.toFixed(2))
   syncTotalAmount()
 }
 
+const resetFeeInfo = () => {
+  formState.value.totalDiscountAmount = 0
+  formState.value.totalDiscountRate = undefined
+  formState.value.totalAmount = 0
+  formState.value.incomeType = undefined
+}
+
 const syncTotalAmount = () => {
-  const rows = formState.value.purchaseReturnOrderProductsDtos || []
-  const baseAmount = rows.reduce((sum, item) => {
-    return sum + toNumber(item.taxInclusiveTotalPrice)
-  }, 0)
+  const baseAmount = getBaseAmount()
   const discount = toNumber(formState.value.totalDiscountAmount)
   // 鎴愪氦閲戦 = 浜у搧閫�璐ф�讳环鍚堣 - 鎶樻墸棰�
   formState.value.totalAmount = Number((baseAmount - discount).toFixed(2))
@@ -594,6 +661,11 @@
 
 // 澶勭悊鏀瑰彉閲囪喘鍙拌处鏁版嵁
 const handleChangePurchaseLedgerId = async () => {
+  resetFeeInfo()
+  if (!formState.value.purchaseLedgerId) {
+    formState.value.purchaseReturnOrderProductsDtos = []
+    return
+  }
   const res = await productList({ salesLedgerId: formState.value.purchaseLedgerId, type: 2 });
   formState.value.purchaseReturnOrderProductsDtos = res.data.map(item => ({
     ...item,

--
Gitblit v1.9.3