旧秤端打的就是:分拣标签 / 客户 / 品名 / 重量(斤) / 日期 + 右上角商品条码二维码及其下码文,且不印订单号。本次把小程序与 Web 的标签版式改回逐项对齐该版式(50x30mm @8dot/mm),二维码内容回到商品条码,Web 纸宽 58mm 改 50x30mm。
80 lines
3.1 KiB
JavaScript
80 lines
3.1 KiB
JavaScript
/**
|
|
* 分拣标签打印(小程序 · BLE 热敏直连)。
|
|
* 设计:docs/design/20261013-分拣标签打印改蓝牙与浏览器直连.md
|
|
* 版式与旧安卓称重终端 PrintManager.buildPickingLabelBitmap 一致:
|
|
* 「分拣标签 / 客户:… / 品名:… / 重量:X.XX 斤(或数量) / 日期:…」+ 右上角二维码及其下码文;
|
|
* **不印订单号**。不走旧链路(print_jobs / 称重终端)。
|
|
*/
|
|
const { printThermal } = require('./printHistory');
|
|
const { displayText } = require('./pickingAssembly');
|
|
const { isWeightUnit } = require('./units');
|
|
const { fmtLocalDate } = require('./purchaseToday');
|
|
|
|
/** 市斤/斤(不含「公斤」,与秤端 WeighStationMatcher.isJinUnit 一致) */
|
|
function isJinUnit(unit) {
|
|
const u = String(unit || '').trim().toLowerCase();
|
|
if (!u) return false;
|
|
if (u.indexOf('公斤') >= 0 || u.indexOf('千克') >= 0 || u === 'kg' || u === 'g' || u === '克') {
|
|
return false;
|
|
}
|
|
return u.indexOf('斤') >= 0;
|
|
}
|
|
|
|
/** 克(与秤端 WeighStationMatcher.isGramUnit 一致) */
|
|
function isGramUnit(unit) {
|
|
const u = String(unit || '').trim().toLowerCase();
|
|
return u === 'g' || u === '克';
|
|
}
|
|
|
|
/** 展示用单位;空则默认斤(与秤端 displayUnit 一致) */
|
|
function displayUnit(unit) {
|
|
const u = String(unit || '').trim();
|
|
return u || '斤';
|
|
}
|
|
|
|
/** 标签重量/数量行(与旧秤端 formatLabelWeightLine 逐字一致):重量单位统一展示「斤」,计数单位展示数量。 */
|
|
function formatLabelWeightLine(qty, unit) {
|
|
const value = Number(qty) || 0;
|
|
if (!isWeightUnit(unit)) {
|
|
return `数量:${value.toFixed(2)} ${displayUnit(unit)}`;
|
|
}
|
|
let kg = value;
|
|
if (isJinUnit(unit)) kg = value / 2.0;
|
|
else if (isGramUnit(unit)) kg = value / 1000.0;
|
|
return `重量:${(kg * 2.0).toFixed(2)} 斤`;
|
|
}
|
|
|
|
/** 结算量优先(已确认实拣),否则落回需求量 —— 对齐旧秤端行为 */
|
|
function labelQty(item) {
|
|
const weight = Number(item && item.settlement_qty);
|
|
if (Number.isFinite(weight) && weight > 0) return weight;
|
|
return Number(item && item.required_qty) || 0;
|
|
}
|
|
|
|
/** 组装单张分拣标签(字段与旧秤端一致) */
|
|
function buildPickingLabel(task, item) {
|
|
const code = displayText(item && (item.barcode || item.sku_code));
|
|
const date = displayText(task && task.delivery_date).slice(0, 10) || fmtLocalDate();
|
|
return {
|
|
title: '分拣标签',
|
|
customer: `客户:${displayText(item && item.company_name, displayText(task && task.company_name)) || '客户'}`,
|
|
itemNameLine: `品名:${displayText(item && item.item_name, displayText(item && item.display_name)) || '商品'}`,
|
|
weightLine: formatLabelWeightLine(labelQty(item), item && item.unit),
|
|
dateLine: `日期:${date}`,
|
|
qrText: code,
|
|
};
|
|
}
|
|
|
|
/** 打印一张分拣标签;pickDevice 用于首次绑定 BLE 打印机 */
|
|
async function printPickingLabel(component, task, item, pickDevice) {
|
|
const label = buildPickingLabel(task, item);
|
|
await printThermal(component, { label }, pickDevice);
|
|
return label;
|
|
}
|
|
|
|
module.exports = {
|
|
buildPickingLabel,
|
|
formatLabelWeightLine,
|
|
printPickingLabel,
|
|
};
|