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/procurementManagement/purchaseReturnOrder/New.vue |  252 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 209 insertions(+), 43 deletions(-)

diff --git a/src/views/procurementManagement/purchaseReturnOrder/New.vue b/src/views/procurementManagement/purchaseReturnOrder/New.vue
index f130733..186a552 100644
--- a/src/views/procurementManagement/purchaseReturnOrder/New.vue
+++ b/src/views/procurementManagement/purchaseReturnOrder/New.vue
@@ -3,8 +3,10 @@
     <el-dialog
         v-model="isShow"
         title="鏂板閲囪喘閫�璐�"
-        width="1600"
+        width="70%"
+        top="3vh"
         @close="closeModal"
+        class="purchase-return-dialog"
     >
       <el-form label-width="140px" :model="formState" label-position="top" ref="formRef" :inline="true">
         <div class="section-title">
@@ -56,6 +58,63 @@
         </el-form-item>
 
         <el-form-item
+            label="鍙戣揣绫诲瀷"
+            prop="shippingType"
+            :rules="[
+                {
+                  required: true,
+                  message: '璇烽�夋嫨鍙戣揣绫诲瀷',
+                  trigger: 'change',
+                }
+              ]"
+        >
+          <el-select
+              v-model="formState.shippingType"
+              placeholder="璇烽�夋嫨鍙戣揣绫诲瀷"
+              style="width: 240px"
+              @change="handleShippingTypeChange"
+          >
+            <el-option label="璐ц溅" :value="1" />
+            <el-option label="蹇��" :value="2" />
+          </el-select>
+        </el-form-item>
+
+        <el-form-item
+            v-if="formState.shippingType === 1"
+            label="鍙戣揣杞︾墝鍙�"
+            prop="truckPlateNo"
+        >
+          <el-input
+              v-model="formState.truckPlateNo"
+              placeholder="璇疯緭鍏ュ彂璐ц溅鐗屽彿"
+              style="width: 240px"
+          />
+        </el-form-item>
+
+        <template v-else-if="formState.shippingType === 2">
+          <el-form-item
+              label="蹇�掑叕鍙�"
+              prop="expressCompany"
+          >
+            <el-input
+                v-model="formState.expressCompany"
+                placeholder="璇疯緭鍏ュ揩閫掑叕鍙�"
+                style="width: 240px"
+            />
+          </el-form-item>
+          <el-form-item
+              label="蹇�掑崟鍙�"
+              prop="expressNo"
+          >
+            <el-input
+                v-model="formState.expressNo"
+                placeholder="璇疯緭鍏ュ揩閫掑崟鍙�"
+                style="width: 240px"
+            />
+          </el-form-item>
+        </template>
+
+        <el-form-item
             label="渚涘簲鍟嗗悕绉�"
             prop="supplierId"
             :rules="[
@@ -70,6 +129,7 @@
               v-model="formState.supplierId"
               placeholder="璇烽�夋嫨渚涘簲鍟�"
               style="width: 240px"
+							filterable
               @focus="fetchSupplierOptions"
               @change="handleChangeSupplierId"
           >
@@ -220,18 +280,19 @@
           <el-input style="width: 240px" v-model="formState.remark" :rows="1" type="textarea" placeholder="璇疯緭鍏ュ娉�"/>
         </el-form-item>
 
-        <div style="margin: 20px 0;">
+        <div style="margin:20px 0;min-width:0;">
             <div class="section-title">
               <span class="title-dot"></span>
               <span class="title-text">浜у搧鍒楄〃</span>
             </div>
-            <el-button type="primary" size="small" style="margin-bottom: 20px" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">娣诲姞浜у搧</el-button>
-            <el-table :data="formState.purchaseReturnOrderProductsDtos"
+            <el-button type="primary" size="small" style="margin-bottom:20px" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">娣诲姞浜у搧</el-button>
+            <el-table
+                      :data="formState.purchaseReturnOrderProductsDtos"
                       border
                       max-height="400"
-                      :scroll-y="true"
                       show-summary
-                      :summary-method="summarizeChildrenTable">
+                      :summary-method="summarizeChildrenTable"
+                      style="width:100%;min-width:0;">
               <el-table-column align="center"
                                type="selection"
                                width="55" />
@@ -239,6 +300,12 @@
                                label="搴忓彿"
                                type="index"
                                width="60" />
+              <el-table-column label="鍏ュ簱鍗曞彿"
+                               prop="inboundBatches"
+                               width="150" />
+              <el-table-column label="鎵规鍙�"
+                               prop="batchNo"
+                               width="150" />
               <el-table-column label="浜у搧澶х被"
                                prop="productCategory" />
               <el-table-column label="瑙勬牸鍨嬪彿"
@@ -247,11 +314,20 @@
                                prop="unit"
                                width="70" />
               <el-table-column label="鏁伴噺"
-                               prop="quantity"
+                               prop="stockInNum"
                                width="100" />
+              <el-table-column label="閿�鍞彂璐ф暟閲�"
+                               prop="saleOutQuantity"
+                               width="120" />
                                <el-table-column label="鍙��璐ф暟閲�"
-                               prop="availableQuality"
+                               prop="unQuantity"
                                width="130" />
+              <el-table-column label="宸查��璐ф暟閲�"
+                               width="130">
+                <template #default="scope">
+                  {{ formattedNumber(scope.row, null, scope.row.totalReturnNum || 0) }}
+                </template>
+              </el-table-column>
               <el-table-column label="閫�璐ф暟閲�"
                                prop="returnQuantity"
                                width="180">
@@ -267,27 +343,27 @@
                             placeholder="璇疯緭鍏ラ��璐ф暟閲�" />
                 </template>
               </el-table-column>
-              <el-table-column label="搴撳瓨棰勮鏁伴噺"
+              <!-- <el-table-column label="搴撳瓨棰勮鏁伴噺"
                                prop="warnNum"
                                width="120"
                                show-overflow-tooltip />
               <el-table-column label="绋庣巼(%)"
                                prop="taxRate"
-                               width="80" />
+                               width="80" /> -->
               <el-table-column label="鍚◣鍗曚环(鍏�)"
                                prop="taxInclusiveUnitPrice"
                                :formatter="formattedNumber"
-                               width="150" />
+                               width="120" />
               <el-table-column label="閫�璐ф�讳环(鍏�)"
                                prop="taxInclusiveTotalPrice"
-                               width="180">
+                               width="120">
                 <template #default="scope">
                   {{ formatAmount(getReturnTotal(scope.row)) || '--' }}
                 </template>
               </el-table-column>
               <el-table-column label="鏄惁璐ㄦ"
                                prop="isChecked"
-                               width="150">
+                               width="100">
                 <template #default="scope">
                   <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
                     {{ scope.row.isChecked ? '鏄�' : '鍚�' }}
@@ -334,12 +410,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
@@ -399,12 +480,9 @@
 <script setup>
 import {ref, computed, getCurrentInstance, watch, defineAsyncComponent} from "vue";
 import {createPurchaseReturnOrder} from "@/api/procurementManagement/purchase_return_order.js";
-import {getOptions, purchaseList} from "@/api/procurementManagement/procurementLedger.js";
+import {getOptions, purchaseReturnableList} from "@/api/procurementManagement/procurementLedger.js";
 import {userListNoPageByTenantId} from "@/api/system/user.js";
 const ProductList = defineAsyncComponent(() => import("@/views/procurementManagement/purchaseReturnOrder/ProductList.vue"));
-  import {
-    productList,
-  } from "@/api/procurementManagement/procurementLedger.js";
 const props = defineProps({
   visible: {
     type: Boolean,
@@ -412,7 +490,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锛�
@@ -420,6 +515,10 @@
   no: '',
   isDefaultNo: true,
   returnType: 0,
+  shippingType: undefined,
+  truckPlateNo: '',
+  expressCompany: '',
+  expressNo: '',
   incomeType: undefined,
   remark: '',
   supplierId: undefined,
@@ -466,6 +565,19 @@
 // 鏄惁灞曠ず浜у搧鍒楄〃鏁版嵁
 const isShowProductsModal = ref(false)
 
+const handleShippingTypeChange = (val) => {
+  if (val === 1) {
+    formState.value.expressCompany = '';
+    formState.value.expressNo = '';
+  } else if (val === 2) {
+    formState.value.truckPlateNo = '';
+  } else {
+    formState.value.truckPlateNo = '';
+    formState.value.expressCompany = '';
+    formState.value.expressNo = '';
+  }
+};
+
 const isShow = computed({
   get() {
     return props.visible;
@@ -509,8 +621,28 @@
   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)
+  const max = Number(row?.unQuantity)
   if (Number.isNaN(max) || max < 0) {
     return 0
   }
@@ -518,6 +650,10 @@
 }
 
 const closeModal = () => {
+  formState.value.shippingType = undefined;
+  formState.value.truckPlateNo = '';
+  formState.value.expressCompany = '';
+  formState.value.expressNo = '';
   isShow.value = false;
 };
 
@@ -525,30 +661,55 @@
   return proxy.summarizeTable(
       param,
       [
-        "quantity",
-        "availableQuality",
+        "stockInNum",
+        "unQuantity",
         "returnQuantity",
         "taxInclusiveUnitPrice",
         "taxInclusiveTotalPrice",
         "taxExclusiveTotalPrice",
       ],
       {
-        quantity: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
+        stockInNum: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
         returnQuantity: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
-        availableQuality: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
+        unQuantity: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
       }
   );
 };
 
 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))
@@ -586,21 +747,16 @@
 const fetchPurchaseLedgerOptions = () => {
   purchaseLedgerOptions.value = []
   if (formState.value.supplierId) {
-    purchaseList({supplierId: formState.value.supplierId,approvalStatus:3}).then((res) => {
+    purchaseReturnableList({ supplierId: formState.value.supplierId }).then((res) => {
       purchaseLedgerOptions.value = res.rows;
     });
   }
 }
 
-// 澶勭悊鏀瑰彉閲囪喘鍙拌处鏁版嵁
-const handleChangePurchaseLedgerId = async () => {
-  const res = await productList({ salesLedgerId: formState.value.purchaseLedgerId, type: 2 });
-  formState.value.purchaseReturnOrderProductsDtos = res.data.map(item => ({
-    ...item,
-    returnQuantity: undefined,
-    taxInclusiveTotalPrice: 0,
-    salesLedgerProductId: item.id,
-  }))
+// 澶勭悊鏀瑰彉閲囪喘鍙拌处鏁版嵁锛堜笉璇锋眰鎺ュ彛鍥炴樉浜у搧锛屼骇鍝佷粎鍦ㄣ�屾坊鍔犱骇鍝併�嶅脊绐楀嬀閫夊悗鍐欏叆锛�
+const handleChangePurchaseLedgerId = () => {
+  resetFeeInfo()
+  formState.value.purchaseReturnOrderProductsDtos = []
   syncTotalAmount()
 }
 
@@ -618,7 +774,7 @@
     ...item,
     returnQuantity: undefined,
     taxInclusiveTotalPrice: 0,
-    salesLedgerProductId: item.id,
+    // salesLedgerProductId: item.salesLedgerProductId,
   }));
   formState.value.purchaseReturnOrderProductsDtos.push(...newProducts);
   syncTotalAmount()
@@ -644,7 +800,7 @@
   // 閫愯鏍¢獙閫�璐ф暟閲忥細浠绘剰涓�琛屾湭濉�/闈炴硶/瓒呴檺閮戒笉鍏佽鎻愪氦
   const invalidRowIndex = productList.findIndex((item) => {
     const qty = Number(item.returnQuantity)
-    const maxQty = Number(item.availableQuality)
+    const maxQty = Number(item.unQuantity)
 
     if (item.returnQuantity === null || item.returnQuantity === undefined || item.returnQuantity === "") {
       return true
@@ -665,7 +821,15 @@
 
   proxy.$refs["formRef"].validate(valid => {
     if (valid) {
-      createPurchaseReturnOrder(formState.value).then(res => {
+      console.log(productList)
+      const submitPayload = {
+        ...formState.value,
+        purchaseReturnOrderProductsDtos: productList.map((row) => ({
+          ...row,
+          stockInRecordId: row.id,
+        })),
+      }
+      createPurchaseReturnOrder(submitPayload).then(res => {
         // 鍏抽棴妯℃�佹
         isShow.value = false;
         // 鍛婄煡鐖剁粍浠跺凡瀹屾垚
@@ -712,4 +876,6 @@
   border-radius: 50%;
   margin-right: 8px;
 }
-</style>
\ No newline at end of file
+
+
+</style>

--
Gitblit v1.9.3