新增本地USB打印

This commit is contained in:
gyq
2024-07-29 18:10:01 +08:00
parent 4fb34a4235
commit b2e450fd52
8 changed files with 222 additions and 46 deletions

View File

@@ -0,0 +1,83 @@
import getLodop from "./LodopFuncs.js";
export default (data) => {
let LODOP = getLodop();
LODOP.PRINT_INIT("打印小票");
// 设置打印纸大小D
LODOP.SET_PRINT_PAGESIZE(3, "58mm", 20, "");
//设置默认打印机(这里用的是打印机名称)
LODOP.SET_PRINTER_INDEX(data.deviceName);
// 文字内容
let html = `
<div style="font-size: 30px;display:flex;justify-content:center;">
${data.shop_name}
</div>
<div style="font-size: 16px;display: flex; justify-content:center;margin-top:6px;">
预结算单【${data.orderInfo.masterId ? data.orderInfo.masterId : ""}
</div>
<div style="font-size: 16px;display: flex; justify-content:center;margin-top:6px;">
${data.orderInfo.outNumber ? data.orderInfo.outNumber : ""}
</div>
<div style="margin-top: 30px;font-size: 12px;">
订单号:${data.orderInfo && data.orderInfo.orderNo}
</div>
<div style="margin-top: 4px;font-size: 12px;">
交易时间:${data.createdAt}
</div>
<div style="margin-top: 4px;font-size: 12px;">
收银员:${data.loginAccount}
</div>
<div style="margin-top: 6px;margin-bottom: 6px;border-bottom:1px dashed #000;"></div>
<table class="table">
<tr>
<td style="font-size: 12px;width:50%;">品名</td>
<td style="font-size: 12px;width:16.66%;">单价</td>
<td style="font-size: 12px;width:16.66%;">数量</td>
<td style="font-size: 12px;width:16.66%;">小计</td>
</tr>
`;
let table = "";
for (let item of data.carts) {
table += `
<tr>
<td style="font-size: 12px;width:50%;">
<div>${item.name}</div>
<div class="sku">规格:${item.skuName || ""}</div>
</td>
<td style="font-size: 12px;width:16.66%;">${item.salePrice}</td>
<td style="font-size: 12px;width:16.66%;">${item.number}</td>
<td style="font-size: 12px;width:16.66%;">
${item.totalAmount}
</td>
</tr>
`;
}
let str = `
</table>
<div style="margin-top: 6px; border-bottom:1px dashed #000;"></div>
<div style="margin-top: 6px; font-size: 22px;display:flex;justify-content: space-between;">
<span>应收</span>
<span>¥${data.amount}</span>
</div>
<div style="margin-top: 4px; font-size: 12px;">
<span>余额:</span>
<span>0.00</span>
</div>
<div style="margin-top: 6px; border-bottom:1px dashed #000;"></div>
<div style="margin-top: 4px; font-size: 12px;">备注:${data.remark}</div>
<div style="margin-top: 4px; padding-bottom: 50px;font-size: 12px;">
打印时间:${data.printTime}
</div>
<div style="height: 50px;"></div>
`;
let lastHtml = `${html}${table}${str}`;
setTimeout(() => {
LODOP.ADD_PRINT_HTM("9mm", "0mm", "RightMargin:0mm", 20, lastHtml);
LODOP.SET_LICENSES("", "DCFF409304DFCEB3E2C644BF96CD0720", "", "");
LODOP.PRINT();
}, 800);
};