From 71d274a839cdc1f8f70b45abe53c750a0f9a2a14 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期二, 29 九月 2026 11:23:42 +0800
Subject: [PATCH] Merge branch 'dev_pro_山西长治_鹤壁版' of http://114.132.189.42:9002/r/product-inventory-management into dev_pro_山西长治_鹤壁版

---
 src/views/customerService/feedbackRegistration/components/formDia.vue |  173 +++++++++++++++++++++++++++++++--------------------------
 1 files changed, 95 insertions(+), 78 deletions(-)

diff --git a/src/views/customerService/feedbackRegistration/components/formDia.vue b/src/views/customerService/feedbackRegistration/components/formDia.vue
index e606107..2a67073 100644
--- a/src/views/customerService/feedbackRegistration/components/formDia.vue
+++ b/src/views/customerService/feedbackRegistration/components/formDia.vue
@@ -127,9 +127,9 @@
   import {
     afterSalesServiceAdd,
     afterSalesServiceUpdate,
-    getAllCustomerList,
     getSalesLedger,
   } from "@/api/customerService/index.js";
+  import { ledgerListNoPage, productList as getSalesLedgerProductList } from "@/api/salesManagement/salesLedger.js";
   import { getCurrentDate } from "@/utils/index.js";
   const { proxy } = getCurrentInstance();
   const emit = defineEmits(["close"]);
@@ -288,57 +288,68 @@
       .filter(item => item !== undefined && item !== null && item !== "");
   });
 
+  const associatedSalesOrderNumberOptions = ref([]);
+  // 褰撳墠閿�鍞崟鍙蜂笅鐨勪骇鍝佹睜锛屼緵鈥滈�夋嫨浜у搧鈥濆脊绐椾娇鐢�
+  const salesLedgerProducts = ref([]);
+
+  const loadSalesLedgerOptions = customerId => {
+    if (!customerId) {
+      associatedSalesOrderNumberOptions.value = [];
+      return Promise.resolve([]);
+    }
+    return getSalesLedger({ customerId }).then(res => {
+      const records = res?.code === 200 ? res.data?.records || [] : [];
+      associatedSalesOrderNumberOptions.value = records.map(item => ({
+        label: item.salesContractNo,
+        value: item.salesContractNo,
+        id: item.id,
+      }));
+      return records;
+    });
+  };
+
+  const loadSalesLedgerProducts = salesLedgerId => {
+    if (!salesLedgerId) {
+      salesLedgerProducts.value = [];
+      return Promise.resolve([]);
+    }
+    return getSalesLedgerProductList({ salesLedgerId, type: 1 }).then(res => {
+      const rows = Array.isArray(res?.data) ? res.data : [];
+      salesLedgerProducts.value = rows.map(normalizeProductRow);
+      return salesLedgerProducts.value;
+    });
+  };
+
   const associatedSalesOrderNumberChange = () => {
     const opt = associatedSalesOrderNumberOptions.value.find(
       item => item.value === form.value.salesContractNo
     );
-    tableData.value = (opt?.productData || []).map(normalizeProductRow);
     form.value.salesLedgerId = opt?.id || null;
+    tableData.value = [];
+    loadSalesLedgerProducts(form.value.salesLedgerId).then(products => {
+      tableData.value = products.map(row => ({ ...row }));
+    });
   };
 
-  const associatedSalesOrderNumberOptions = ref([]);
-
-  const currentSalesOrderProducts = computed(() => {
-    const opt = associatedSalesOrderNumberOptions.value.find(
-      item => item.value === form.value.salesContractNo
-    );
-    return (opt?.productData || []).map(normalizeProductRow);
-  });
+  const currentSalesOrderProducts = computed(() => salesLedgerProducts.value);
 
   const customerNameChange = val => {
     form.value.salesContractNo = "";
     form.value.salesLedgerId = null;
     tableData.value = [];
+    salesLedgerProducts.value = [];
     associatedSalesOrderNumberOptions.value = [];
     const opt = customerNameOptions.value.find(item => item.value === val);
-    if (opt) {
-      form.value.customerId = opt.id;
-    } else {
-      form.value.customerId = null;
-    }
-    getSalesLedger({
-      customerId: form.value.customerId,
-    }).then(res => {
-      if (res.code === 200) {
-        associatedSalesOrderNumberOptions.value = res.data.records.map(item => ({
-          label: item.salesContractNo,
-          value: item.salesContractNo,
-          productData: item.productData,
-          id: item.id,
-        }));
-      }
-    });
+    form.value.customerId = opt ? opt.id : null;
+    loadSalesLedgerOptions(form.value.customerId);
   };
 
   const getApproveStatusText = row => {
     if (!row) return "涓嶈冻";
-    if (
-      row.approveStatus === 1 &&
-      (!row.shippingDate || !row.shippingCarNumber)
-    ) {
+    if (row.approveStatus === 1) {
       return "鍏呰冻";
     }
-    if (row.approveStatus === 0 && (row.shippingDate || row.shippingCarNumber)) {
+    if (row.approveStatus === 0 && Number(row.noQuantity) === 0) {
       return "宸插嚭搴�";
     }
     return "涓嶈冻";
@@ -364,6 +375,7 @@
       瀹℃牳涓�: "瀹℃牳涓�",
       瀹℃牳鎷掔粷: "瀹℃牳鎷掔粷",
       瀹℃牳閫氳繃: "瀹℃牳閫氳繃",
+      閮ㄥ垎鍙戣揣: "閮ㄥ垎鍙戣揣",
       宸插彂璐�: "宸插彂璐�",
     };
     return map[String(status).trim()] || "寰呭彂璐�";
@@ -384,29 +396,36 @@
       瀹℃牳涓�: "warning",
       瀹℃牳鎷掔粷: "danger",
       瀹℃牳閫氳繃: "success",
+      閮ㄥ垎鍙戣揣: "warning",
       宸插彂璐�: "success",
     };
     return map[String(status).trim()] || "info";
   };
 
+  // 瀹㈡埛涓嬫媺浠呭睍绀洪攢鍞彴璐︿腑瀛樺湪璁板綍鐨勫鎴�
+  const loadLedgerCustomerOptions = () => {
+    return ledgerListNoPage({}).then(res => {
+      const rows = Array.isArray(res?.data) ? res.data : [];
+      const seen = new Set();
+      const options = [];
+      rows.forEach(row => {
+        const customerName = row?.customerName;
+        const customerId = row?.customerId;
+        if (!customerName || customerId === null || customerId === undefined) {
+          return;
+        }
+        if (seen.has(customerName)) return;
+        seen.add(customerName);
+        options.push({ label: customerName, value: customerName, id: customerId });
+      });
+      customerNameOptions.value = options;
+    });
+  };
+
   // 鎵撳紑寮规
   const openDialog = async (type, row) => {
     // 璇锋眰澶氫釜鎺ュ彛锛岃幏鍙栨暟鎹�
-    let res = await getAllCustomerList({
-      current: 1,
-      size: 1000,
-      total: 0,
-    });
-    console.log(res, "res");
-
-    if (res.data.records) {
-      customerNameOptions.value = res.data.records.map(item => ({
-        label: item.customerName,
-        value: item.customerName,
-        id: item.id,
-      }));
-    } else {
-    }
+    await loadLedgerCustomerOptions();
 
     operationType.value = type;
     dialogFormVisible.value = true;
@@ -417,44 +436,42 @@
     // 鏂板鏃舵竻绌哄凡閫夊叧鑱斾骇鍝�
     if (type === "add") {
       tableData.value = [];
+      salesLedgerProducts.value = [];
+      associatedSalesOrderNumberOptions.value = [];
     }
     userListNoPageByTenantId().then(res => {
       userList.value = res.data;
     });
     if (type === "edit") {
       form.value = { ...row };
-      if (form.value.customerName) {
-        const res = await getSalesLedger({
-          customerId: form.value.customerId,
-        });
-        if (res?.code === 200) {
-          console.log(res);
-          associatedSalesOrderNumberOptions.value = (res.data?.records || []).map(
-            item => ({
-              label: item.salesContractNo,
-              value: item.salesContractNo,
-              productData: item.productData,
-              id: item.id,
-            })
-          );
-          const opt = associatedSalesOrderNumberOptions.value.find(
-            item => item.value === form.value.salesContractNo
-          );
-          if (opt) {
-            let restoredData = (opt.productData || []).map(normalizeProductRow);
-            const selectedIds = form.value.productModelIds ? String(form.value.productModelIds).split(",") : [];
-            const quantities = form.value.productModelQuantities ? String(form.value.productModelQuantities).split(",") : [];
-            tableData.value = restoredData.filter(item => selectedIds.includes(String(item.id))).map(item => {
-              let qIndex = selectedIds.indexOf(String(item.id));
-              if (qIndex !== -1 && qIndex < quantities.length && quantities[qIndex] !== "") {
-                 item.quantity = Number(quantities[qIndex]);
-              }
-              return item;
-            });
-          }
-        }
+      // 鍞悗鍗曞彧瀛樹簡瀹㈡埛鍚嶇О锛岃繖閲屾寜鍚嶇О鍙嶆煡瀹㈡埛 ID
+      if (!form.value.customerId && form.value.customerName) {
+        const customer = customerNameOptions.value.find(
+          item => item.value === form.value.customerName
+        );
+        form.value.customerId = customer?.id ?? null;
       }
-      console.log(form.value);
+      await loadSalesLedgerOptions(form.value.customerId);
+      const products = await loadSalesLedgerProducts(form.value.salesLedgerId);
+      const selectedIds = form.value.productModelIds
+        ? String(form.value.productModelIds).split(",")
+        : [];
+      const quantities = form.value.productModelQuantities
+        ? String(form.value.productModelQuantities).split(",")
+        : [];
+      tableData.value = products
+        .filter(item => selectedIds.includes(String(item.id)))
+        .map(item => {
+          const qIndex = selectedIds.indexOf(String(item.id));
+          if (
+            qIndex !== -1 &&
+            qIndex < quantities.length &&
+            quantities[qIndex] !== ""
+          ) {
+            item.quantity = Number(quantities[qIndex]);
+          }
+          return item;
+        });
     }
   };
   const submitForm = () => {

--
Gitblit v1.9.3