From b3af089315a98903163a394a3b1ca0e4c634b9ab Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 14 一月 2026 17:51:37 +0800
Subject: [PATCH] Merge branch 'dev_New' of http://114.132.189.42:9002/r/product-inventory-management into dev_New

---
 src/views/salesManagement/salesLedger/index.vue |  195 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 192 insertions(+), 3 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 6fa5859..6fe7057 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -98,6 +98,11 @@
       @confirm="submitForm"
       @cancel="closeDia">
       <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
+        <el-row v-if="operationType !== 'view'">
+          <el-col :span="24" style="display:flex; justify-content:flex-end; gap:10px; margin-bottom: 6px;">
+            <el-button type="primary" plain @click="openQuotationDialog">浠庡鎵归�氳繃鐨勬姤浠峰崟瀵煎叆</el-button>
+          </el-col>
+        </el-row>
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="閿�鍞悎鍚屽彿锛�" prop="salesContractNo">
@@ -203,6 +208,62 @@
         </el-row>
       </el-form>
     </FormDialog>
+
+    <!-- 浠庢姤浠峰崟瀵煎叆锛堜粎瀹℃壒閫氳繃锛� -->
+    <el-dialog
+      v-model="quotationDialogVisible"
+      title="閫夋嫨瀹℃壒閫氳繃鐨勯攢鍞姤浠峰崟"
+      width="80%"
+      :close-on-click-modal="false"
+    >
+      <div style="margin-bottom: 12px; display:flex; gap: 12px; align-items:center;">
+        <el-input
+          v-model="quotationSearchForm.quotationNo"
+          placeholder="璇疯緭鍏ユ姤浠峰崟鍙�"
+          clearable
+          style="max-width: 260px;"
+          @change="fetchQuotationList"
+        />
+        <el-input
+          v-model="quotationSearchForm.customer"
+          placeholder="璇疯緭鍏ュ鎴峰悕绉�"
+          clearable
+          style="max-width: 260px;"
+          @change="fetchQuotationList"
+        />
+        <el-button type="primary" @click="fetchQuotationList">鎼滅储</el-button>
+        <el-button @click="resetQuotationSearch">閲嶇疆</el-button>
+      </div>
+
+      <el-table
+        :data="quotationList"
+        border
+        stripe
+        v-loading="quotationLoading"
+        height="420px"
+      >
+        <el-table-column align="center" label="搴忓彿" type="index" width="60" />
+        <el-table-column prop="quotationNo" label="鎶ヤ环鍗曞彿" width="180" show-overflow-tooltip />
+        <el-table-column prop="customer" label="瀹㈡埛鍚嶇О" min-width="220" show-overflow-tooltip />
+        <el-table-column prop="salesperson" label="涓氬姟鍛�" width="120" show-overflow-tooltip />
+        <el-table-column prop="quotationDate" label="鎶ヤ环鏃ユ湡" width="140" />
+        <el-table-column prop="status" label="瀹℃壒鐘舵��" width="120" align="center" />
+        <el-table-column prop="totalAmount" label="鎶ヤ环閲戦(鍏�)" width="160" align="right">
+          <template #default="scope">
+            {{ Number(scope.row.totalAmount ?? 0).toFixed(2) }}
+          </template>
+        </el-table-column>
+        <el-table-column fixed="right" label="鎿嶄綔" width="120" align="center">
+          <template #default="scope">
+            <el-button type="primary" link @click="applyQuotation(scope.row)">閫夋嫨</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+
+      <template #footer>
+        <el-button @click="quotationDialogVisible = false">鍏抽棴</el-button>
+      </template>
+    </el-dialog>
     <FormDialog 
       v-model="productFormVisible" 
       :title="productOperationType === 'add' ? '鏂板浜у搧' : '缂栬緫浜у搧'" 
@@ -461,6 +522,7 @@
 import { userListNoPage } from "@/api/system/user.js";
 import FileListDialog from '@/components/Dialog/FileListDialog.vue';
 import FormDialog from '@/components/Dialog/FormDialog.vue';
+import { getQuotationList } from "@/api/salesManagement/salesQuotation.js";
 import {
 	ledgerListPage,
 	productList,
@@ -576,6 +638,16 @@
 const printPreviewVisible = ref(false);
 const printData = ref([]);
 
+// 鎶ヤ环鍗曞鍏ョ浉鍏�
+const quotationDialogVisible = ref(false);
+const quotationLoading = ref(false);
+const quotationList = ref([]);
+const quotationSearchForm = reactive({
+  quotationNo: "",
+  customer: "",
+});
+const selectedQuotation = ref(null);
+
 // 鍙戣揣鐩稿叧
 const deliveryFormVisible = ref(false);
 const currentDeliveryRow = ref(null);
@@ -644,8 +716,10 @@
 };
 // 鑾峰彇浜у搧澶х被tree鏁版嵁
 const getProductOptions = () => {
-  productTreeList().then((res) => {
+  // 杩斿洖 Promise锛屼究浜庡湪缂栬緫浜у搧鏃剁瓑寰呭姞杞藉畬鎴�
+  return productTreeList().then((res) => {
     productOptions.value = convertIdToValue(res);
+    return productOptions.value;
   });
 };
 const formattedNumber = (row, column, cellValue) => {
@@ -695,6 +769,19 @@
 
     return newItem;
   });
+}
+// 鏍规嵁鍚嶇О鍙嶆煡浜у搧澶х被 id锛屼究浜庝粎瀛樺悕绉版椂鐨勫弽鏄�
+function findNodeIdByLabel(nodes, label) {
+  if (!label) return null;
+  for (let i = 0; i < nodes.length; i++) {
+    const node = nodes[i];
+    if (node.label === label) return node.value;
+    if (node.children && node.children.length > 0) {
+      const found = findNodeIdByLabel(node.children, label);
+      if (found !== null && found !== undefined) return found;
+    }
+  }
+  return null;
 }
 // 琛ㄦ牸閫夋嫨鏁版嵁
 const handleSelectionChange = (selection) => {
@@ -746,6 +833,7 @@
   operationType.value = type;
   form.value = {};
   productData.value = [];
+  selectedQuotation.value = null;
   let userLists = await userListNoPage();
   userList.value = userLists.data;
   customerList().then((res) => {
@@ -774,6 +862,87 @@
   // });
   form.value.entryDate = getCurrentDate(); // 璁剧疆榛樿褰曞叆鏃ユ湡涓哄綋鍓嶆棩鏈�
   dialogFormVisible.value = true;
+};
+
+// 鎵撳紑鎶ヤ环鍗曢�夋嫨寮圭獥锛堜粎瀹℃壒閫氳繃锛�
+const openQuotationDialog = async () => {
+  if (operationType.value === "view") return;
+  quotationDialogVisible.value = true;
+  // 鍏堢‘淇濆鎴峰垪琛ㄥ凡鍔犺浇锛屼究浜庡悗缁洖濉� customerId
+  if (!customerOption.value || customerOption.value.length === 0) {
+    try {
+      const res = await customerList();
+      customerOption.value = res;
+    } catch (e) {
+      // ignore锛屽厑璁哥敤鎴峰悗缁墜鍔ㄩ�夋嫨瀹㈡埛
+    }
+  }
+  await fetchQuotationList();
+};
+
+const fetchQuotationList = async () => {
+  quotationLoading.value = true;
+  try {
+    const params = {
+      // 鍏煎鍚庣鍒嗛〉瀛楁锛氳繖閲屾部鐢ㄦ姤浠烽〉闈㈠凡鏈夊彲鐢ㄧ殑瀛楁鍛藉悕
+      currentPage: 1,
+      pageSize: 100,
+      ...quotationSearchForm,
+      status: "閫氳繃",
+    };
+    const res = await getQuotationList(params);
+    quotationList.value = res?.data?.records || [];
+  } finally {
+    quotationLoading.value = false;
+  }
+};
+
+const resetQuotationSearch = async () => {
+  quotationSearchForm.quotationNo = "";
+  quotationSearchForm.customer = "";
+  await fetchQuotationList();
+};
+
+// 閫変腑鎶ヤ环鍗曞悗鍥炲~鍒板彴璐﹁〃鍗�
+const applyQuotation = (row) => {
+  if (!row) return;
+  selectedQuotation.value = row;
+
+  // 涓氬姟鍛�
+  form.value.salesman = row.salesperson || "";
+
+  // 瀹㈡埛鍚嶇О -> customerId
+  const customer = (customerOption.value || []).find((c) => c.customerName === row.customer);
+  if (customer?.id) {
+    form.value.customerId = customer.id;
+  } else {
+    // 濡傛灉鎵句笉鍒帮紝淇濈暀鍘熷�硷紙鍏佽鐢ㄦ埛鎵嬪姩閫夋嫨/涓嶆墦鏂凡鏈夎緭鍏ワ級
+    form.value.customerId = form.value.customerId || "";
+  }
+
+  // 浜у搧淇℃伅鏄犲皠锛氭姤浠� products -> 鍙拌处 productData
+  const products = Array.isArray(row.products) ? row.products : [];
+  productData.value = products.map((p) => {
+    const quantity = Number(p.quantity ?? 0) || 0;
+    const unitPrice = Number(p.unitPrice ?? 0) || 0;
+    const taxRate = "13"; // 榛樿 13%锛屼究浜庣洿鎺ユ彁浜わ紙濡傞渶鍙湪浜у搧涓嚜琛屼慨鏀癸級
+    const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
+    const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(taxInclusiveTotalPrice, taxRate);
+    return {
+      // 鍙拌处瀛楁
+      productCategory: p.product || p.productName || "",
+      specificationModel: p.specification || "",
+      unit: p.unit || "",
+      quantity: quantity,
+      taxRate: taxRate,
+      taxInclusiveUnitPrice: unitPrice.toFixed(2),
+      taxInclusiveTotalPrice: taxInclusiveTotalPrice,
+      taxExclusiveTotalPrice: taxExclusiveTotalPrice,
+      invoiceType: "澧炴櫘绁�",
+    };
+  });
+
+  quotationDialogVisible.value = false;
 };
 function changs(val) {
   console.log(val);
@@ -847,16 +1016,36 @@
 
 const productIndex = ref(0);
 // 鎵撳紑浜у搧寮规
-const openProductForm = (type, row,index) => {
+const openProductForm = async (type, row, index) => {
   productOperationType.value = type;
   productForm.value = {};
   proxy.resetForm("productFormRef");
   if (type === "edit") {
     productForm.value = { ...row };
     productIndex.value = index;
+    // 缂栬緫鏃舵牴鎹骇鍝佸ぇ绫诲悕绉板弽鏌� tree 鑺傜偣 id锛屽苟鍔犺浇瑙勬牸鍨嬪彿鍒楄〃
+    try {
+      const options = productOptions.value && productOptions.value.length > 0
+        ? productOptions.value
+        : await getProductOptions();
+      const categoryId = findNodeIdByLabel(options, productForm.value.productCategory);
+      if (categoryId) {
+        const models = await modelList({ id: categoryId });
+        modelOptions.value = models || [];
+        // 鏍规嵁褰撳墠瑙勬牸鍨嬪彿鍚嶇О鍙嶆煡骞惰缃� productModelId锛屼究浜庝笅鎷夋鏄剧ず宸查�夊��
+        const currentModel = (modelOptions.value || []).find(
+          (m) => m.model === productForm.value.specificationModel
+        );
+        if (currentModel) {
+          productForm.value.productModelId = currentModel.id;
+        }
+      }
+    } catch (e) {
+      // 鍔犺浇澶辫触鏃朵繚鎸佸彲缂栬緫锛屼笉涓柇寮圭獥
+      console.error("鍔犺浇浜у搧瑙勬牸鍨嬪彿澶辫触", e);
+    }
   }
   productFormVisible.value = true;
-  getProductOptions();
 };
 // 鎻愪氦浜у搧琛ㄥ崟
 const submitProduct = () => {

--
Gitblit v1.9.3