From f3cec0341563c2c0dd4f5df609d0689c6c450bfc Mon Sep 17 00:00:00 2001
From: ZN <zhang_12370@163.com>
Date: 星期六, 21 三月 2026 17:11:12 +0800
Subject: [PATCH] feat(采购退货): 增加退货详情查看功能并完善退货流程

---
 src/views/procurementManagement/purchaseReturnOrder/New.vue |  441 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 332 insertions(+), 109 deletions(-)

diff --git a/src/views/procurementManagement/purchaseReturnOrder/New.vue b/src/views/procurementManagement/purchaseReturnOrder/New.vue
index 1fccb11..f130733 100644
--- a/src/views/procurementManagement/purchaseReturnOrder/New.vue
+++ b/src/views/procurementManagement/purchaseReturnOrder/New.vue
@@ -3,10 +3,14 @@
     <el-dialog
         v-model="isShow"
         title="鏂板閲囪喘閫�璐�"
-        width="1200"
+        width="1600"
         @close="closeModal"
     >
       <el-form label-width="140px" :model="formState" label-position="top" ref="formRef" :inline="true">
+        <div class="section-title">
+          <span class="title-dot"></span>
+          <span class="title-text">鍩烘湰淇℃伅</span>
+        </div>
         <el-form-item
             label="閫�鏂欏崟鍙�"
             prop="no"
@@ -22,6 +26,7 @@
               v-model="formState.no"
               :placeholder="formState.isDefaultNo ? '浣跨敤绯荤粺缂栧彿' : '璇疯緭鍏ラ��鏂欏崟鍙�'"
               :disabled="formState.isDefaultNo"
+              style="width: 240px"
           >
             <template #append>
               <el-checkbox v-model="formState.isDefaultNo" size="large" @change="handleChangeIsDefaultNo" />
@@ -73,25 +78,6 @@
               :key="item.id"
               :label="item.supplierName"
               :value="item.id"
-            />
-          </el-select>
-        </el-form-item>
-
-        <el-form-item
-            label="椤圭洰"
-            prop="projectId"
-        >
-          <el-select
-              v-model="formState.projectId"
-              placeholder="璇烽�夋嫨椤圭洰"
-              style="width: 240px"
-              @focus="fetchProjectOptions"
-          >
-            <el-option
-                v-for="item in projectOptions"
-                :key="item.id"
-                :label="item.name"
-                :value="item.id"
             />
           </el-select>
         </el-form-item>
@@ -155,6 +141,7 @@
               :reserve-keyword="false"
               style="width: 240px"
               @focus="fetchUserOptions"
+              @change="formState.preparedUserName = userOptions.find(item => item.userId === formState.preparedUserId)?.nickName || ''"
           >
             <el-option
                 v-for="item in userOptions"
@@ -185,6 +172,7 @@
               style="width: 240px"
               :reserve-keyword="false"
               @focus="fetchUserOptions"
+              @change="formState.returnUserName = userOptions.find(item => item.userId === formState.returnUserId)?.nickName || ''"
           >
             <el-option
                 v-for="item in userOptions"
@@ -229,80 +217,167 @@
             label="澶囨敞锛�"
             prop="remark"
         >
-          <el-input v-model="formState.remark" type="textarea" placeholder="璇疯緭鍏ュ娉�"/>
+          <el-input style="width: 240px" v-model="formState.remark" :rows="1" type="textarea" placeholder="璇疯緭鍏ュ娉�"/>
         </el-form-item>
-      </el-form>
 
-      <el-button type="primary" size="small" style="margin-bottom: 10px;" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">娣诲姞浜у搧</el-button>
-      <el-table :data="products" border>
-        <el-table-column align="center"
-                         type="selection"
-                         width="55" />
-        <el-table-column align="center"
-                         label="搴忓彿"
-                         type="index"
-                         width="60" />
-        <el-table-column label="浜у搧澶х被"
-                         prop="productCategory" />
-        <el-table-column label="瑙勬牸鍨嬪彿"
-                         prop="specificationModel" />
-        <el-table-column label="鍗曚綅"
-                         prop="unit"
-                         width="70" />
-        <el-table-column label="鏁伴噺"
-                         prop="quantity"
-                         width="70" />
-        <el-table-column label="搴撳瓨棰勮鏁伴噺"
-                         prop="warnNum"
-                         width="120"
-                         show-overflow-tooltip />
-        <el-table-column label="绋庣巼(%)"
-                         prop="taxRate"
-                         width="80" />
-        <el-table-column label="鍚◣鍗曚环(鍏�)"
-                         prop="taxInclusiveUnitPrice"
-                         :formatter="formattedNumber"
-                         width="150" />
-        <el-table-column label="鍚◣鎬讳环(鍏�)"
-                         prop="taxInclusiveTotalPrice"
-                         :formatter="formattedNumber"
-                         width="150" />
-        <el-table-column label="涓嶅惈绋庢�讳环(鍏�)"
-                         prop="taxExclusiveTotalPrice"
-                         :formatter="formattedNumber"
-                         width="150" />
-        <el-table-column label="鏄惁璐ㄦ"
-                         prop="isChecked"
-                         width="150">
-          <template #default="scope">
-            <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
-              {{ scope.row.isChecked ? '鏄�' : '鍚�' }}
-            </el-tag>
-          </template>
-        </el-table-column>
-        <el-table-column fixed="right"
-                         label="鎿嶄綔"
-                         width="120"
-                         align="center">
-          <template #default="scope">
-            <el-button
-              link
-              type="primary"
-              size="small"
-            >
-              缂栬緫
-            </el-button>
-            <el-button
-                link
-                type="danger"
-                size="small"
-                @click="delProduct(scope.$index)"
-            >
-              鍒犻櫎
-            </el-button>
-          </template>
-        </el-table-column>
-      </el-table>
+        <div style="margin: 20px 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"
+                      border
+                      max-height="400"
+                      :scroll-y="true"
+                      show-summary
+                      :summary-method="summarizeChildrenTable">
+              <el-table-column align="center"
+                               type="selection"
+                               width="55" />
+              <el-table-column align="center"
+                               label="搴忓彿"
+                               type="index"
+                               width="60" />
+              <el-table-column label="浜у搧澶х被"
+                               prop="productCategory" />
+              <el-table-column label="瑙勬牸鍨嬪彿"
+                               prop="specificationModel" />
+              <el-table-column label="鍗曚綅"
+                               prop="unit"
+                               width="70" />
+              <el-table-column label="鏁伴噺"
+                               prop="quantity"
+                               width="100" />
+                               <el-table-column label="鍙��璐ф暟閲�"
+                               prop="availableQuality"
+                               width="130" />
+              <el-table-column label="閫�璐ф暟閲�"
+                               prop="returnQuantity"
+                               width="180">
+                <template #default="scope">
+                  <el-input-number v-model="scope.row.returnQuantity"
+                            controls-position="right"
+                            :step="1"
+                            :min="0"
+                            :max="getReturnQtyMax(scope.row)"
+                            :disabled="getReturnQtyMax(scope.row) <= 0"
+                            @change="syncReturnTotal(scope.row)"
+                            required
+                            placeholder="璇疯緭鍏ラ��璐ф暟閲�" />
+                </template>
+              </el-table-column>
+              <el-table-column label="搴撳瓨棰勮鏁伴噺"
+                               prop="warnNum"
+                               width="120"
+                               show-overflow-tooltip />
+              <el-table-column label="绋庣巼(%)"
+                               prop="taxRate"
+                               width="80" />
+              <el-table-column label="鍚◣鍗曚环(鍏�)"
+                               prop="taxInclusiveUnitPrice"
+                               :formatter="formattedNumber"
+                               width="150" />
+              <el-table-column label="閫�璐ф�讳环(鍏�)"
+                               prop="taxInclusiveTotalPrice"
+                               width="180">
+                <template #default="scope">
+                  {{ formatAmount(getReturnTotal(scope.row)) || '--' }}
+                </template>
+              </el-table-column>
+              <el-table-column label="鏄惁璐ㄦ"
+                               prop="isChecked"
+                               width="150">
+                <template #default="scope">
+                  <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
+                    {{ scope.row.isChecked ? '鏄�' : '鍚�' }}
+                  </el-tag>
+                </template>
+              </el-table-column>
+              <el-table-column fixed="right"
+                               label="鎿嶄綔"
+                               width="100"
+                               align="center">
+                <template #default="scope">
+                  <el-button
+                      link
+                      type="danger"
+                      size="small"
+                      @click="delProduct(scope.$index)"
+                  >
+                    鍒犻櫎
+                  </el-button>
+                </template>
+              </el-table-column>
+            </el-table>
+          </div>
+
+        <div class="section-title">
+          <span class="title-dot"></span>
+          <span class="title-text">璐圭敤淇℃伅</span>
+        </div>
+
+        <el-form-item
+            label="鏁村崟鎶樻墸棰濓細"
+            prop="totalDiscountAmount"
+        >
+          <el-input-number v-model="formState.totalDiscountAmount"
+                           controls-position="right"
+                           :step="0.01"
+                           :precision="2"
+                           style="width: 100%;"
+                           @change="handleChangeTotalDiscountAmount"
+                           placeholder="璇疯緭鍏ユ暣鍗曟姌鎵i"/>
+        </el-form-item>
+
+        <el-form-item
+            label="鏁村崟鎶樻墸鐜囷細"
+            prop="totalDiscountAmount"
+        >
+          <el-input-number v-model="formState.totalDiscountRate"
+                           controls-position="right"
+                           :step="0.01"
+                           :precision="2"
+                           style="width: 100%;"
+                           placeholder="璇疯緭鍏ユ暣鍗曟姌鎵g巼"/>
+        </el-form-item>
+
+        <el-form-item
+            label="鎴愪氦閲戦锛�"
+            prop="totalAmount"
+            :rules="[
+              {
+                required: true,
+                message: '璇疯緭鍏ユ垚浜ら噾棰�',
+                trigger: 'change',
+              }
+            ]"
+        >
+          <el-input-number v-model="formState.totalAmount"
+                           controls-position="right"
+                           :step="0.01"
+                           :precision="2"
+                           style="width: 100%;"
+                           placeholder="璇疯緭鍏ユ垚浜ら噾棰�"/>
+        </el-form-item>
+        <el-form-item label="鏀舵鏂瑰紡" prop="incomeType" :rules="[
+              {
+                required: true,
+                message: '璇烽�夋嫨鏀舵鏂瑰紡',
+                trigger: 'change',
+              }
+            ]">
+        <el-select
+          style="width: 240px;"
+          v-model="formState.incomeType"
+          placeholder="璇烽�夋嫨"
+          clearable
+          
+        >
+          <el-option :label="item.label" :value="item.value" v-for="(item,index) in payment_methods" :key="index" />
+        </el-select>
+      </el-form-item>
+      </el-form>
       <template #footer>
         <div class="dialog-footer">
           <el-button type="primary" @click="handleSubmit">纭</el-button>
@@ -322,11 +397,14 @@
 </template>
 
 <script setup>
-import {ref, computed, getCurrentInstance} from "vue";
+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 {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,
@@ -334,6 +412,7 @@
   }
 });
 let { proxy } = getCurrentInstance()
+const { payment_methods } = proxy.useDict("payment_methods");
 const emit = defineEmits(['update:visible', 'completed']);
 
 // 鍝嶅簲寮忔暟鎹紙鏇夸唬閫夐」寮忕殑 data锛�
@@ -341,6 +420,7 @@
   no: '',
   isDefaultNo: true,
   returnType: 0,
+  incomeType: undefined,
   remark: '',
   supplierId: undefined,
   projectId: undefined,
@@ -349,11 +429,13 @@
   preparedUserId: undefined,
   returnUserId: undefined,
   purchaseLedgerId: undefined,
+  purchaseReturnOrderProductsDtos: [],
+  totalDiscountAmount: 0,
+  totalDiscountRate: undefined,
+  totalAmount: 0,
 });
 // 渚涘簲鍟嗛�夐」
 const supplierOptions = ref([])
-// 椤圭洰閫夐」
-const projectOptions = ref([])
 // 椤圭洰闃舵閫夐」
 const projectStageOptions = ref([
   {
@@ -381,8 +463,6 @@
 const userOptions = ref([])
 // 閲囪喘鍙拌处閫夐」
 const purchaseLedgerOptions = ref([])
-// 浜у搧鍒楄〃鏁版嵁
-const products = ref([])
 // 鏄惁灞曠ず浜у搧鍒楄〃鏁版嵁
 const isShowProductsModal = ref(false)
 
@@ -399,9 +479,80 @@
   return parseFloat(cellValue).toFixed(2);
 };
 
+const formatAmount = (value) => {
+  if (value === null || value === undefined || value === '') {
+    return '--'
+  }
+  const num = Number(value)
+  if (Number.isNaN(num)) {
+    return '--'
+  }
+  return num.toFixed(2)
+}
+
+const toNumber = (val) => {
+  const num = Number(val)
+  return Number.isNaN(num) ? 0 : num
+}
+
+const getReturnTotal = (row) => {
+  const qty = toNumber(row?.returnQuantity)
+  const unitPrice = toNumber(row?.taxInclusiveUnitPrice)
+  const total = qty * unitPrice
+  return Number(total.toFixed(2))
+}
+
+const syncReturnTotal = (row) => {
+  if (!row) {
+    return
+  }
+  row.taxInclusiveTotalPrice = getReturnTotal(row)
+}
+
+const getReturnQtyMax = (row) => {
+  const max = Number(row?.availableQuality)
+  if (Number.isNaN(max) || max < 0) {
+    return 0
+  }
+  return max
+}
+
 const closeModal = () => {
   isShow.value = false;
 };
+
+const summarizeChildrenTable = (param) => {
+  return proxy.summarizeTable(
+      param,
+      [
+        "quantity",
+        "availableQuality",
+        "returnQuantity",
+        "taxInclusiveUnitPrice",
+        "taxInclusiveTotalPrice",
+        "taxExclusiveTotalPrice",
+      ],
+      {
+        quantity: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
+        returnQuantity: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
+        availableQuality: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
+      }
+  );
+};
+
+const handleChangeTotalDiscountAmount= () => {
+  syncTotalAmount()
+}
+
+const syncTotalAmount = () => {
+  const rows = formState.value.purchaseReturnOrderProductsDtos || []
+  const baseAmount = rows.reduce((sum, item) => {
+    return sum + toNumber(item.taxInclusiveTotalPrice)
+  }, 0)
+  const discount = toNumber(formState.value.totalDiscountAmount)
+  // 鎴愪氦閲戦 = 浜у搧閫�璐ф�讳环鍚堣 - 鎶樻墸棰�
+  formState.value.totalAmount = Number((baseAmount - discount).toFixed(2))
+}
 
 // 鑾峰彇渚涘簲鍟嗛�夐」
 const fetchSupplierOptions = () => {
@@ -413,13 +564,6 @@
   });
 }
 
-// 鑾峰彇椤圭洰閫夐」
-const fetchProjectOptions = () => {
-  if (projectOptions.value.length > 0) {
-    return
-  }
-  // todo 椤圭洰閫夐」
-}
 
 // 鑾峰彇鐢ㄦ埛閫夐」
 const fetchUserOptions = () => {
@@ -434,6 +578,7 @@
 // 澶勭悊鏀瑰彉渚涘簲鍟嗘暟鎹�
 const handleChangeSupplierId = () => {
   formState.value.purchaseLedgerId = undefined
+  formState.value.supplierName = supplierOptions.value.find(item => item.id === formState.value.supplierId)?.supplierName || ''
   fetchPurchaseLedgerOptions()
 }
 
@@ -441,15 +586,22 @@
 const fetchPurchaseLedgerOptions = () => {
   purchaseLedgerOptions.value = []
   if (formState.value.supplierId) {
-    purchaseList({supplierId: formState.value.supplierId}).then((res) => {
+    purchaseList({supplierId: formState.value.supplierId,approvalStatus:3}).then((res) => {
       purchaseLedgerOptions.value = res.rows;
     });
   }
 }
 
 // 澶勭悊鏀瑰彉閲囪喘鍙拌处鏁版嵁
-const handleChangePurchaseLedgerId = () => {
-  products.value = []
+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,
+  }))
+  syncTotalAmount()
 }
 
 // 澶勭悊鏀瑰彉鏄惁榛樿缂栧彿
@@ -461,16 +613,56 @@
 
 // 澧炲姞浜у搧
 const handleAddProduct = (selectedRows) => {
-  products.value.push(...selectedRows)
+  const existingIds = new Set(formState.value.purchaseReturnOrderProductsDtos.map(item => item.id));
+  const newProducts = selectedRows.filter(item => !existingIds.has(item.id)).map(item => ({
+    ...item,
+    returnQuantity: undefined,
+    taxInclusiveTotalPrice: 0,
+    salesLedgerProductId: item.id,
+  }));
+  formState.value.purchaseReturnOrderProductsDtos.push(...newProducts);
+  syncTotalAmount()
 }
 
 // 鍒犻櫎鍗曢」浜у搧
 const delProduct = (index) => {
-  products.value.splice(index, 1)
+  formState.value.purchaseReturnOrderProductsDtos.splice(index, 1)
+  syncTotalAmount()
 }
 
 // 鎻愪氦琛ㄥ崟
 const handleSubmit = () => {
+  const productList = formState.value.purchaseReturnOrderProductsDtos || []
+
+  productList.forEach(syncReturnTotal)
+
+  if (productList.length === 0) {
+    proxy.$modal.msgError("璇峰厛閫夋嫨浜у搧")
+    return
+  }
+
+  // 閫愯鏍¢獙閫�璐ф暟閲忥細浠绘剰涓�琛屾湭濉�/闈炴硶/瓒呴檺閮戒笉鍏佽鎻愪氦
+  const invalidRowIndex = productList.findIndex((item) => {
+    const qty = Number(item.returnQuantity)
+    const maxQty = Number(item.availableQuality)
+
+    if (item.returnQuantity === null || item.returnQuantity === undefined || item.returnQuantity === "") {
+      return true
+    }
+    if (Number.isNaN(qty) || qty <= 0) {
+      return true
+    }
+    if (!Number.isNaN(maxQty) && maxQty > 0 && qty > maxQty) {
+      return true
+    }
+    return false
+  })
+
+  if (invalidRowIndex !== -1) {
+    proxy.$modal.msgError(`绗�${invalidRowIndex + 1}琛岄��璐ф暟閲忔湭濉啓鎴栦笉鍚堟硶`)
+    return
+  }
+
   proxy.$refs["formRef"].validate(valid => {
     if (valid) {
       createPurchaseReturnOrder(formState.value).then(res => {
@@ -484,9 +676,40 @@
   })
 };
 
+watch(
+  () => formState.value.purchaseReturnOrderProductsDtos,
+  (rows) => {
+    (rows || []).forEach(syncReturnTotal)
+    syncTotalAmount()
+  },
+  { deep: true }
+)
+
 defineExpose({
   closeModal,
   handleSubmit,
   isShow,
 });
 </script>
+
+<style scoped lang="scss">
+.section-title {
+  display: flex;
+  align-items: center;
+  margin-bottom: 20px;
+  font-size: 16px;
+  font-weight: 600;
+  color: #303133;
+  width: 100%;
+  clear: both;
+}
+
+.title-dot {
+  display: inline-block;
+  width: 8px;
+  height: 8px;
+  background-color: #409EFF;
+  border-radius: 50%;
+  margin-right: 8px;
+}
+</style>
\ No newline at end of file

--
Gitblit v1.9.3