From 88566a9843fd0e1f4c98d696446f2ff27234ad72 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期六, 18 四月 2026 15:19:37 +0800
Subject: [PATCH] feat: 添加采购台账二维码功能及相关样式,更新操作列宽度

---
 src/views/procurementManagement/procurementLedger/index.vue |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/views/salesManagement/salesLedger/index.vue             |    8 ++
 2 files changed, 156 insertions(+), 3 deletions(-)

diff --git a/src/views/procurementManagement/procurementLedger/index.vue b/src/views/procurementManagement/procurementLedger/index.vue
index 4479251..163d88d 100644
--- a/src/views/procurementManagement/procurementLedger/index.vue
+++ b/src/views/procurementManagement/procurementLedger/index.vue
@@ -168,7 +168,7 @@
                          show-overflow-tooltip />
         <el-table-column fixed="right"
                          label="鎿嶄綔"
-                         width="120"
+                         width="200"
                          align="center">
           <template #default="scope">
             <el-button link
@@ -178,6 +178,9 @@
             <el-button link
                        type="primary"
                        @click="downLoadFile(scope.row)">闄勪欢</el-button>
+            <el-button link
+                       type="primary"
+                       @click="openProcurementQrDialog(scope.row)">浜岀淮鐮�</el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -689,6 +692,24 @@
     <FileListDialog ref="fileListRef"
                     v-model="fileListDialogVisible"
                     title="闄勪欢鍒楄〃" />
+    <el-dialog v-model="procurementQrDialogVisible"
+               title="閲囪喘鍙拌处浜岀淮鐮�"
+               width="360px"
+               draggable
+               :close-on-click-modal="false">
+      <div class="procurement-qr-dialog">
+        <img v-if="procurementQrCompositeUrl"
+             :src="procurementQrCompositeUrl"
+             alt="閲囪喘鍙拌处浜岀淮鐮�"
+             class="procurement-qr-composite-img" />
+        <el-button type="primary"
+                   class="procurement-qr-save-btn"
+                   :disabled="!procurementQrCompositeUrl"
+                   @click="downloadProcurementQrCode">
+          淇濆瓨鍥剧墖
+        </el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
@@ -732,6 +753,7 @@
     delPurchaseTemplate,
   } from "@/api/procurementManagement/procurementLedger.js";
   import useFormData from "@/hooks/useFormData.js";
+  import QRCode from "qrcode";
 
   const { proxy } = getCurrentInstance();
   const tableData = ref([]);
@@ -1871,6 +1893,117 @@
     }
   };
 
+  const procurementQrDialogVisible = ref(false);
+  const procurementQrCompositeUrl = ref("");
+  const procurementQrDownloadBaseName = ref("");
+
+  const sanitizeProcurementQrFilename = s =>
+    String(s)
+      .replace(/[\\/:*?"<>|]/g, "_")
+      .trim()
+      .slice(0, 80) || "ledger";
+
+  const wrapProcurementQrTextLines = (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 buildProcurementQrCompositeDataUrl = row =>
+    new Promise((resolve, reject) => {
+      const payload = JSON.stringify({
+        id: row.id,
+        purchaseContractNumber: (row.purchaseContractNumber ?? "").trim(),
+        type: "CG",
+      });
+      QRCode.toDataURL(payload, { width: 220, margin: 2 })
+        .then(qrDataUrl => {
+          const contract = (row.purchaseContractNumber ?? "").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 = wrapProcurementQrTextLines(
+              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 = sanitizeProcurementQrFilename(
+              contract !== "鈥�" ? contract : String(row.id)
+            );
+            resolve({ dataUrl: canvas.toDataURL("image/png"), baseName });
+          };
+          img.onerror = () => reject(new Error("浜岀淮鐮佸浘鐗囧姞杞藉け璐�"));
+          img.src = qrDataUrl;
+        })
+        .catch(reject);
+    });
+
+  const openProcurementQrDialog = async row => {
+    if (row?.id === undefined || row?.id === null || row?.id === "") {
+      ElMessage.warning("鏃犳硶鐢熸垚浜岀淮鐮侊細缂哄皯鍙拌处 ID");
+      return;
+    }
+    procurementQrCompositeUrl.value = "";
+    procurementQrDownloadBaseName.value = "";
+    try {
+      const { dataUrl, baseName } = await buildProcurementQrCompositeDataUrl(row);
+      procurementQrCompositeUrl.value = dataUrl;
+      procurementQrDownloadBaseName.value = baseName;
+      procurementQrDialogVisible.value = true;
+    } catch {
+      ElMessage.error("浜岀淮鐮佺敓鎴愬け璐�");
+    }
+  };
+
+  const downloadProcurementQrCode = () => {
+    if (!procurementQrCompositeUrl.value) return;
+    const a = document.createElement("a");
+    a.href = procurementQrCompositeUrl.value;
+    a.download = `閲囪喘鍙拌处浜岀淮鐮�-${procurementQrDownloadBaseName.value}.png`;
+    a.click();
+  };
+
   // 鑾峰彇妯℃澘淇℃伅
   const getTemplateList = async () => {
     let res = await getPurchaseTemplateList();
@@ -2009,4 +2142,20 @@
       transform: scale(1.2);
     }
   }
+
+  .procurement-qr-dialog {
+    text-align: center;
+    padding-bottom: 8px;
+  }
+
+  .procurement-qr-composite-img {
+    max-width: 100%;
+    height: auto;
+    display: block;
+    margin: 0 auto 28px;
+  }
+
+  .procurement-qr-save-btn {
+    margin-bottom: 12px;
+  }
 </style>
diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 61251e2..c974cc9 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -1815,7 +1815,11 @@
 
   const buildLedgerQrCompositeDataUrl = row =>
     new Promise((resolve, reject) => {
-      const payload = JSON.stringify({ id: row.id });
+      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() || "鈥�";
@@ -1885,7 +1889,7 @@
     if (!ledgerQrCompositeUrl.value) return;
     const a = document.createElement("a");
     a.href = ledgerQrCompositeUrl.value;
-    a.download = `閿�鍞攢鍞鍗曚簩缁寸爜-${ledgerQrDownloadBaseName.value}.png`;
+    a.download = `閿�鍞彴璐︿簩缁寸爜-${ledgerQrDownloadBaseName.value}.png`;
     a.click();
   };
 

--
Gitblit v1.9.3