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 |  136 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 104 insertions(+), 32 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 5ceb912..e5ca3d6 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -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"
@@ -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 => {

--
Gitblit v1.9.3