From 47271b02898cd08645abaaeb5a82cffa3dcdd474 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期二, 21 四月 2026 10:15:31 +0800
Subject: [PATCH] 添加产品复制功能和优化行数据处理逻辑

---
 src/views/salesManagement/salesLedger/index.vue |  170 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 121 insertions(+), 49 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 6a71d8a..e5ca3d6 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -225,9 +225,9 @@
                   <el-tag v-else-if="scope.row.productStockStatus == 2"
                           type="success">宸插叆搴�</el-tag>
                   <el-tag v-else-if="scope.row.productStockStatus == 0"
-                          type="info">鏈嚭搴�</el-tag>
+                          type="info">鏈叆搴�</el-tag>
                   <el-tag v-else
-                          type="danger">涓嶈冻</el-tag>
+                          type="danger">鏈叆搴�</el-tag>
                 </template>
               </el-table-column>
               <!-- <el-table-column label="鍙戣揣鐘舵��" width="140" align="center">
@@ -666,12 +666,12 @@
                                v-model="scope.row.settlePieceArea"
                                :min="0"
                                :step="1"
-                               :precision="10"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable
                                @change="() => handleInlineSettleAreaChange(scope.row)" />
-              <span v-else>{{ scope.row.settlePieceArea ?? "" }}</span>
+              <span v-else>{{ scope.row.settlePieceArea ? Number(scope.row.settlePieceArea).toFixed(4) : "" }}</span>
             </template>
           </el-table-column>
           <el-table-column label="鏁伴噺"
@@ -701,10 +701,10 @@
                                v-model="scope.row.actualTotalArea"
                                :min="0"
                                :step="1"
-                               :precision="10"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="鑷姩璁$畻" />
-              <span v-else>{{ scope.row.actualTotalArea ?? "" }}</span>
+              <span v-else>{{ scope.row.actualTotalArea ? Number(scope.row.actualTotalArea).toFixed(4) : "" }}</span>
             </template>
           </el-table-column>
           <el-table-column label="鍚◣鍗曚环(鍏�)"
@@ -721,7 +721,7 @@
                                clearable
                                @change="() => handleInlineUnitPriceChange(scope.row)"
                                @input="() => handleInlineUnitPriceChange(scope.row)" />
-              <span v-else>{{ formattedNumber(null, null, scope.row.taxInclusiveUnitPrice ?? 0) }}</span>
+              <span v-else>{{ formattedNumber(null, null, scope.row.taxInclusiveUnitPrice) }}</span>
             </template>
           </el-table-column>
           <el-table-column label="绋庣巼(%)"
@@ -927,6 +927,13 @@
                            :disabled="isProductShipped(scope.row)"
                            @click="editProductInline(scope.row, scope.$index)">
                   缂栬緫
+                </el-button>
+                <el-button link
+                           type="primary"
+                           size="small"
+                           :disabled="isProductShipped(scope.row) || hasEditingProductRow()"
+                           @click="copyProductInline(scope.row, scope.$index)">
+                  澶嶅埗鏂板缓
                 </el-button>
                 <el-popover :width="560"
                             trigger="click"
@@ -1341,8 +1348,8 @@
                           prop="actualPieceArea">
               <el-input-number v-model="productForm.actualPieceArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="0.0001"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable
@@ -1354,8 +1361,8 @@
                           prop="actualTotalArea">
               <el-input-number v-model="productForm.actualTotalArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="0.0001"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable />
@@ -1366,8 +1373,8 @@
                           prop="settlePieceArea">
               <el-input-number v-model="productForm.settlePieceArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="0.0001"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable
@@ -1379,8 +1386,8 @@
                           prop="settleTotalArea">
               <el-input-number v-model="productForm.settleTotalArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="0.0001"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable />
@@ -1391,8 +1398,8 @@
                           prop="settleTotalArea">
               <el-input-number v-model="productForm.settleTotalArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="0.0001"
+                               :precision="4"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable />
@@ -2045,6 +2052,37 @@
     return (productData.value || []).some(r => r && r.__editing);
   };
 
+  const buildEmptyInlineProductRow = () => ({
+    id: null,
+    __tempKey: `__temp_${Date.now()}_${Math.random().toString(16).slice(2)}`,
+    __editing: true,
+    __isNew: true,
+    __productCategoryId: null,
+    productCategory: "",
+    productModelId: null,
+    specificationModel: "",
+    thickness: null,
+    quantity: null,
+    taxInclusiveUnitPrice: null,
+    taxRate: "",
+    taxInclusiveTotalPrice: null,
+    taxExclusiveTotalPrice: null,
+    invoiceType: "",
+    width: null,
+    height: null,
+    perimeter: null,
+    actualPieceArea: null,
+    actualTotalArea: null,
+    settlePieceArea: null,
+    settleTotalArea: null,
+    processRequirement: "",
+    remark: "",
+    salesProductProcessList: [],
+    processFlowConfigId: null,
+    floorCode: "",
+    heavyBox: "",
+  });
+
   const addProductInline = async () => {
     if (operationType.value === "view") return;
     if (hasEditingProductRow()) {
@@ -2053,40 +2091,70 @@
     }
     await getProductOptions();
     await fetchOtherAmountSelectOptions(true);
-    const row = {
-      id: null,
-      __tempKey: `__temp_${Date.now()}_${Math.random().toString(16).slice(2)}`,
-      __editing: true,
-      __isNew: true,
-      __productCategoryId: null,
-      productCategory: "",
-      productModelId: null,
-      specificationModel: "",
-      thickness: null,
-      quantity: 0,
-      taxInclusiveUnitPrice: 0,
-      taxRate: "",
-      taxInclusiveTotalPrice: 0,
-      taxExclusiveTotalPrice: 0,
-      invoiceType: "",
-      width: 0,
-      height: 0,
-      perimeter: 0,
-      actualPieceArea: 0,
-      actualTotalArea: 0,
-      settlePieceArea: 0,
-      settleTotalArea: 0,
-      processRequirement: "",
-      remark: "",
-      salesProductProcessList: [],
-      processFlowConfigId: null,
-      floorCode: "",
-      heavyBox: "",
-    };
+    const row = buildEmptyInlineProductRow();
     productData.value.push(row);
     editingProductRow.value = row;
     // 璁╃幇鏈夌殑璁$畻/鍏朵粬閲戦閫昏緫澶嶇敤褰撳墠琛�
     productForm.value = row;
+  };
+
+  const copyProductInline = async row => {
+    if (operationType.value === "view") return;
+    if (!row) return;
+    if (isProductShipped(row)) {
+      proxy.$modal.msgWarning("宸插彂璐ф垨瀹℃牳閫氳繃鐨勪骇鍝佷笉鑳藉鍒�");
+      return;
+    }
+    if (hasEditingProductRow()) {
+      proxy.$modal.msgWarning("璇峰厛淇濆瓨鎴栧彇娑堝綋鍓嶇紪杈戣");
+      return;
+    }
+    await getProductOptions();
+    await fetchOtherAmountSelectOptions(true);
+
+    const copied = buildEmptyInlineProductRow();
+    copied.__productCategoryId =
+      row.__productCategoryId ??
+      findNodeIdByLabel(productOptions.value, row.productCategory) ??
+      null;
+    copied.productCategory = row.productCategory ?? "";
+    copied.productModelId = row.productModelId ?? null;
+    copied.specificationModel = row.specificationModel ?? "";
+    copied.thickness =
+      row.thickness !== null && row.thickness !== undefined && row.thickness !== ""
+        ? Number(row.thickness)
+        : null;
+
+    // 澶嶅埗鏂板缓浠呭甫鍑轰骇鍝佸ぇ绫讳笌瑙勬牸鍨嬪彿锛屽叾浠栨暟瀛楀瓧娈靛叏閮ㄧ暀绌猴紝閬垮厤鍑虹幇 0.00
+    copied.quantity = null;
+    copied.taxInclusiveUnitPrice = null;
+    copied.taxInclusiveTotalPrice = null;
+    copied.taxExclusiveTotalPrice = null;
+    copied.width = null;
+    copied.height = null;
+    copied.perimeter = null;
+    copied.actualPieceArea = null;
+    copied.actualTotalArea = null;
+    copied.settlePieceArea = null;
+    copied.settleTotalArea = null;
+
+    // 澶嶅埗鏃舵寜鈥滀骇鍝佸ぇ绫� + 瑙勬牸鍨嬪彿鍚嶇О鈥濆弽鏌ュ瀷鍙� id锛岀‘淇濅笅鎷夎兘姝g‘鍥炴樉
+    try {
+      if (copied.__productCategoryId) {
+        const models = await modelList({ id: copied.__productCategoryId });
+        modelOptions.value = models || [];
+        const matchedModel = (modelOptions.value || []).find(
+          m => m.model === copied.specificationModel
+        );
+        copied.productModelId = matchedModel?.id ?? copied.productModelId ?? null;
+      }
+    } catch (e) {
+      console.error("澶嶅埗鏃跺姞杞戒骇鍝佽鏍煎瀷鍙峰け璐�", e);
+    }
+
+    productData.value.push(copied);
+    editingProductRow.value = copied;
+    productForm.value = copied;
   };
 
   const editProductInline = async (row, index) => {
@@ -2967,7 +3035,11 @@
     });
   };
   const formattedNumber = (row, column, cellValue) => {
-    return parseFloat(cellValue).toFixed(2);
+    if (cellValue === null || cellValue === undefined || cellValue === "") {
+      return "";
+    }
+    const num = Number(cellValue);
+    return Number.isFinite(num) ? num.toFixed(2) : "";
   };
   // 鑾峰彇tree瀛愭暟鎹�
   const getModels = value => {
@@ -3751,7 +3823,7 @@
       try {
         const res = await getSalesInvoices(selectedIds);
         const salesInvoiceData = res?.data ?? {};
-        printSalesDeliveryNote(salesInvoiceData, selectedRow);
+        await printSalesDeliveryNote(salesInvoiceData, selectedRow, selectedIds);
       } catch (error) {
         console.error("鎵撳嵃閿�鍞彂璐у崟澶辫触:", error);
         proxy.$modal.msgError("鎵撳嵃澶辫触锛岃绋嶅悗閲嶈瘯");

--
Gitblit v1.9.3