From 3a48d44d1eb5340c7caf2b010e1e9f081955d56c Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 22 四月 2026 11:52:09 +0800
Subject: [PATCH] 添加历史迁移功能,支持未发货和已发货的销售台账导入

---
 src/views/salesManagement/salesLedger/index.vue |  874 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 793 insertions(+), 81 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 72ce7e8..083d3db 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -32,6 +32,20 @@
                     prefix-icon="Search"
                     @change="handleQuery" />
         </el-form-item>
+        <el-form-item label="浜у搧瀹�(mm)锛�">
+          <el-input v-model="searchForm.width"
+                    placeholder="璇疯緭鍏�"
+                    clearable
+                    prefix-icon="Search"
+                    @change="handleQuery" />
+        </el-form-item>
+        <el-form-item label="浜у搧楂�(mm)锛�">
+          <el-input v-model="searchForm.height"
+                    placeholder="璇疯緭鍏�"
+                    clearable
+                    prefix-icon="Search"
+                    @change="handleQuery" />
+        </el-form-item>
         <el-form-item label="褰曞叆鏃ユ湡锛�">
           <el-date-picker v-model="searchForm.entryDate"
                           value-format="YYYY-MM-DD"
@@ -63,8 +77,10 @@
                      style="width: 140px">
             <el-option label="鏈叆搴�"
                        :value="0" />
-            <el-option label="宸插叆搴�"
+            <el-option label="閮ㄥ垎鍏ュ簱"
                        :value="1" />
+            <el-option label="宸插叆搴�"
+                       :value="2" />
           </el-select>
         </el-form-item>
         <el-form-item>
@@ -93,6 +109,20 @@
           <el-button type="primary"
                      plain
                      @click="handleImport">瀵煎叆</el-button>
+          <el-dropdown @command="handleHistoryImportCommand">
+            <el-button type="primary"
+                       plain>
+              鍘嗗彶杩佺Щ<el-icon class="el-icon--right">
+                <ArrowDown />
+              </el-icon>
+            </el-button>
+            <template #dropdown>
+              <el-dropdown-menu>
+                <el-dropdown-item command="notShipped">鏈彂璐�</el-dropdown-item>
+                <el-dropdown-item command="shipped">宸插彂璐�</el-dropdown-item>
+              </el-dropdown-menu>
+            </template>
+          </el-dropdown>
           <el-button @click="handleOut">瀵煎嚭</el-button>
           <el-button type="danger"
                      plain
@@ -214,6 +244,20 @@
                           type="danger">涓嶈冻</el-tag>
                 </template>
               </el-table-column>
+              <el-table-column label="鍏ュ簱鐘舵��"
+                               width="100px"
+                               align="center">
+                <template #default="scope">
+                  <el-tag v-if="scope.row.productStockStatus == 1"
+                  type="warning">閮ㄥ垎鍏ュ簱</el-tag>
+                  <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>
+                  <el-tag v-else
+                          type="danger">鏈叆搴�</el-tag>
+                </template>
+              </el-table-column>
               <!-- <el-table-column label="鍙戣揣鐘舵��" width="140" align="center">
 								<template #default="scope">
 									<el-tag :type="getShippingStatusType(scope.row)" size="small">
@@ -303,6 +347,14 @@
                          width="220"
                          show-overflow-tooltip
                          :formatter="formattedNumber" />
+        <el-table-column label="闈㈢Н"
+                         prop="productTotalArea"
+                         width="120"
+                         show-overflow-tooltip />
+        <el-table-column label="鏁伴噺"
+                         prop="productTotalQuantity"
+                         width="120"
+                         show-overflow-tooltip />
         <el-table-column label="鍙戣揣鐘舵��"
                          width="140"
                          align="center">
@@ -328,6 +380,8 @@
             <el-tag v-if="Number(scope.row.stockStatus) === 0"
                     type="info">鏈叆搴�</el-tag>
             <el-tag v-else-if="Number(scope.row.stockStatus) === 1"
+                    type="success">閮ㄥ垎鍏ュ簱</el-tag>
+            <el-tag v-else-if="Number(scope.row.stockStatus) === 2"
                     type="success">宸插叆搴�</el-tag>
             <el-tag v-else
                     type="info">-</el-tag>
@@ -353,9 +407,13 @@
                          prop="remarks"
                          width="200"
                          show-overflow-tooltip />
+        <el-table-column label="瀹㈡埛澶囨敞"
+                         prop="customerRemarks"
+                         width="200"
+                         show-overflow-tooltip />
         <el-table-column fixed="right"
                          label="鎿嶄綔"
-                         width="200"
+                         width="280"
                          align="center">
           <template #default="scope">
             <el-button link
@@ -369,6 +427,9 @@
             <el-button link
                        type="primary"
                        @click="downLoadFile(scope.row)">闄勪欢</el-button>
+            <el-button link
+                       type="primary"
+                       @click="openLedgerQrDialog(scope.row)">浜岀淮鐮�</el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -390,6 +451,7 @@
                label-width="140px"
                label-position="top"
                :rules="rules"
+               @keydown.capture="handleTabScrollFollow"
                ref="formRef">
         <!-- 鎶ヤ环鍗曞鍏ュ叆鍙o細鏀惧湪琛ㄥ崟椤堕儴锛岄�夋嫨鍚庡弽鏄惧鎴�/涓氬姟鍛樼瓑 -->
         <el-row v-if="operationType === 'add'"
@@ -441,9 +503,7 @@
                            :key="item.id"
                            :label="item.customerName"
                            :value="item.id">
-                  {{
-                    item.customerName + "鈥斺��" + item.taxpayerIdentificationNumber
-                  }}
+                  {{ item.customerName + (item.taxpayerIdentificationNumber ? "鈥斺��" + item.taxpayerIdentificationNumber : "") }}
                 </el-option>
               </el-select>
             </el-form-item>
@@ -565,7 +625,7 @@
           </el-table-column>
           <el-table-column label="瑙勬牸鍨嬪彿"
                            prop="specificationModel"
-                           min-width="160">
+                           min-width="200">
             <template #default="scope">
               <el-select v-if="scope.row.__editing"
                          v-model="scope.row.productModelId"
@@ -587,10 +647,11 @@
                            min-width="160">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
+                               controls-position="right"
                                v-model="scope.row.thickness"
                                :min="0"
-                               :step="0.000000000000001"
-                               :precision="15"
+                               :step="1"
+                               :precision="2"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable />
@@ -602,6 +663,7 @@
                            min-width="160">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
+                               controls-position="right"
                                v-model="scope.row.width"
                                :min="0"
                                :step="1"
@@ -619,6 +681,7 @@
                            min-width="160">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
+                               controls-position="right"
                                v-model="scope.row.height"
                                :min="0"
                                :step="1"
@@ -633,18 +696,19 @@
           </el-table-column>
           <el-table-column label="缁撶畻鍗曠墖闈㈢Н(銕�)"
                            prop="settlePieceArea"
-                           min-width="160">
+                           min-width="200">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
+                               controls-position="right"
                                v-model="scope.row.settlePieceArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="1"
+                               :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="鏁伴噺"
@@ -652,10 +716,11 @@
                            min-width="150">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
+                               controls-position="right"
                                v-model="scope.row.quantity"
-                               :step="0.1"
+                               :step="1"
                                :min="0"
-                               :precision="2"
+                               :precision="0"
                                style="width: 100%"
                                placeholder="璇疯緭鍏�"
                                clearable
@@ -666,21 +731,22 @@
           </el-table-column>
           <el-table-column label="闈㈢Н(m虏)"
                            prop="actualTotalArea"
-                           min-width="160">
+                           min-width="200">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
+                               controls-position="right"
                                v-model="scope.row.actualTotalArea"
                                :min="0"
-                               :step="0.00001"
-                               :precision="5"
+                               :step="1"
+                               :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="鍚◣鍗曚环(鍏�)"
                            prop="taxInclusiveUnitPrice"
-                           min-width="140">
+                           min-width="160">
             <template #default="scope">
               <el-input-number v-if="scope.row.__editing"
                                :step="0.01"
@@ -692,7 +758,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="绋庣巼(%)"
@@ -772,7 +838,7 @@
           </el-table-column>
           <el-table-column label="妤煎眰缂栧彿"
                            prop="floorCode"
-                           min-width="140"
+                           min-width="250"
                            show-overflow-tooltip>
             <template #default="scope">
               <el-input v-if="scope.row.__editing"
@@ -898,6 +964,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"
@@ -1312,8 +1385,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
@@ -1325,8 +1398,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 />
@@ -1337,8 +1410,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
@@ -1350,8 +1423,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 />
@@ -1362,8 +1435,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 />
@@ -1505,9 +1578,10 @@
     <FormDialog v-model="importUpload.open"
                 :title="importUpload.title"
                 :width="'600px'"
-                @close="importUpload.open = false"
+                :loading="importUpload.isUploading"
+                @close="onClose"
                 @confirm="submitImportFile"
-                @cancel="importUpload.open = false">
+                @cancel="onClose">
       <el-upload ref="importUploadRef"
                  :limit="1"
                  accept=".xlsx,.xls"
@@ -1518,6 +1592,7 @@
                  :on-error="importUpload.onError"
                  :on-progress="importUpload.onProgress"
                  :on-change="importUpload.onChange"
+                 :on-exceed="importUpload.onExceed"
                  :auto-upload="false"
                  drag>
         <i class="el-icon-upload"></i>
@@ -1609,6 +1684,109 @@
         </div>
       </template>
     </el-dialog>
+    <!-- 鍏ュ簱浜у搧閫夋嫨寮圭獥 -->
+    <el-dialog v-model="stockDialogVisible"
+               title="閫夋嫨鍏ュ簱浜у搧"
+               width="60%"
+               :close-on-click-modal="false">
+      <div style="margin-bottom: 12px;">
+        <el-form>
+          <el-form-item required>
+            <template #label>
+              <div style="display: flex; align-items: center; justify-content: space-between; width: 100%;">
+                <span>瀹℃壒浜洪�夋嫨锛�</span>
+                <el-button type="primary"
+                           size="small"
+                           @click="addStockApproverNode"
+                           icon="Plus">鏂板鑺傜偣</el-button>
+              </div>
+            </template>
+            <div class="approver-nodes-container">
+              <div v-for="(node, index) in stockApproverNodes"
+                   :key="node.id"
+                   class="approver-node-item">
+                <div class="approver-node-header">
+                  <span class="approver-node-label">瀹℃壒鑺傜偣 {{ index + 1 }}</span>
+                  <el-button v-if="stockApproverNodes.length > 1"
+                             type="danger"
+                             size="small"
+                             text
+                             @click="removeStockApproverNode(index)"
+                             icon="Delete">鍒犻櫎</el-button>
+                </div>
+                <el-select v-model="node.userId"
+                           placeholder="璇烽�夋嫨瀹℃壒浜�"
+                           filterable
+                           clearable
+                           style="width: 100%;">
+                  <el-option v-for="item in stockApproverOptions"
+                             :key="item.userId"
+                             :label="item.userName"
+                             :value="item.userId" />
+                </el-select>
+              </div>
+            </div>
+          </el-form-item>
+        </el-form>
+      </div>
+      <el-table :data="stockProductList"
+                border
+                stripe
+                v-loading="stockLoading"
+                height="400px"
+                @selection-change="val => selectedStockProductIds = val.map(item => item.id)">
+        <el-table-column type="selection"
+                         width="55"
+                         align="center" />
+        <el-table-column align="center"
+                         label="搴忓彿"
+                         type="index"
+                         width="60" />
+        <el-table-column prop="productCategory"
+                         label="浜у搧澶х被"
+                         show-overflow-tooltip />
+        <el-table-column prop="specificationModel"
+                         label="瑙勬牸鍨嬪彿"
+                         show-overflow-tooltip />
+        <el-table-column prop="quantity"
+                         label="鏁伴噺"
+                         width="100" />
+        <el-table-column prop="stockedQuantity"
+                         label="宸插叆搴撴暟閲�"
+                         width="120"
+                         align="center"
+                         show-overflow-tooltip />
+        <el-table-column prop="floorCode"
+                         label="妤煎眰缂栧彿"
+                         show-overflow-tooltip />
+      </el-table>
+      <template #footer>
+        <el-button @click="stockDialogVisible = false">鍙栨秷</el-button>
+        <el-button type="primary"
+                   @click="submitStock"
+                   :disabled="selectedStockProductIds.length === 0">
+          纭鍏ュ簱
+        </el-button>
+      </template>
+    </el-dialog>
+    <el-dialog v-model="ledgerQrDialogVisible"
+               title="閿�鍞鍗曚簩缁寸爜"
+               width="360px"
+               draggable
+               :close-on-click-modal="false">
+      <div class="ledger-qr-dialog">
+        <img v-if="ledgerQrCompositeUrl"
+             :src="ledgerQrCompositeUrl"
+             alt="閿�鍞鍗曚簩缁寸爜"
+             class="ledger-qr-composite-img" />
+        <el-button type="primary"
+                   class="ledger-qr-save-btn"
+                   :disabled="!ledgerQrCompositeUrl"
+                   @click="downloadLedgerQrCode">
+          淇濆瓨鍥剧墖
+        </el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
@@ -1656,6 +1834,7 @@
   import { printSalesOrder } from "./components/salesOrderPrint.js";
   import { printSalesDeliveryNote } from "./components/salesDeliveryPrint.js";
   import { printSalesLabel } from "./components/salesLabelPrint.js";
+  import QRCode from "qrcode";
   // import { salesLedgerProductSetProcessFlowConfig } from "@/api/salesManagement/salesProcessFlowConfig.js";
 
   const userStore = useUserStore();
@@ -1684,6 +1863,129 @@
   const processFlowSelectBoundRouteId = ref(null);
   const processFlowSelectBoundRouteName = ref("");
 
+  // 鍏ュ簱寮圭獥鐩稿叧
+  const stockDialogVisible = ref(false);
+  const stockProductList = ref([]);
+  const selectedStockProductIds = ref([]);
+  const stockLoading = ref(false);
+  const currentStockLedgerId = ref(null);
+  const stockApproverOptions = ref([]);
+  const stockApproverNodes = ref([{ id: 1, userId: null }]);
+  let nextStockApproverId = 2;
+  const addStockApproverNode = () => {
+    stockApproverNodes.value.push({ id: nextStockApproverId++, userId: null });
+  };
+  const removeStockApproverNode = index => {
+    stockApproverNodes.value.splice(index, 1);
+  };
+
+  const ledgerQrDialogVisible = ref(false);
+  const ledgerQrCompositeUrl = ref("");
+  const ledgerQrDownloadBaseName = ref("");
+
+  const sanitizeLedgerQrFilename = s =>
+    String(s)
+      .replace(/[\\/:*?"<>|]/g, "_")
+      .trim()
+      .slice(0, 80) || "ledger";
+
+  const wrapLedgerQrTextLines = (ctx, text, maxWidth) => {
+    const chars = [...text];
+    const lines = [];
+    let line = "";
+    for (const ch of chars) {
+      const test = line + ch;
+      if (ctx.measureText(test).width > maxWidth && line.length) {
+        lines.push(line);
+        line = ch;
+      } else {
+        line = test;
+      }
+    }
+    if (line) lines.push(line);
+    return lines;
+  };
+
+  const buildLedgerQrCompositeDataUrl = row =>
+    new Promise((resolve, reject) => {
+      const payload = JSON.stringify({
+        id: row.id,
+        salesContractNo: (row.salesContractNo ?? "").trim(),
+        type: "XS",
+      });
+      QRCode.toDataURL(payload, { width: 220, margin: 2 })
+        .then(qrDataUrl => {
+          const contract = (row.salesContractNo ?? "").trim() || "鈥�";
+          const img = new Image();
+          img.onload = () => {
+            const QR_SIZE = 220;
+            const padTop = 16;
+            const gapAfterQr = 14;
+            const bottomPad = 48;
+            const horizontalPad = 20;
+            const lineHeight = 20;
+            const fontSize = 14;
+            const label = `閿�鍞悎鍚屽彿锛�${contract}`;
+
+            const canvas = document.createElement("canvas");
+            const ctx = canvas.getContext("2d");
+            canvas.width = Math.max(QR_SIZE + horizontalPad * 2, 280);
+            ctx.font = `${fontSize}px "Microsoft YaHei", "PingFang SC", sans-serif`;
+            const lines = wrapLedgerQrTextLines(ctx, label, canvas.width - horizontalPad * 2);
+            const textBlockHeight = lines.length * lineHeight;
+            canvas.height = padTop + QR_SIZE + gapAfterQr + textBlockHeight + bottomPad;
+
+            ctx.fillStyle = "#ffffff";
+            ctx.fillRect(0, 0, canvas.width, canvas.height);
+
+            const qrX = (canvas.width - QR_SIZE) / 2;
+            ctx.drawImage(img, qrX, padTop, QR_SIZE, QR_SIZE);
+
+            ctx.fillStyle = "#606266";
+            ctx.font = `${fontSize}px "Microsoft YaHei", "PingFang SC", sans-serif`;
+            ctx.textAlign = "center";
+            ctx.textBaseline = "top";
+            const textY0 = padTop + QR_SIZE + gapAfterQr;
+            lines.forEach((ln, i) => {
+              ctx.fillText(ln, canvas.width / 2, textY0 + i * lineHeight);
+            });
+
+            const baseName = sanitizeLedgerQrFilename(
+              contract !== "鈥�" ? contract : String(row.id)
+            );
+            resolve({ dataUrl: canvas.toDataURL("image/png"), baseName });
+          };
+          img.onerror = () => reject(new Error("浜岀淮鐮佸浘鐗囧姞杞藉け璐�"));
+          img.src = qrDataUrl;
+        })
+        .catch(reject);
+    });
+
+  const openLedgerQrDialog = async row => {
+    if (row?.id === undefined || row?.id === null || row?.id === "") {
+      ElMessage.warning("鏃犳硶鐢熸垚浜岀淮鐮侊細缂哄皯鍙拌处 ID");
+      return;
+    }
+    ledgerQrCompositeUrl.value = "";
+    ledgerQrDownloadBaseName.value = "";
+    try {
+      const { dataUrl, baseName } = await buildLedgerQrCompositeDataUrl(row);
+      ledgerQrCompositeUrl.value = dataUrl;
+      ledgerQrDownloadBaseName.value = baseName;
+      ledgerQrDialogVisible.value = true;
+    } catch {
+      ElMessage.error("浜岀淮鐮佺敓鎴愬け璐�");
+    }
+  };
+
+  const downloadLedgerQrCode = () => {
+    if (!ledgerQrCompositeUrl.value) return;
+    const a = document.createElement("a");
+    a.href = ledgerQrCompositeUrl.value;
+    a.download = `閿�鍞彴璐︿簩缁寸爜-${ledgerQrDownloadBaseName.value}.png`;
+    a.click();
+  };
+
   // 鐢ㄦ埛淇℃伅琛ㄥ崟寮规鏁版嵁
   const operationType = ref("");
   const dialogFormVisible = ref(false);
@@ -1692,11 +1994,13 @@
       customerName: "", // 瀹㈡埛鍚嶇О
       customerId: "", // 瀹㈡埛ID锛堟煡璇笅鎷夛級
       salesContractNo: "", // 閿�鍞悎鍚岀紪鍙�
+      width: undefined, // 浜у搧瀹�(mm)
+      height: undefined, // 浜у搧楂�(mm)
       entryDate: null, // 褰曞叆鏃ユ湡
       entryDateStart: undefined,
       entryDateEnd: undefined,
       deliveryStatus: undefined, // 鍙戣揣鐘舵�侊細1鏈彂璐� 2瀹℃壒涓� 3瀹℃壒澶辫触 4宸插彂璐�
-      stockStatus: undefined, // 鍏ュ簱鐘舵�侊細0鏈叆搴� 1宸插叆搴�
+      stockStatus: undefined, // 鍏ュ簱鐘舵�侊細0鏈叆搴� 1閮ㄥ垎鍏ュ簱 2宸插叆搴�
     },
     form: {
       salesContractNo: "",
@@ -1836,6 +2140,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()) {
@@ -1844,40 +2179,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) => {
@@ -2509,6 +2874,13 @@
     onChange: (file, fileList) => {
       console.log("鏂囦欢鐘舵�佹敼鍙�", file, fileList);
     },
+    onExceed: (files, fileList) => {
+      if (importUploadRef.value) {
+        importUploadRef.value.clearFiles();
+        const file = files[0];
+        importUploadRef.value.handleStart(file);
+      }
+    },
     onProgress: (event, file, fileList) => {
       console.log("涓婁紶涓�...", event.percent);
     },
@@ -2532,6 +2904,10 @@
       proxy.$modal.msgError("瀵煎叆澶辫触锛岃閲嶈瘯");
     },
   });
+  const HISTORY_IMPORT_URL_MAP = {
+    notShipped: "/sales/ledger/salesHistory/notShippingImport",
+    shipped: "/sales/ledger/salesHistory/shippingImport",
+  };
 
   const changeDaterange = value => {
     if (value) {
@@ -2582,14 +2958,44 @@
         delete params.customerName;
       }
     }
+    const widthValue =
+      params.width != null ? String(params.width).trim() : "";
+    if (widthValue) {
+      params.width = widthValue;
+    } else {
+      delete params.width;
+    }
+    const heightValue =
+      params.height != null ? String(params.height).trim() : "";
+    if (heightValue) {
+      params.height = heightValue;
+    } else {
+      delete params.height;
+    }
+    const shouldAutoExpandBySize = Boolean(params.width || params.height);
     delete params.customerId;
     return ledgerListPage(params)
-      .then(res => {
+      .then(async res => {
         tableLoading.value = false;
         tableData.value = res.records;
         tableData.value.map(item => {
           item.children = [];
         });
+        if (shouldAutoExpandBySize && tableData.value.length > 0) {
+          const loadChildrenTasks = tableData.value.map(item =>
+            productList({ salesLedgerId: item.id, type: 1 })
+              .then(productRes => {
+                item.children = Array.isArray(productRes?.data)
+                  ? productRes.data
+                  : [];
+              })
+              .catch(() => {
+                item.children = [];
+              })
+          );
+          await Promise.all(loadChildrenTasks);
+          expandedRowKeys.value = tableData.value.map(item => item.id);
+        }
         total.value = res.total;
         return res;
       })
@@ -2610,12 +3016,51 @@
       ElMessage.warning("鎵�閫夋暟鎹己灏慽d锛屾棤娉曞叆搴�");
       return;
     }
-    if (Number(row.stockStatus) === 1) {
-      ElMessage.info("璇ュ彴璐﹀凡鍏ュ簱锛屾棤闇�閲嶅鎿嶄綔");
+    if (Number(row.stockStatus) === 2) {
+      ElMessage.info("璇ュ彴璐﹀凡鍏ㄩ儴鍏ュ簱锛屾棤闇�閲嶅鎿嶄綔");
       return;
     }
+
+    currentStockLedgerId.value = id;
+    selectedStockProductIds.value = [];
+    stockProductList.value = [];
+    stockApproverNodes.value = [{ id: 1, userId: null }];
+    nextStockApproverId = 2;
+    stockDialogVisible.value = true;
+    stockLoading.value = true;
+
     try {
-      await ElMessageBox.confirm("纭瀵规墍閫夊彴璐︽墽琛屽叆搴擄紵", "鎻愮ず", {
+      const approverRes = await approveUserList({ approveType: 9 });
+      stockApproverOptions.value = Array.isArray(approverRes?.data)
+        ? approverRes.data.map(item => ({
+            userId: item.userId,
+            userName: item.userName,
+          }))
+        : [];
+      const res = await productList({ salesLedgerId: id, type: 1 });
+      stockProductList.value = [];
+      stockProductList.value =
+        res.data.filter(item => item.productStockStatus == 0 || item.productStockStatus == 1) || [];
+    } catch (e) {
+      proxy?.$modal?.msgError?.("鑾峰彇浜у搧鎴栧鎵逛汉澶辫触");
+    } finally {
+      stockLoading.value = false;
+    }
+  };
+
+  const submitStock = async () => {
+    const hasEmptyApprover = stockApproverNodes.value.some(node => !node.userId);
+    if (hasEmptyApprover) {
+      ElMessage.warning("璇蜂负鎵�鏈夊鎵硅妭鐐归�夋嫨瀹℃壒浜�");
+      return;
+    }
+    if (selectedStockProductIds.value.length === 0) {
+      ElMessage.warning("璇烽�夋嫨鑷冲皯涓�涓骇鍝佽繘琛屽叆搴�");
+      return;
+    }
+
+    try {
+      await ElMessageBox.confirm("纭瀵规墍閫変骇鍝佹墽琛屽叆搴擄紵", "鎻愮ず", {
         confirmButtonText: "纭畾",
         cancelButtonText: "鍙栨秷",
         type: "warning",
@@ -2623,10 +3068,22 @@
     } catch {
       return;
     }
+
     proxy?.$modal?.loading?.("姝e湪鍏ュ簱锛岃绋嶅��...");
     try {
-      await salesStock({ id });
+      const approveUserIds = stockApproverNodes.value.map(node => node.userId).join(",");
+      const approveUserName = stockApproverNodes.value
+        .map(node => stockApproverOptions.value.find(item => String(item.userId) === String(node.userId))?.userName)
+        .filter(Boolean)
+        .join(",");
+      await salesStock({
+        salesLedgerId: currentStockLedgerId.value,
+        salesLedgerProducts: selectedStockProductIds.value,
+        approveUserIds,
+        approveUserName,
+      });
       proxy?.$modal?.msgSuccess?.("鍏ュ簱鎴愬姛");
+      stockDialogVisible.value = false;
       await getList();
     } catch (e) {
       proxy?.$modal?.msgError?.("鍏ュ簱澶辫触锛岃绋嶅悗閲嶈瘯");
@@ -2721,7 +3178,63 @@
     });
   };
   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) : "";
+  };
+
+  const scrollElementIntoVisibleArea = target => {
+    if (!target || !(target instanceof HTMLElement)) return;
+    let parent = target.parentElement;
+    while (parent && parent !== document.body) {
+      const style = window.getComputedStyle(parent);
+      const canScrollX =
+        (style.overflowX === "auto" ||
+          style.overflowX === "scroll" ||
+          style.overflowX === "overlay") &&
+        parent.scrollWidth > parent.clientWidth;
+      const canScrollY =
+        (style.overflowY === "auto" ||
+          style.overflowY === "scroll" ||
+          style.overflowY === "overlay") &&
+        parent.scrollHeight > parent.clientHeight;
+
+      if (canScrollX || canScrollY) {
+        const parentRect = parent.getBoundingClientRect();
+        const targetRect = target.getBoundingClientRect();
+        if (canScrollX) {
+          const targetCenterX = targetRect.left + targetRect.width / 2;
+          const parentCenterX = parentRect.left + parentRect.width / 2;
+          const deltaX = targetCenterX - parentCenterX;
+          if (Math.abs(deltaX) > 2) {
+            parent.scrollLeft += deltaX;
+          }
+        }
+
+        if (canScrollY) {
+          const targetCenterY = targetRect.top + targetRect.height / 2;
+          const parentCenterY = parentRect.top + parentRect.height / 2;
+          const deltaY = targetCenterY - parentCenterY;
+          if (Math.abs(deltaY) > 2) {
+            parent.scrollTop += deltaY;
+          }
+        }
+      }
+
+      parent = parent.parentElement;
+    }
+  };
+
+  const handleTabScrollFollow = e => {
+    if (!e || e.key !== "Tab") return;
+    requestAnimationFrame(() => {
+      const active = document.activeElement;
+      if (active instanceof HTMLElement) {
+        scrollElementIntoVisibleArea(active);
+      }
+    });
   };
   // 鑾峰彇tree瀛愭暟鎹�
   const getModels = value => {
@@ -2862,6 +3375,8 @@
   const summarizeMainTable = param => {
     return proxy.summarizeTable(param, [
       "contractAmount",
+      "productTotalQuantity",
+      "productTotalArea",
       "taxInclusiveTotalPrice",
       "taxExclusiveTotalPrice",
     ]);
@@ -3349,18 +3864,36 @@
     otherAmountAddDialogVisible.value = false;
     otherAmountAddId.value = null;
   };
-  // 瀵煎叆
-  const handleImport = () => {
-    importUpload.title = "瀵煎叆閿�鍞彴璐�";
+  const openImportDialog = (title, url) => {
+    importUpload.title = title;
+    importUpload.url = import.meta.env.VITE_APP_BASE_API + url;
     importUpload.open = true;
+    importUpload.isUploading = false;
     if (importUploadRef.value) {
       importUploadRef.value.clearFiles();
     }
+  };
+  // 瀵煎叆
+  const handleImport = () => {
+    openImportDialog("瀵煎叆閿�鍞彴璐�", "/sales/ledger/import");
+  };
+  // 鍘嗗彶杩佺Щ
+  const handleHistoryImportCommand = command => {
+    const url = HISTORY_IMPORT_URL_MAP[command];
+    if (!url) return;
+    const title = command === "shipped" ? "鍘嗗彶杩佺Щ-宸插彂璐�" : "鍘嗗彶杩佺Щ-鏈彂璐�";
+    openImportDialog(title, url);
   };
 
   // 涓嬭浇瀵煎叆妯℃澘
   const downloadTemplate = () => {
     proxy.download("/sales/ledger/exportTemplate", {}, "閿�鍞彴璐﹀鍏ユā鏉�.xlsx");
+  };
+  const onClose = () => {
+    importUpload.open = false;
+    if (importUploadRef.value) {
+      importUploadRef.value.clearFiles();
+    }
   };
 
   // 鎻愪氦瀵煎叆鏂囦欢
@@ -3499,7 +4032,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("鎵撳嵃澶辫触锛岃绋嶅悗閲嶈瘯");
@@ -3528,7 +4061,35 @@
       } else {
         const res = await getProcessCard(selectedId);
         const processCardData = res?.data ?? {};
-        printFinishedProcessCard(processCardData);
+        // 琛ラ綈浜岀淮鐮佹墍闇�鐨勫彴璐︽爣璇嗭紙鍚庣鏁版嵁鏈夋椂涓嶅甫 id锛�
+        if (processCardData && typeof processCardData === "object") {
+          processCardData.salesLedgerId = processCardData.salesLedgerId ?? selectedId;
+          processCardData.salesContractNo =
+            (processCardData.salesContractNo ?? "").trim() ||
+            String(selectedRow?.salesContractNo ?? "").trim();
+        }
+        const routeNodes = processCardData?.routeNodes;
+        const isProcessRouteEmpty =
+          !Array.isArray(routeNodes) || routeNodes.length === 0;
+        if (isProcessRouteEmpty) {
+          proxy.$modal.closeLoading();
+          try {
+            await ElMessageBox.confirm(
+              "褰撳墠璁㈠崟鏈粦瀹氬伐鑹鸿矾绾夸篃娌℃湁璁剧疆榛樿鐨勫伐鑹鸿矾绾匡紝鏄惁浠嶈鎵撳嵃锛�",
+              "鎻愮ず",
+              {
+                confirmButtonText: "鎵撳嵃",
+                cancelButtonText: "鍙栨秷",
+                type: "warning",
+              }
+            );
+          } catch {
+            return;
+          }
+          await printFinishedProcessCard(processCardData);
+        } else {
+          await printFinishedProcessCard(processCardData);
+        }
       }
     } catch (error) {
       console.error(
@@ -3944,6 +4505,40 @@
     return statusStr === "寰呭彂璐�" || statusStr === "瀹℃牳鎷掔粷";
   };
 
+  const getLedgerDisplayName = ledger =>
+    String(ledger?.salesContractNo || "").trim() ||
+    String(ledger?.projectName || "").trim() ||
+    `ID:${ledger?.id ?? "-"}`;
+
+  const validateLedgersStockedBeforeDelivery = async ledgers => {
+    const invalidLedgers = [];
+    for (const ledger of ledgers || []) {
+      const ledgerId = ledger?.id;
+      const ledgerName = getLedgerDisplayName(ledger);
+      if (!ledgerId) {
+        invalidLedgers.push(`${ledgerName}(缂哄皯鍙拌处ID)`);
+        continue;
+      }
+      let products = [];
+      try {
+        const res = await productList({ salesLedgerId: ledgerId, type: 1 });
+        products = Array.isArray(res?.data) ? res.data : [];
+      } catch (e) {
+        invalidLedgers.push(`${ledgerName}(鏄庣粏鍔犺浇澶辫触)`);
+        continue;
+      }
+      const unstockedProducts = products.filter(
+        item => Number(item?.productStockStatus) !== 2
+      );
+      if (unstockedProducts.length > 0) {
+        invalidLedgers.push(
+          `${ledgerName}(鏈叏閮ㄥ叆搴�${unstockedProducts.length}鏉�)`
+        );
+      }
+    }
+    return invalidLedgers;
+  };
+
   const handleBulkDelivery = async () => {
     if (selectedRows.value.length === 0) {
       proxy.$modal.msgWarning("璇烽�夋嫨鏁版嵁");
@@ -3951,12 +4546,44 @@
     }
 
     // 鍙厑璁搞�愭湭鍙戣揣/瀹℃壒澶辫触銆戣繘鍏ュ彂璐ф祦绋�
-    const canDeliveryLedgers = selectedRows.value.filter(r => {
-      const status = Number(r.deliveryStatus);
-      return status === 1 || status === 3;
+    const statusItem = selectedRows.value[0].deliveryStatus;
+    let isTrue = true;
+    selectedRows.value.forEach(row => {
+      if (row.deliveryStatus != 1 && row.deliveryStatus != 3) {
+        proxy.$modal.msgWarning("浠呮湭鍙戣揣鎴栧鎵瑰け璐ョ殑鍙拌处鍙互鍙戣揣");
+        isTrue = false;
+        return;
+      }
+      if (row.deliveryStatus !== statusItem) {
+        proxy.$modal.msgWarning("璇烽�夋嫨鐩稿悓鐘舵�佺殑閿�鍞彴璐�");
+        isTrue = false;
+        return;
+      }
     });
-    if (canDeliveryLedgers.length === 0) {
-      proxy.$modal.msgWarning("浠呮湭鍙戣揣鎴栧鎵瑰け璐ョ殑鍙拌处鍙互鍙戣揣");
+    if (!isTrue) {
+      return;
+    }
+
+    proxy.$modal.loading("姝e湪鏍¢獙鏄庣粏鍏ュ簱鐘舵�侊紝璇风◢鍊�...");
+    const invalidLedgers = await validateLedgersStockedBeforeDelivery(
+      selectedRows.value
+    );
+    proxy.$modal.closeLoading();
+    if (invalidLedgers.length > 0) {
+      try {
+        await ElMessageBox.alert(
+          `浠ヤ笅閿�鍞彴璐﹀瓨鍦ㄦ湭鍏ㄩ儴鍏ュ簱鐨勬槑缁嗭紝鏆備笉鍙彂璐э細\n${invalidLedgers.join(
+            "\n"
+          )}`,
+          "鎻愮ず",
+          {
+            type: "warning",
+            confirmButtonText: "鐭ラ亾浜�",
+          }
+        );
+      } catch {
+        /* 鍏抽棴寮圭獥 */
+      }
       return;
     }
 
@@ -4076,11 +4703,30 @@
   };
 
   // 鎵撳紑鍙戣揣寮规锛堝崟鏉★級
-  const openDeliveryForm = row => {
+  const openDeliveryForm = async row => {
     // 鍙厑璁搞�愭湭鍙戣揣/瀹℃壒澶辫触銆戝彂璐э紱宸插彂璐�/瀹℃壒涓笉鍏佽
     const status = Number(row.deliveryStatus);
     if (status !== 1 && status !== 3) {
       proxy.$modal.msgWarning("鍙湁鍙戣揣鐘舵�佷负鏈彂璐ф垨瀹℃壒澶辫触鐨勮褰曟墠鍙互鍙戣揣");
+      return;
+    }
+
+    proxy.$modal.loading("姝e湪鏍¢獙鏄庣粏鍏ュ簱鐘舵�侊紝璇风◢鍊�...");
+    const invalidLedgers = await validateLedgersStockedBeforeDelivery([row]);
+    proxy.$modal.closeLoading();
+    if (invalidLedgers.length > 0) {
+      try {
+        await ElMessageBox.alert(
+          `褰撳墠閿�鍞彴璐﹀瓨鍦ㄦ湭鍏ㄩ儴鍏ュ簱鐨勬槑缁嗭紝鏆備笉鍙彂璐э細\n${invalidLedgers[0]}`,
+          "鎻愮ず",
+          {
+            type: "warning",
+            confirmButtonText: "鐭ラ亾浜�",
+          }
+        );
+      } catch {
+        /* 鍏抽棴寮圭獥 */
+      }
       return;
     }
 
@@ -4231,4 +4877,70 @@
     justify-content: space-between;
     margin-bottom: 10px;
   }
+
+  .ledger-qr-dialog {
+    text-align: center;
+    padding-bottom: 8px;
+  }
+
+  .ledger-qr-composite-img {
+    max-width: 100%;
+    height: auto;
+    display: block;
+    margin: 0 auto 28px;
+  }
+
+  .ledger-qr-save-btn {
+    margin-bottom: 12px;
+  }
+
+  .approver-nodes-container {
+    display: flex;
+    flex-wrap: wrap;
+    gap: 16px;
+    padding: 16px;
+    background-color: #f8f9fa;
+    border-radius: 4px;
+    border: 1px solid #e4e7ed;
+  }
+
+  .approver-node-item {
+    flex: 0 0 calc(33.333% - 12px);
+    min-width: 200px;
+    padding: 12px;
+    background-color: #fff;
+    border-radius: 4px;
+    border: 1px solid #dcdfe6;
+    transition: all 0.3s;
+  }
+
+  .approver-node-item:hover {
+    border-color: #409eff;
+    box-shadow: 0 2px 8px rgba(64, 158, 255, 0.1);
+  }
+
+  .approver-node-header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    margin-bottom: 8px;
+  }
+
+  .approver-node-label {
+    font-size: 13px;
+    font-weight: 500;
+    color: #606266;
+  }
+
+  @media (max-width: 1200px) {
+    .approver-node-item {
+      flex: 0 0 calc(50% - 8px);
+    }
+  }
+
+  @media (max-width: 768px) {
+    .approver-node-item {
+      flex: 0 0 100%;
+    }
+  }
 </style>

--
Gitblit v1.9.3