From 52459bcaba196c47a0f28079729b48ce012eaef1 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期六, 18 四月 2026 13:35:47 +0800
Subject: [PATCH] feat: 添加销售订单二维码功能及相关样式,更新操作列宽度
---
src/views/salesManagement/salesLedger/index.vue | 150 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 149 insertions(+), 1 deletions(-)
diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index f09b997..61251e2 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -221,6 +221,8 @@
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>
@@ -375,7 +377,7 @@
show-overflow-tooltip />
<el-table-column fixed="right"
label="鎿嶄綔"
- width="200"
+ width="280"
align="center">
<template #default="scope">
<el-button link
@@ -389,6 +391,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>
@@ -1662,6 +1667,11 @@
<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 />
@@ -1674,6 +1684,24 @@
纭鍏ュ簱
</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>
@@ -1722,6 +1750,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();
@@ -1756,6 +1785,109 @@
const selectedStockProductIds = ref([]);
const stockLoading = ref(false);
const currentStockLedgerId = ref(null);
+
+ 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 });
+ 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("");
@@ -4377,4 +4509,20 @@
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;
+ }
</style>
--
Gitblit v1.9.3