Compare commits
4 Commits
prod
...
8655757dd6
| Author | SHA1 | Date | |
|---|---|---|---|
| 8655757dd6 | |||
| 78e88b8eb7 | |||
| c3a20ab2db | |||
| 5fab9a857a |
File diff suppressed because one or more lines are too long
@@ -5,6 +5,7 @@ import axios from "axios";
|
||||
import os from "os";
|
||||
import fs from "fs";
|
||||
import { exec } from "child_process";
|
||||
import { printReceipt, printHandoverReceipt, printRefund } from "./printService";
|
||||
|
||||
// ===== 核心配置:单文件缓存 =====
|
||||
// 固定的缓存文件路径(永远只存这1个文件)
|
||||
@@ -106,6 +107,46 @@ app.whenReady().then(() => {
|
||||
});
|
||||
});
|
||||
|
||||
// 打印结算小票
|
||||
ipcMain.on('networkPrint', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
console.log(_parmas);
|
||||
console.log(_parmas.orderData.carts);
|
||||
await printReceipt(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
})
|
||||
|
||||
// 打印交班小票
|
||||
ipcMain.on('printHandoverReceipt', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
console.log(_parmas);
|
||||
await printHandoverReceipt(_parmas.printerIp, _parmas.handoverData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印退菜单/退款小票
|
||||
ipcMain.on('printRefund', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await printRefund(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
||||
// 点击托盘图标时通常会重新创建一个新窗口
|
||||
|
||||
529
electron/printService.js
Normal file
529
electron/printService.js
Normal file
@@ -0,0 +1,529 @@
|
||||
// 网口打印机管理(80mm 终极美化版 · 无多余间距最终版)
|
||||
import net from 'net'
|
||||
import iconv from 'iconv-lite'
|
||||
|
||||
// ======================== 全局工具函数 ========================
|
||||
const getPrintWidth = (str) => {
|
||||
let width = 0
|
||||
const s = String(str || '')
|
||||
for (let i = 0; i < s.length; i++) {
|
||||
const char = s.charAt(i)
|
||||
if (/[\u4e00-\u9fa5\u3000-\u303f\uff00-\uffef]/.test(char)) {
|
||||
width += 2
|
||||
} else {
|
||||
width += 1
|
||||
}
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
const padLeftAlign = (str, targetWidth) => {
|
||||
const s = String(str || '')
|
||||
const currentWidth = getPrintWidth(s)
|
||||
const spaceNum = Math.max(0, targetWidth - currentWidth)
|
||||
return s + ' '.repeat(spaceNum)
|
||||
}
|
||||
|
||||
const padRightAlign = (str, targetWidth) => {
|
||||
const s = String(str || '')
|
||||
const currentWidth = getPrintWidth(s)
|
||||
const spaceNum = Math.max(0, targetWidth - currentWidth)
|
||||
return ' '.repeat(spaceNum) + s
|
||||
}
|
||||
|
||||
const truncateByPrintWidth = (str, maxWidth) => {
|
||||
const s = String(str || '')
|
||||
let width = 0
|
||||
let result = ''
|
||||
for (const char of s) {
|
||||
const charWidth = /[\u4e00-\u9fa5\u3000-\u303f\uff00-\uffef]/.test(char) ? 2 : 1
|
||||
if (width + charWidth > maxWidth) break
|
||||
result += char
|
||||
width += charWidth
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const centerAlign = (str, lineWidth = 48) => {
|
||||
const s = String(str || '').trim(); // 去除首尾空格,避免干扰
|
||||
const currentWidth = getPrintWidth(s);
|
||||
if (currentWidth >= lineWidth) return s; // 内容超宽时直接返回,不居中
|
||||
|
||||
const totalPad = lineWidth - currentWidth;
|
||||
const leftPad = Math.floor(totalPad / 2);
|
||||
const rightPad = totalPad - leftPad; // 避免奇数宽度时总长度超行宽
|
||||
|
||||
// 用空格填充左右,保证总宽度严格等于 lineWidth
|
||||
return ' '.repeat(leftPad) + s + ' '.repeat(rightPad);
|
||||
};
|
||||
|
||||
const createDivider = (lineWidth = 48, type = 'full') => {
|
||||
const fullChar = '═'
|
||||
const thinChar = '─'
|
||||
const char = type === 'full' ? fullChar : thinChar
|
||||
return char.repeat(Math.ceil(lineWidth / 2)).substring(0, lineWidth)
|
||||
}
|
||||
|
||||
const setupPrinter = (socket, options = {}) => {
|
||||
socket.write(Buffer.from([0x1B, 0x40]))
|
||||
if (options.fontSize) {
|
||||
socket.write(Buffer.from([0x1B, 0x21, options.fontSize]))
|
||||
}
|
||||
if (options.bold) {
|
||||
socket.write(Buffer.from([0x1B, 0x45, options.bold ? 0x01 : 0x00]))
|
||||
}
|
||||
}
|
||||
|
||||
// 用餐模式 堂食 dine-in 外带 take-out 外卖 take-away
|
||||
const dineModeFilter = t => {
|
||||
if (t === 'dine-in') return '堂食'
|
||||
if (t === 'take-out') return '外带'
|
||||
if (t === 'take-away') return '外卖'
|
||||
return t
|
||||
}
|
||||
|
||||
// ======================== 打印结算小票 ========================
|
||||
export function printReceipt(printerIp, order) {
|
||||
return new Promise((resolve) => {
|
||||
const socket = new net.Socket()
|
||||
const lineWidth = 48
|
||||
socket.setTimeout(8000)
|
||||
|
||||
const formatAmount = (amount) => Number(amount || 0).toFixed(2)
|
||||
|
||||
socket.connect(9100, printerIp, () => {
|
||||
try {
|
||||
setupPrinter(socket)
|
||||
|
||||
// ======================== 标题区域(彻底修复居中问题!) ========================
|
||||
const title1 = order.shop_name || '';
|
||||
let title2 = `结算单 #${order.orderInfo.orderNum}`
|
||||
if (order.isBefore && !order.isGuest) {
|
||||
title2 = `${order.isBefore ? '预' : ''}结算单 #${order.orderInfo.orderNum}`;
|
||||
}
|
||||
if (order.isGuest && order.isBefore) {
|
||||
title2 = `客看单 #${order.orderInfo.orderNum}`;
|
||||
}
|
||||
|
||||
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
||||
socket.write(iconv.encode('\n', 'gbk'));
|
||||
|
||||
// 步骤1:重置打印机格式(避免残留格式影响)
|
||||
socket.write(Buffer.from([0x1B, 0x40]));
|
||||
// 步骤2:居中对齐标题
|
||||
socket.write(Buffer.from([0x1B, 0x61, 0x01])); // 1 = center
|
||||
// 步骤3:设置标题1的格式(加粗+大号字体)
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 字号放大(0x11 是常用放大值)
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(title1 + '\n', 'gbk'));
|
||||
|
||||
// 步骤4:恢复格式,打印标题2(常规字体)
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
socket.write(iconv.encode(title2 + '\n\n', 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x61, 0x00])); // 0 = left
|
||||
|
||||
// ======================== 订单信息(修复显示+换行问题) ========================
|
||||
const tableLine = padLeftAlign('桌台号:', 8) + padLeftAlign(order.orderInfo.tableName || '无', 14) + '\n'
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 正常字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(tableLine, 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
|
||||
let orderInfo = ''
|
||||
|
||||
// 修复:打印机-用餐模式 + 就餐人数 展示逻辑
|
||||
const dineModeText = dineModeFilter(order.orderInfo.dineMode)
|
||||
// 1. 拼接打印机+用餐模式文本,空值兜底
|
||||
const printerDineText = `${order.printerName || '未知打印机'}-${dineModeText || '未知模式'}`
|
||||
// 2. 截断超长文本(左侧分配20宽度,保证不超限)
|
||||
const truncatedPrinterDine = truncateByPrintWidth(printerDineText, 20)
|
||||
// 3. 左侧左对齐填充20宽度(保证占满分配空间,不浪费空白)
|
||||
const leftPart = padLeftAlign(truncatedPrinterDine, 20)
|
||||
// 4. 右侧就餐人数:空值兜底为“无”,右对齐填充28宽度(20+28=48,刚好行宽)
|
||||
const seatNumText = order.orderInfo.seatNum || '0'
|
||||
const rightPart = padRightAlign(`${seatNumText}人`, 28) // 加标签更清晰,也可只显示数字
|
||||
|
||||
orderInfo += leftPart + rightPart + '\n'
|
||||
if (!order.isBefore) {
|
||||
orderInfo += padLeftAlign('结账时间:', 10) + padLeftAlign(order.createdAt || '-', 38) + '\n'
|
||||
}
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
// ======================== 商品表格 ========================
|
||||
orderInfo += padLeftAlign('品名', 18)
|
||||
orderInfo += padLeftAlign('单价', 8)
|
||||
orderInfo += padLeftAlign('数量', 6)
|
||||
orderInfo += padRightAlign('小计', 16) + '\n'
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
order.carts.forEach(item => {
|
||||
const name = truncateByPrintWidth(item.name || '未知商品', 18)
|
||||
const price = formatAmount(item.salePrice)
|
||||
const num = item.number || 1
|
||||
const total = formatAmount(item.totalAmount)
|
||||
orderInfo += padLeftAlign(name, 18)
|
||||
orderInfo += padLeftAlign(price, 8)
|
||||
orderInfo += padLeftAlign(num, 6)
|
||||
orderInfo += padRightAlign(total, 16) + '\n'
|
||||
})
|
||||
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
orderInfo += padLeftAlign('原价', 10) + padRightAlign(formatAmount(order.originAmount), 38) + '\n'
|
||||
orderInfo += padLeftAlign('优惠金额', 10) + padRightAlign(`-${formatAmount(order.discountAllAmount)}`, 38) + '\n'
|
||||
orderInfo += padLeftAlign('备注:', 6) + padLeftAlign(order.remark || '无', 38) + '\n'
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
socket.write(iconv.encode(orderInfo, 'gbk'))
|
||||
|
||||
// ======================== 付款信息 ========================
|
||||
const payableLine = padLeftAlign('应付', 10) + padRightAlign(formatAmount(order.originAmount), 51) + '\n'
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 放大字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(payableLine, 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
||||
if (!order.isBefore) {
|
||||
const paidLine = padLeftAlign('已付', 10) + padRightAlign(formatAmount(order.orderInfo.payAmount), 51) + '\n'
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x11]));
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01]));
|
||||
socket.write(iconv.encode(paidLine, 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00]));
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00]));
|
||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
||||
}
|
||||
|
||||
// ======================== 底部 ========================
|
||||
let bottom = ''
|
||||
bottom += padLeftAlign('操作员:', 8) + padLeftAlign(order.loginAccount || '无', 38) + '\n'
|
||||
bottom += padLeftAlign('打印时间:', 10) + padLeftAlign(new Date().toLocaleString(), 38) + '\n'
|
||||
bottom += padLeftAlign('订单号:', 8) + padLeftAlign(order.orderInfo.orderNo || '-', 38) + '\n'
|
||||
bottom += createDivider(lineWidth, 'full') + '\n'
|
||||
bottom += '\n\n'
|
||||
bottom += '\n\n'
|
||||
|
||||
socket.write(iconv.encode(bottom, 'gbk'))
|
||||
socket.write(Buffer.from([0x1D, 0x56, 0x00]))
|
||||
|
||||
setTimeout(() => {
|
||||
socket.end()
|
||||
resolve('success')
|
||||
}, 400)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
socket.destroy()
|
||||
resolve('error')
|
||||
}
|
||||
})
|
||||
|
||||
socket.on('error', () => resolve('error'))
|
||||
socket.on('timeout', () => resolve('timeout'))
|
||||
socket.on('close', () => { })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// ======================== 打印退菜单/退款小票 ========================
|
||||
export function printRefund(printerIp, order) {
|
||||
console.log(JSON.stringify(order));
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const socket = new net.Socket()
|
||||
const lineWidth = 48
|
||||
socket.setTimeout(8000)
|
||||
|
||||
const formatAmount = (amount) => Number(amount || 0).toFixed(2)
|
||||
|
||||
socket.connect(9100, printerIp, () => {
|
||||
try {
|
||||
setupPrinter(socket)
|
||||
|
||||
// ======================== 标题区域(彻底修复居中问题!) ========================
|
||||
const title1 = order.shop_name || '';
|
||||
let title2 = order.title || '退款单'
|
||||
|
||||
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
||||
socket.write(iconv.encode('\n', 'gbk'));
|
||||
|
||||
// 步骤1:重置打印机格式(避免残留格式影响)
|
||||
socket.write(Buffer.from([0x1B, 0x40]));
|
||||
// 步骤2:居中对齐标题
|
||||
socket.write(Buffer.from([0x1B, 0x61, 0x01])); // 1 = center
|
||||
// 步骤3:设置标题1的格式(加粗+大号字体)
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 字号放大(0x11 是常用放大值)
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(title1 + '\n', 'gbk'));
|
||||
|
||||
// 步骤4:恢复格式,打印标题2(常规字体)
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
socket.write(iconv.encode(title2 + '\n\n', 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x61, 0x00])); // 0 = left
|
||||
|
||||
// ======================== 订单信息(修复显示+换行问题) ========================
|
||||
const tableLine = padLeftAlign('桌台号:', 8) + padLeftAlign(order.orderInfo.tableName || '无', 14) + '\n'
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 正常字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(tableLine, 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
|
||||
let orderInfo = ''
|
||||
|
||||
// 修复:打印机-用餐模式 + 就餐人数 展示逻辑
|
||||
const dineModeText = dineModeFilter(order.orderInfo.dineMode)
|
||||
// 1. 拼接打印机+用餐模式文本,空值兜底
|
||||
const printerDineText = `${order.printerName || '未知打印机'}-${dineModeText || '未知模式'}`
|
||||
// 2. 截断超长文本(左侧分配20宽度,保证不超限)
|
||||
const truncatedPrinterDine = truncateByPrintWidth(printerDineText, 20)
|
||||
// 3. 左侧左对齐填充20宽度(保证占满分配空间,不浪费空白)
|
||||
const leftPart = padLeftAlign(truncatedPrinterDine, 20)
|
||||
// 4. 右侧就餐人数:空值兜底为“无”,右对齐填充28宽度(20+28=48,刚好行宽)
|
||||
const seatNumText = order.orderInfo.seatNum || '0'
|
||||
const rightPart = padRightAlign(`${seatNumText}人`, 28) // 加标签更清晰,也可只显示数字
|
||||
|
||||
if (order.carts.length > 0) {
|
||||
orderInfo += leftPart + rightPart + '\n'
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
// ======================== 商品表格 ========================
|
||||
orderInfo += padLeftAlign('品名', 18)
|
||||
orderInfo += padLeftAlign('单价', 8)
|
||||
orderInfo += padLeftAlign('数量', 6)
|
||||
orderInfo += padRightAlign('小计', 16) + '\n'
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
order.carts.forEach(item => {
|
||||
const name = truncateByPrintWidth(item.name || '未知商品', 18)
|
||||
const price = formatAmount(item.salePrice)
|
||||
const num = item.number || 1
|
||||
const total = formatAmount(item.totalAmount)
|
||||
orderInfo += padLeftAlign(name, 18)
|
||||
orderInfo += padLeftAlign(price, 8)
|
||||
orderInfo += padLeftAlign(num, 6)
|
||||
orderInfo += padRightAlign(total, 16) + '\n'
|
||||
})
|
||||
|
||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
socket.write(iconv.encode(orderInfo, 'gbk'))
|
||||
}
|
||||
|
||||
// ======================== 付款信息 ========================
|
||||
let payableLine = ''
|
||||
payableLine += padLeftAlign('退款总计', 10) + padRightAlign(formatAmount(order.amount), 51) + '\n'
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 放大字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(payableLine, 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
let refundInfo = ''
|
||||
refundInfo += padLeftAlign('退款方式:', 10) + padLeftAlign(order.refundMethod || '无', 38) + '\n'
|
||||
refundInfo += padLeftAlign('退款原因:', 10) + padLeftAlign(order.remark || '无', 38) + '\n'
|
||||
socket.write(iconv.encode(refundInfo, 'gbk'));
|
||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
||||
|
||||
// ======================== 底部 ========================
|
||||
let bottom = ''
|
||||
bottom += padLeftAlign('操作员:', 8) + padLeftAlign(order.loginAccount || '无', 38) + '\n'
|
||||
bottom += padLeftAlign('打印时间:', 10) + padLeftAlign(new Date().toLocaleString(), 38) + '\n'
|
||||
bottom += padLeftAlign('原订单号:', 10) + padLeftAlign(order.orderInfo.orderNo || '-', 38) + '\n'
|
||||
bottom += createDivider(lineWidth, 'full') + '\n'
|
||||
bottom += '\n\n'
|
||||
bottom += '\n\n'
|
||||
|
||||
socket.write(iconv.encode(bottom, 'gbk'))
|
||||
socket.write(Buffer.from([0x1D, 0x56, 0x00]))
|
||||
|
||||
setTimeout(() => {
|
||||
socket.end()
|
||||
resolve('success')
|
||||
}, 400)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
socket.destroy()
|
||||
resolve('error')
|
||||
}
|
||||
})
|
||||
|
||||
socket.on('error', () => resolve('error'))
|
||||
socket.on('timeout', () => resolve('timeout'))
|
||||
socket.on('close', () => { })
|
||||
})
|
||||
}
|
||||
|
||||
// ======================== 打印交班小票(完整版 · 补齐分类/商品数据) ========================
|
||||
export function printHandoverReceipt(printerIp, data) {
|
||||
return new Promise((resolve) => {
|
||||
const socket = new net.Socket()
|
||||
const lineWidth = 48
|
||||
socket.setTimeout(8000)
|
||||
|
||||
const formatAmount = (v) => Number(v || 0).toFixed(2)
|
||||
|
||||
socket.connect(9100, printerIp, () => {
|
||||
try {
|
||||
setupPrinter(socket)
|
||||
|
||||
// ======================== 标题区域(统一结算小票的居中修复逻辑) ========================
|
||||
const title1 = data.shopName || '店铺';
|
||||
const title2 = '交班小票';
|
||||
|
||||
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
||||
socket.write(iconv.encode('\n', 'gbk'));
|
||||
|
||||
// 步骤1:重置打印机格式(避免残留格式影响)
|
||||
socket.write(Buffer.from([0x1B, 0x40]));
|
||||
// 步骤2:居中对齐标题
|
||||
socket.write(Buffer.from([0x1B, 0x61, 0x01])); // 1 = center
|
||||
// 步骤3:设置标题1的格式(加粗+大号字体)
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 字号放大(0x11 是常用放大值)
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
socket.write(iconv.encode(title1 + '\n', 'gbk'));
|
||||
|
||||
// 步骤4:恢复格式,打印标题2(常规字体)
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
socket.write(iconv.encode(title2 + '\n\n', 'gbk'));
|
||||
socket.write(Buffer.from([0x1B, 0x61, 0x00])); // 0 = left
|
||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
||||
|
||||
// ======================== 基础信息区域(拆分当班/交班时间) ========================
|
||||
let basicInfo = ''
|
||||
// 优化:拆分当班时间和交班时间,空值兜底
|
||||
basicInfo += padLeftAlign('交班时间:', 10) + padLeftAlign(data.handoverTime || '-', 36) + '\n'
|
||||
basicInfo += padLeftAlign('收银员:', 8) + padLeftAlign(data.staffName || '-', 36) + '\n'
|
||||
basicInfo += padLeftAlign('交班周期:', 10) + padLeftAlign(`${data.loginTime}-${data.handoverTime}` || '-', 36) + '\n\n'
|
||||
|
||||
// basicInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
// 收入明细 - 补充会员支付/充值字段
|
||||
basicInfo += padLeftAlign('当班营业总额:', 10) + padLeftAlign(formatAmount(data.handAmount), 36) + '\n'
|
||||
basicInfo += padLeftAlign('实际收款的支付方式', 10) + '\n'
|
||||
basicInfo += padLeftAlign('现金', 10) + padRightAlign(formatAmount(data.cashAmount), 36) + '\n'
|
||||
basicInfo += padLeftAlign('微信', 10) + padRightAlign(formatAmount(data.wechatAmount), 36) + '\n'
|
||||
basicInfo += padLeftAlign('支付宝', 10) + padRightAlign(formatAmount(data.alipayAmount), 36) + '\n'
|
||||
basicInfo += padLeftAlign('二维码收款', 10) + padRightAlign(formatAmount(data.vipPay), 36) + '\n'
|
||||
basicInfo += padLeftAlign('扫码收款', 10) + padRightAlign(formatAmount(data.vipRecharge), 36) + '\n\n'
|
||||
basicInfo += padLeftAlign('非实际收款的支付方式', 10) + '\n'
|
||||
basicInfo += padLeftAlign('挂账', 10) + padRightAlign(formatAmount(data.creditAmount), 36) + '\n'
|
||||
basicInfo += padLeftAlign('余额', 10) + padRightAlign(formatAmount(data.vipPay), 36) + '\n'
|
||||
basicInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 正常字号
|
||||
socket.write(iconv.encode(basicInfo, 'gbk'))
|
||||
|
||||
let refundInfo = ''
|
||||
refundInfo += padLeftAlign('退款/退菜', 10) + '\n'
|
||||
refundInfo += padLeftAlign('退款金额', 10) + padRightAlign(formatAmount(data.refundAmount), 36) + '\n'
|
||||
refundInfo += padLeftAlign('退菜数量', 10) + padRightAlign(formatAmount(data.refundAmount), 36) + '\n'
|
||||
refundInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
socket.write(iconv.encode(refundInfo, 'gbk'))
|
||||
|
||||
let orderInfo = ''
|
||||
const orderLabel = '订单(数量/订单总额)'
|
||||
const orderValue = `${data.orderCount}/${formatAmount(data.orderAmount)}`
|
||||
const orderLabelWidth = lineWidth - getPrintWidth(orderValue)
|
||||
orderInfo += padLeftAlign(orderLabel, orderLabelWidth) + orderValue + '\n\n'
|
||||
socket.write(iconv.encode(orderInfo, 'gbk'))
|
||||
|
||||
// ======================== 分类数据区域 ========================
|
||||
let categoryInfo = ''
|
||||
if (data.categoryDataList && data.categoryDataList.length) {
|
||||
categoryInfo += centerAlign('销售数据', lineWidth) + '\n'
|
||||
categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
// 分类表头
|
||||
categoryInfo += padLeftAlign('名称', 24) + padLeftAlign('数量', 12) + padRightAlign('总计', 12) + '\n'
|
||||
// categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
// 分类数据行
|
||||
data.categoryDataList.forEach(item => {
|
||||
const catName = truncateByPrintWidth(item.categoryName || '未知分类', 24)
|
||||
const num = item.num || 0
|
||||
const amount = formatAmount(item.amount)
|
||||
categoryInfo += padLeftAlign(catName, 24) + padLeftAlign(num, 12) + padRightAlign(amount, 12) + '\n'
|
||||
})
|
||||
categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
}
|
||||
socket.write(iconv.encode(categoryInfo, 'gbk'))
|
||||
|
||||
// ======================== 商品数据区域 ========================
|
||||
let productInfo = ''
|
||||
if (data.printShop && data.productDataList && data.productDataList.length) {
|
||||
productInfo += centerAlign('商品数据', lineWidth) + '\n'
|
||||
productInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
// 商品表头
|
||||
productInfo += padLeftAlign('商品', 36) + padRightAlign('数量', 12) + '\n'
|
||||
// productInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
// 商品数据行
|
||||
data.productDataList.forEach(item => {
|
||||
const prodName = truncateByPrintWidth(item.productName || '未知商品', 36)
|
||||
const num = item.num || 0
|
||||
productInfo += padLeftAlign(prodName, 36) + padRightAlign(num, 12) + '\n'
|
||||
})
|
||||
productInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
}
|
||||
socket.write(iconv.encode(productInfo, 'gbk'))
|
||||
|
||||
// ======================== 收入明细区域(优化对齐和格式) ========================
|
||||
// let incomeInfo = ''
|
||||
// incomeInfo += centerAlign('【收支汇总】', lineWidth) + '\n'
|
||||
// incomeInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||
|
||||
// // 收支汇总项(补充挂账金额)
|
||||
// const incomeItems = [
|
||||
// { label: '快捷收款金额:', val: data.quickInAmount },
|
||||
// { label: '退款金额:', val: data.refundAmount },
|
||||
// { label: '总收入:', val: data.handAmount },
|
||||
// { label: '挂账金额:', val: data.creditAmount },
|
||||
// { label: '总订单数:', val: data.orderCount || 0 }
|
||||
// ]
|
||||
|
||||
// incomeItems.forEach((item, index) => {
|
||||
// const labelPart = padLeftAlign(item.label, 16)
|
||||
// let valPart = ''
|
||||
// // 总收入/总订单数加粗显示
|
||||
// if (index === 2 || index === 4) {
|
||||
// socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
||||
// valPart = padRightAlign(index === 4 ? item.val : formatAmount(item.val), 32)
|
||||
// incomeInfo += labelPart + valPart + '\n'
|
||||
// socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
||||
// } else {
|
||||
// valPart = padRightAlign(formatAmount(item.val), 32)
|
||||
// incomeInfo += labelPart + valPart + '\n'
|
||||
// }
|
||||
// })
|
||||
|
||||
// incomeInfo += createDivider(lineWidth, 'full') + '\n'
|
||||
// socket.write(iconv.encode(incomeInfo, 'gbk'))
|
||||
|
||||
// ======================== 底部区域(统一结算小票风格) ========================
|
||||
let bottomInfo = ''
|
||||
bottomInfo += padLeftAlign('打印时间:', 12) + padRightAlign(data.printTime || new Date().toLocaleString(), 36) + '\n'
|
||||
bottomInfo += createDivider(lineWidth, 'full') + '\n'
|
||||
// 增加空行,避免打印内容紧贴纸边
|
||||
bottomInfo += '\n\n'
|
||||
bottomInfo += '\n\n'
|
||||
|
||||
socket.write(iconv.encode(bottomInfo, 'gbk'))
|
||||
// 切纸指令(统一结算小票的切纸逻辑)
|
||||
socket.write(Buffer.from([0x1D, 0x56, 0x00]))
|
||||
|
||||
// 统一延迟关闭连接,保证数据完整发送
|
||||
setTimeout(() => {
|
||||
socket.end()
|
||||
resolve('success')
|
||||
}, 400)
|
||||
} catch (err) {
|
||||
console.error('打印交班小票异常:', err)
|
||||
socket.destroy()
|
||||
resolve('error')
|
||||
}
|
||||
})
|
||||
|
||||
// 统一错误处理(对齐结算小票的错误处理逻辑)
|
||||
socket.on('error', (err) => {
|
||||
console.error('打印机连接错误:', err)
|
||||
resolve('error')
|
||||
})
|
||||
socket.on('timeout', () => resolve('timeout'))
|
||||
socket.on('close', () => { })
|
||||
})
|
||||
}
|
||||
1145
package-lock.json
generated
1145
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -19,6 +19,7 @@
|
||||
"electron-pos-printer": "^1.3.6",
|
||||
"electron-pos-printer-vue": "^1.0.9",
|
||||
"element-plus": "^2.4.3",
|
||||
"iconv-lite": "^0.7.2",
|
||||
"js-md5": "^0.8.3",
|
||||
"lodash": "^4.17.21",
|
||||
"pinia": "^2.1.7",
|
||||
@@ -30,13 +31,13 @@
|
||||
"uuid": "^10.0.0",
|
||||
"vue": "^3.3.8",
|
||||
"vue-router": "^4.2.5",
|
||||
"win32-api": "^26.1.2",
|
||||
"ysk-utils": "^1.0.84"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.5.0",
|
||||
"electron": "^28.3.3",
|
||||
"electron-builder": "^24.13.3",
|
||||
"electron-rebuild": "^3.2.9",
|
||||
"path": "^0.12.7",
|
||||
"sass": "^1.69.5",
|
||||
"sass-loader": "^13.3.2",
|
||||
@@ -79,4 +80,4 @@
|
||||
"createStartMenuShortcut": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
printer.sdk.dll
Normal file
BIN
printer.sdk.dll
Normal file
Binary file not shown.
@@ -321,7 +321,7 @@ export function printerList(subType = "") {
|
||||
params: {
|
||||
name: "",
|
||||
subType: subType,
|
||||
connectionType: "USB",
|
||||
connectionType: "",
|
||||
page: 1,
|
||||
size: 100,
|
||||
},
|
||||
|
||||
@@ -51,3 +51,56 @@ export function markIsSoldOut(data) {
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存酒商品列表
|
||||
* @param {*} params
|
||||
* @returns
|
||||
*/
|
||||
export function storageGoodGet(params) {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/product/admin/storageGood",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 存酒记录添加
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
export function shopStoragePost(data) {
|
||||
return request({
|
||||
method: "post",
|
||||
url: "/product/admin/shopStorage",
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 存酒记录
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
export function shopStorageGet(params) {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/product/admin/shopStorage",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 存酒取酒
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
export function shopStoragePut(data) {
|
||||
return request({
|
||||
method: "put",
|
||||
url: "/product/admin/shopStorage",
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,30 +11,28 @@ import { useSocket } from './socket.js';
|
||||
|
||||
export const usePrint = defineStore("print", {
|
||||
state: () => ({
|
||||
isPrintService: false, // 打印服务是否启动
|
||||
printServiceTimer: false, // 打印服务定时器
|
||||
printServiceTimerCount: 0, // 打印服务定时器计数
|
||||
printServiceTimerMaxCount: 10, // 打印服务定时器最大计数
|
||||
showPrintNotService: false, // 是否显示重启软件,
|
||||
localDevices: [], // 本地打印机列表
|
||||
deviceNoteList: [], // 添加的打印机
|
||||
deviceLableList: [], // 添加的打印机
|
||||
labelList: [], // 要打印的队列数据
|
||||
isPrintService: false,
|
||||
printServiceTimer: null,
|
||||
printServiceTimerCount: 0,
|
||||
printServiceTimerMaxCount: 10,
|
||||
showPrintNotService: false,
|
||||
localDevices: [],
|
||||
deviceNoteList: [],
|
||||
deviceLableList: [],
|
||||
labelList: [],
|
||||
printTimer: null,
|
||||
receiptList: [], // 小票队列数据
|
||||
receiptList: [],
|
||||
receiptTimer: null,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
// 获取本地打印机和已添加的可以用打印机列表
|
||||
async init() {
|
||||
// 获取本地打印机
|
||||
ipcRenderer.send("getPrintList");
|
||||
ipcRenderer.on("printList", (event, arg) => {
|
||||
this.localDevices = arg;
|
||||
});
|
||||
|
||||
try {
|
||||
// 获取已添加的打印机
|
||||
const res = await printerList();
|
||||
this.deviceNoteList = res.records.filter(
|
||||
(item) => item.status && item.subType == "cash"
|
||||
@@ -42,18 +40,12 @@ export const usePrint = defineStore("print", {
|
||||
this.deviceLableList = res.records.filter(
|
||||
(item) => item.status && item.subType == "label"
|
||||
);
|
||||
console.log("打印队列初始化成功", {
|
||||
deviceNoteList: this.deviceNoteList,
|
||||
deviceLableList: this.deviceLableList,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("获取已添加的打印机列表失败", error);
|
||||
console.error("获取打印机列表失败", error);
|
||||
}
|
||||
|
||||
// 检测打印服务是否启动
|
||||
this.checkPrintService();
|
||||
},
|
||||
// 检测打印组件服务是否启动
|
||||
|
||||
checkPrintService() {
|
||||
this.printServiceTimer = setInterval(() => {
|
||||
if (
|
||||
@@ -61,26 +53,154 @@ export const usePrint = defineStore("print", {
|
||||
LODOP.webskt &&
|
||||
LODOP.webskt.readyState == 1
|
||||
) {
|
||||
// 准备好
|
||||
this.isPrintService = true;
|
||||
clearInterval(this.printServiceTimer);
|
||||
this.printServiceTimer = null;
|
||||
} else {
|
||||
this.printServiceTimerCount++;
|
||||
console.log("打印服务未启动", this.printServiceTimerCount);
|
||||
|
||||
if (this.printServiceTimerCount >= this.printServiceTimerMaxCount) {
|
||||
// 超过最大次数
|
||||
this.isPrintService = false;
|
||||
this.showPrintNotService = true;
|
||||
clearInterval(this.printServiceTimer);
|
||||
this.printServiceTimer = null;
|
||||
}
|
||||
}
|
||||
console.log("打印服务是否启动:", this.isPrintService);
|
||||
}, 1000);
|
||||
},
|
||||
// 检查本地打印机是否能正常使用
|
||||
|
||||
// 检查打印机是否可用
|
||||
checkPrinterAvailable(printer) {
|
||||
if (printer.connectionType === "局域网") {
|
||||
const ipReg = /^(\d{1,3}\.){3}\d{1,3}$/;
|
||||
return ipReg.test(printer.address);
|
||||
}
|
||||
|
||||
if (printer.connectionType === "usb") {
|
||||
return this.localDevices.some(item => item.name === printer.address);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// ==============================
|
||||
// 最终完美版 → 空数组打印全部
|
||||
// ==============================
|
||||
pushReceiptData(props, isDevice = true) {
|
||||
if (!isDevice) {
|
||||
this.receiptList.push(props);
|
||||
this.startReceiptPrint();
|
||||
return;
|
||||
}
|
||||
|
||||
const validPrinters = this.deviceNoteList.filter(p => {
|
||||
return this.checkPrinterAvailable(p) && this.isPrintService;
|
||||
});
|
||||
|
||||
if (validPrinters.length === 0) {
|
||||
console.log("无可用小票打印机");
|
||||
return;
|
||||
}
|
||||
|
||||
const store = useUser();
|
||||
|
||||
validPrinters.forEach(printer => {
|
||||
let filterCarts = [];
|
||||
|
||||
// ======================================
|
||||
// ✅ 核心:分类为空数组 → 打印全部菜品
|
||||
// ======================================
|
||||
if (!printer.categoryList || printer.categoryList.length === 0) {
|
||||
filterCarts = props.carts || [];
|
||||
} else {
|
||||
// 有分类 → 只打印对应分类
|
||||
filterCarts = (props.carts || []).filter(item => {
|
||||
return printer.categoryList.includes(item.categoryId);
|
||||
});
|
||||
}
|
||||
|
||||
if (filterCarts.length === 0) return;
|
||||
|
||||
const printData = {
|
||||
...props,
|
||||
carts: filterCarts,
|
||||
deviceId: printer.id,
|
||||
deviceName: printer.address,
|
||||
printerName: printer.name,
|
||||
connectionType: printer.connectionType,
|
||||
shop_name: store.shopInfo.shopName,
|
||||
loginAccount: store.userInfo.name,
|
||||
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
|
||||
if (!printData.orderInfo.masterId) {
|
||||
printData.orderInfo.masterId = printData.orderInfo.tableName;
|
||||
}
|
||||
printData.orderInfo.outNumber = printData.outNumber;
|
||||
if (!printData.discountAmount) {
|
||||
printData.discountAmount = printData.amount;
|
||||
}
|
||||
|
||||
this.receiptList.push(printData);
|
||||
});
|
||||
|
||||
if (this.receiptList.length > 0) {
|
||||
this.startReceiptPrint();
|
||||
}
|
||||
},
|
||||
|
||||
// ==============================
|
||||
// 打印执行(USB/局域网自动区分)
|
||||
// ==============================
|
||||
async startReceiptPrint() {
|
||||
try {
|
||||
const socketStore = useSocket();
|
||||
const userStore = useUser();
|
||||
if (this.receiptTimer !== null) return;
|
||||
|
||||
this.receiptTimer = setInterval(() => {
|
||||
if (!this.receiptList.length) {
|
||||
clearInterval(this.receiptTimer);
|
||||
this.receiptTimer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const printData = this.receiptList[0];
|
||||
try {
|
||||
if (printData.connectionType === "局域网") {
|
||||
ipcRenderer.send('networkPrint', JSON.stringify({
|
||||
printerIp: printData.deviceName,
|
||||
orderData: printData
|
||||
}));
|
||||
} else {
|
||||
receiptPrint(printData);
|
||||
}
|
||||
|
||||
const syncData = {
|
||||
type: "cashier",
|
||||
operate_type: "order_print_status",
|
||||
table_code: printData.orderInfo.tableCode,
|
||||
account: userStore.shopInfo.account,
|
||||
print_status: "1",
|
||||
order_id: printData.orderInfo.id,
|
||||
print_id: printData.deviceId,
|
||||
shop_id: printData.orderInfo.shopId,
|
||||
};
|
||||
socketStore.ws.send(JSON.stringify(syncData));
|
||||
console.log("✅ 打印成功:", printData.deviceName, "菜品数:", printData.carts.length);
|
||||
} catch (error) {
|
||||
console.error("❌ 打印失败:", printData.deviceName, error);
|
||||
} finally {
|
||||
this.receiptList.splice(0, 1);
|
||||
}
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
console.log("打印定时器异常", error);
|
||||
}
|
||||
},
|
||||
|
||||
// ————————————————————————————————
|
||||
// 以下原有代码完全不动(除了printWork方法)
|
||||
// ————————————————————————————————
|
||||
checkLocalPrint(address) {
|
||||
let print = "";
|
||||
for (let item of this.localDevices) {
|
||||
@@ -88,17 +208,15 @@ export const usePrint = defineStore("print", {
|
||||
print = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (!print.name) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
// 打印标签小票
|
||||
|
||||
labelPrint(props) {
|
||||
const store = useUser();
|
||||
|
||||
if (
|
||||
this.deviceLableList.length &&
|
||||
this.checkLocalPrint(this.deviceLableList[0].address)
|
||||
@@ -106,7 +224,6 @@ export const usePrint = defineStore("print", {
|
||||
let pids = this.deviceLableList[0].categoryList;
|
||||
let count = 0;
|
||||
let sum = 0;
|
||||
|
||||
props.carts.map((item) => {
|
||||
if (pids.some((el) => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
@@ -114,7 +231,6 @@ export const usePrint = defineStore("print", {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
props.carts.map((item) => {
|
||||
if (pids.some((el) => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
@@ -133,17 +249,12 @@ export const usePrint = defineStore("print", {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log("this.labelList===", this.labelList);
|
||||
// return;
|
||||
|
||||
// 执行打印操作
|
||||
this.startLabelPrint();
|
||||
} else {
|
||||
console.log("标签打印:未在本机查询到打印机");
|
||||
}
|
||||
},
|
||||
// 开始打印标签数据
|
||||
|
||||
startLabelPrint() {
|
||||
if (this.printTimer != null) return;
|
||||
this.printTimer = setInterval(() => {
|
||||
@@ -161,88 +272,55 @@ export const usePrint = defineStore("print", {
|
||||
}
|
||||
}, 2000);
|
||||
},
|
||||
// 添加小票打印队列数据
|
||||
pushReceiptData(props, isDevice = true) {
|
||||
// console.log("pushReceiptData===", props);
|
||||
if (!isDevice) {
|
||||
// 测试打印,无需校验本地打印机
|
||||
this.receiptList.push(props);
|
||||
this.startReceiptPrint();
|
||||
} else {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address) &&
|
||||
this.isPrintService
|
||||
) {
|
||||
const store = useUser();
|
||||
props.deviceId = this.deviceNoteList[0].id;
|
||||
props.deviceName = this.deviceNoteList[0].address;
|
||||
props.shop_name = store.shopInfo.shopName;
|
||||
props.loginAccount = store.userInfo.name;
|
||||
props.createdAt = dayjs(props.createdAt).format(
|
||||
"YYYY-MM-DD HH:mm:ss"
|
||||
);
|
||||
props.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||
if (!props.orderInfo.masterId) {
|
||||
props.orderInfo.masterId = props.orderInfo.tableName;
|
||||
}
|
||||
props.orderInfo.outNumber = props.outNumber;
|
||||
if (!props.discountAmount) {
|
||||
props.discountAmount = props.amount;
|
||||
}
|
||||
|
||||
this.receiptList.push(props);
|
||||
this.startReceiptPrint();
|
||||
} else {
|
||||
console.log("订单小票:未在本机查询到打印机");
|
||||
}
|
||||
}
|
||||
},
|
||||
// 开始打印小票
|
||||
async startReceiptPrint() {
|
||||
try {
|
||||
const socketStore = useSocket();
|
||||
const userStore = useUser();
|
||||
|
||||
if (this.receiptTimer !== null) return;
|
||||
this.receiptTimer = setInterval(() => {
|
||||
if (!this.receiptList.length) {
|
||||
clearInterval(this.receiptTimer);
|
||||
this.receiptTimer = null;
|
||||
} else {
|
||||
receiptPrint(this.receiptList[0]);
|
||||
// 在这里触发已打印操作标记
|
||||
const data = {
|
||||
type: "cashier",
|
||||
operate_type: "order_print_status",
|
||||
table_code: this.receiptList[0].orderInfo.tableCode,
|
||||
account: userStore.shopInfo.account,
|
||||
print_status: "1",
|
||||
order_id: this.receiptList[0].orderInfo.id,
|
||||
print_id: this.receiptList[0].deviceId,
|
||||
shop_id: this.receiptList[0].orderInfo.shopId,
|
||||
}
|
||||
socketStore.ws.send(JSON.stringify(data));
|
||||
this.receiptList.splice(0, 1);
|
||||
}
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
// 打印交班小票
|
||||
// 打印交班小票(优化:1. 新增handoverSwitch=1才打印 2. 兼容局域网打印机)
|
||||
printWork(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||
) {
|
||||
data.deviceName = this.deviceNoteList[0].address;
|
||||
lodopPrintWork(data);
|
||||
} else {
|
||||
console.log("交班小票:未在本机查询到打印机");
|
||||
// 筛选条件:
|
||||
// 1. 状态启用 + 小票类型 + handoverSwitch=1
|
||||
// 2. 打印机可用
|
||||
// 3. 打印服务正常
|
||||
const validPrinters = this.deviceNoteList.filter(p => {
|
||||
return p.status
|
||||
&& p.subType === "cash"
|
||||
&& p.handoverSwitch === 1 // 新增:只有handoverSwitch为1的打印机才打印交班小票
|
||||
&& this.checkPrinterAvailable(p)
|
||||
&& this.isPrintService;
|
||||
});
|
||||
|
||||
if (validPrinters.length === 0) {
|
||||
console.log("交班小票:无符合条件的可用打印机(handoverSwitch≠1 或 打印机不可用)");
|
||||
return;
|
||||
}
|
||||
|
||||
// 遍历符合条件的打印机打印
|
||||
validPrinters.forEach(printer => {
|
||||
const printData = {
|
||||
...data,
|
||||
deviceId: printer.id,
|
||||
deviceName: printer.address,
|
||||
connectionType: printer.connectionType,
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
|
||||
try {
|
||||
// 区分局域网和USB打印机
|
||||
if (printer.connectionType === "局域网") {
|
||||
// 局域网打印机:使用networkPrint指令
|
||||
ipcRenderer.send('printHandoverReceipt', JSON.stringify({
|
||||
printerIp: printer.address,
|
||||
handoverData: printData
|
||||
}));
|
||||
} else {
|
||||
// USB打印机:使用原有LODOP方式
|
||||
lodopPrintWork(printData);
|
||||
}
|
||||
console.log("✅ 交班小票打印成功:", printer.address);
|
||||
} catch (error) {
|
||||
console.error("❌ 交班小票打印失败:", printer.address, error);
|
||||
}
|
||||
});
|
||||
},
|
||||
// 打印订单发票
|
||||
|
||||
printInvoice(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
@@ -254,17 +332,55 @@ export const usePrint = defineStore("print", {
|
||||
console.log("订单发票:未在本机查询到打印机");
|
||||
}
|
||||
},
|
||||
// 打印退单小票
|
||||
// 退菜/退款
|
||||
printRefund(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||
) {
|
||||
data.deviceName = this.deviceNoteList[0].address;
|
||||
refundPrint(data);
|
||||
} else {
|
||||
console.log("退单小票:未在本机查询到打印机");
|
||||
// 筛选条件:
|
||||
// 1. 状态启用 + 小票类型
|
||||
// 2. 打印机可用
|
||||
// 3. 打印服务正常
|
||||
const validPrinters = this.deviceNoteList.filter(p => {
|
||||
return p.status
|
||||
&& p.subType === "cash"
|
||||
&& this.checkPrinterAvailable(p)
|
||||
&& this.isPrintService;
|
||||
});
|
||||
|
||||
if (validPrinters.length === 0) {
|
||||
console.log("退单小票:无符合条件的可用打印机");
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
const store = useUser();
|
||||
// 遍历符合条件的打印机打印
|
||||
validPrinters.forEach(printer => {
|
||||
const printData = {
|
||||
...data,
|
||||
deviceId: printer.id,
|
||||
deviceName: printer.address,
|
||||
printerName: printer.name,
|
||||
connectionType: printer.connectionType,
|
||||
shop_name: store.shopInfo.shopName,
|
||||
loginAccount: store.userInfo.name,
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
|
||||
try {
|
||||
// 区分局域网和USB打印机
|
||||
if (printer.connectionType === "局域网") {
|
||||
// 局域网打印机:使用networkPrint指令
|
||||
ipcRenderer.send('printRefund', JSON.stringify({
|
||||
printerIp: printer.address,
|
||||
orderData: printData
|
||||
}));
|
||||
} else {
|
||||
// USB打印机:使用原有LODOP方式
|
||||
refundPrint(printData);
|
||||
}
|
||||
console.log("✅ 退单小票打印成功:", printer.address);
|
||||
} catch (error) {
|
||||
console.error("❌ 退单小票打印失败:", printer.address, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
270
src/store/print20260331.js
Normal file
270
src/store/print20260331.js
Normal file
@@ -0,0 +1,270 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { useUser } from "@/store/user.js";
|
||||
import dayjs from "dayjs";
|
||||
import receiptPrint from "@/components/lodop/receiptPrint.js";
|
||||
import lodopPrintWork from "@/components/lodop/lodopPrintWork.js";
|
||||
import invoicePrint from "@/components/lodop/invoicePrint.js";
|
||||
import refundPrint from "@/components/lodop/refundPrint.js";
|
||||
import { printerList } from "@/api/account.js";
|
||||
import { useSocket } from './socket.js';
|
||||
|
||||
export const usePrint = defineStore("print", {
|
||||
state: () => ({
|
||||
isPrintService: false, // 打印服务是否启动
|
||||
printServiceTimer: false, // 打印服务定时器
|
||||
printServiceTimerCount: 0, // 打印服务定时器计数
|
||||
printServiceTimerMaxCount: 10, // 打印服务定时器最大计数
|
||||
showPrintNotService: false, // 是否显示重启软件,
|
||||
localDevices: [], // 本地打印机列表
|
||||
deviceNoteList: [], // 添加的打印机
|
||||
deviceLableList: [], // 添加的打印机
|
||||
labelList: [], // 要打印的队列数据
|
||||
printTimer: null,
|
||||
receiptList: [], // 小票队列数据
|
||||
receiptTimer: null,
|
||||
}),
|
||||
actions: {
|
||||
// 获取本地打印机和已添加的可以用打印机列表
|
||||
async init() {
|
||||
// 获取本地打印机
|
||||
ipcRenderer.send("getPrintList");
|
||||
ipcRenderer.on("printList", (event, arg) => {
|
||||
this.localDevices = arg;
|
||||
});
|
||||
|
||||
try {
|
||||
// 获取已添加的打印机
|
||||
const res = await printerList();
|
||||
this.deviceNoteList = res.records.filter(
|
||||
(item) => item.status && item.subType == "cash"
|
||||
);
|
||||
this.deviceLableList = res.records.filter(
|
||||
(item) => item.status && item.subType == "label"
|
||||
);
|
||||
console.log("打印队列初始化成功", {
|
||||
deviceNoteList: this.deviceNoteList,
|
||||
deviceLableList: this.deviceLableList,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("获取已添加的打印机列表失败", error);
|
||||
}
|
||||
|
||||
// 检测打印服务是否启动
|
||||
this.checkPrintService();
|
||||
},
|
||||
// 检测打印组件服务是否启动
|
||||
checkPrintService() {
|
||||
this.printServiceTimer = setInterval(() => {
|
||||
if (
|
||||
typeof LODOP !== "undefined" &&
|
||||
LODOP.webskt &&
|
||||
LODOP.webskt.readyState == 1
|
||||
) {
|
||||
// 准备好
|
||||
this.isPrintService = true;
|
||||
clearInterval(this.printServiceTimer);
|
||||
this.printServiceTimer = null;
|
||||
} else {
|
||||
this.printServiceTimerCount++;
|
||||
console.log("打印服务未启动", this.printServiceTimerCount);
|
||||
|
||||
if (this.printServiceTimerCount >= this.printServiceTimerMaxCount) {
|
||||
// 超过最大次数
|
||||
this.isPrintService = false;
|
||||
this.showPrintNotService = true;
|
||||
clearInterval(this.printServiceTimer);
|
||||
this.printServiceTimer = null;
|
||||
}
|
||||
}
|
||||
console.log("打印服务是否启动:", this.isPrintService);
|
||||
}, 1000);
|
||||
},
|
||||
// 检查本地打印机是否能正常使用
|
||||
checkLocalPrint(address) {
|
||||
let print = "";
|
||||
for (let item of this.localDevices) {
|
||||
if (item.name == address) {
|
||||
print = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (!print.name) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
// 打印标签小票
|
||||
labelPrint(props) {
|
||||
const store = useUser();
|
||||
|
||||
if (
|
||||
this.deviceLableList.length &&
|
||||
this.checkLocalPrint(this.deviceLableList[0].address)
|
||||
) {
|
||||
let pids = this.deviceLableList[0].categoryList;
|
||||
let count = 0;
|
||||
let sum = 0;
|
||||
|
||||
props.carts.map((item) => {
|
||||
if (pids.some((el) => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
props.carts.map((item) => {
|
||||
if (pids.some((el) => el == item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
count++;
|
||||
this.labelList.push({
|
||||
outNumber: props.outNumber,
|
||||
name: item.name,
|
||||
skuName: item.skuName,
|
||||
masterId: props.orderInfo.tableName,
|
||||
deviceName: this.deviceLableList[0].address,
|
||||
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
||||
isPrint: false,
|
||||
count: `${count}/${sum}`,
|
||||
ticketLogo: store.shopInfo.ticketLogo,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log("this.labelList===", this.labelList);
|
||||
// return;
|
||||
|
||||
// 执行打印操作
|
||||
this.startLabelPrint();
|
||||
} else {
|
||||
console.log("标签打印:未在本机查询到打印机");
|
||||
}
|
||||
},
|
||||
// 开始打印标签数据
|
||||
startLabelPrint() {
|
||||
if (this.printTimer != null) return;
|
||||
this.printTimer = setInterval(() => {
|
||||
let item = "";
|
||||
if (!this.labelList.length) {
|
||||
clearInterval(this.printTimer);
|
||||
this.printTimer = null;
|
||||
} else {
|
||||
item = this.labelList[0];
|
||||
if (!item.isPrint) {
|
||||
ipcRenderer.send("printerTagSync", JSON.stringify(item));
|
||||
this.labelList[0].isPrint = true;
|
||||
this.labelList.splice(0, 1);
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
},
|
||||
// 添加小票打印队列数据
|
||||
pushReceiptData(props, isDevice = true) {
|
||||
// console.log("pushReceiptData===", props);
|
||||
if (!isDevice) {
|
||||
// 测试打印,无需校验本地打印机
|
||||
this.receiptList.push(props);
|
||||
this.startReceiptPrint();
|
||||
} else {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address) &&
|
||||
this.isPrintService
|
||||
) {
|
||||
const store = useUser();
|
||||
props.deviceId = this.deviceNoteList[0].id;
|
||||
props.deviceName = this.deviceNoteList[0].address;
|
||||
props.shop_name = store.shopInfo.shopName;
|
||||
props.loginAccount = store.userInfo.name;
|
||||
props.createdAt = dayjs(props.createdAt).format(
|
||||
"YYYY-MM-DD HH:mm:ss"
|
||||
);
|
||||
props.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||
if (!props.orderInfo.masterId) {
|
||||
props.orderInfo.masterId = props.orderInfo.tableName;
|
||||
}
|
||||
props.orderInfo.outNumber = props.outNumber;
|
||||
if (!props.discountAmount) {
|
||||
props.discountAmount = props.amount;
|
||||
}
|
||||
|
||||
this.receiptList.push(props);
|
||||
this.startReceiptPrint();
|
||||
} else {
|
||||
console.log("订单小票:未在本机查询到打印机");
|
||||
}
|
||||
}
|
||||
},
|
||||
// 开始打印小票
|
||||
async startReceiptPrint() {
|
||||
try {
|
||||
const socketStore = useSocket();
|
||||
const userStore = useUser();
|
||||
|
||||
if (this.receiptTimer !== null) return;
|
||||
this.receiptTimer = setInterval(() => {
|
||||
if (!this.receiptList.length) {
|
||||
clearInterval(this.receiptTimer);
|
||||
this.receiptTimer = null;
|
||||
} else {
|
||||
receiptPrint(this.receiptList[0]);
|
||||
// 在这里触发已打印操作标记
|
||||
const data = {
|
||||
type: "cashier",
|
||||
operate_type: "order_print_status",
|
||||
table_code: this.receiptList[0].orderInfo.tableCode,
|
||||
account: userStore.shopInfo.account,
|
||||
print_status: "1",
|
||||
order_id: this.receiptList[0].orderInfo.id,
|
||||
print_id: this.receiptList[0].deviceId,
|
||||
shop_id: this.receiptList[0].orderInfo.shopId,
|
||||
}
|
||||
socketStore.ws.send(JSON.stringify(data));
|
||||
this.receiptList.splice(0, 1);
|
||||
}
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
// 打印交班小票
|
||||
printWork(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||
) {
|
||||
data.deviceName = this.deviceNoteList[0].address;
|
||||
lodopPrintWork(data);
|
||||
} else {
|
||||
console.log("交班小票:未在本机查询到打印机");
|
||||
}
|
||||
},
|
||||
// 打印订单发票
|
||||
printInvoice(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||
) {
|
||||
data.deviceName = this.deviceNoteList[0].address;
|
||||
invoicePrint(data);
|
||||
} else {
|
||||
console.log("订单发票:未在本机查询到打印机");
|
||||
}
|
||||
},
|
||||
// 打印退单小票
|
||||
printRefund(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||
) {
|
||||
data.deviceName = this.deviceNoteList[0].address;
|
||||
refundPrint(data);
|
||||
} else {
|
||||
console.log("退单小票:未在本机查询到打印机");
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -159,7 +159,9 @@ export async function getOrderByIdAjax(orderId) {
|
||||
export function commOrderPrintData(orderInfo) {
|
||||
const userStore = useUser();
|
||||
let data = {
|
||||
title: orderInfo.title,
|
||||
isBefore: orderInfo.isBefore || false,
|
||||
isGuest: orderInfo.isGuest || false,
|
||||
shop_name: userStore.shopInfo.shopName,
|
||||
loginAccount: userStore.userInfo.name,
|
||||
carts: [],
|
||||
@@ -179,23 +181,38 @@ export function commOrderPrintData(orderInfo) {
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
|
||||
orderInfo.cartList.map((item) => {
|
||||
data.carts.push({
|
||||
categoryId: item.categoryId,
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.price),
|
||||
totalAmount: formatDecimal(+item.payAmount),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
: "",
|
||||
if (orderInfo.isGuest) {
|
||||
// 如果是客看单,只展示当前下单的菜品
|
||||
orderInfo.detailMap[0].map((item) => {
|
||||
data.carts.push({
|
||||
categoryId: item.categoryId,
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.price),
|
||||
totalAmount: formatDecimal(+item.payAmount),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
: "",
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
orderInfo.cartList.map((item) => {
|
||||
data.carts.push({
|
||||
categoryId: item.categoryId,
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.price),
|
||||
totalAmount: formatDecimal(+item.payAmount),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
: "",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (orderInfo.seatAmount > 0) {
|
||||
console.log('有餐位费', orderInfo.seatAmount);
|
||||
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '餐位费',
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
<el-form-item label="设备名称">
|
||||
<el-input v-model="form.name" placeholder="请输入设备名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备类型">
|
||||
<el-radio-group v-model="form.connectionType">
|
||||
<el-radio-button label="USB" value="USB"></el-radio-button>
|
||||
<el-radio-button label="局域网" value="局域网"></el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="打印机品牌">
|
||||
<el-input v-model="form.contentType" placeholder="请输入打印机品牌"></el-input>
|
||||
</el-form-item> -->
|
||||
@@ -21,17 +27,30 @@
|
||||
<el-option label="80mm" value="80mm"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备类型">
|
||||
<el-select v-model="form.connectionType">
|
||||
<el-option label="USB" value="USB"></el-option>
|
||||
<!-- <el-option label="网络" value="network"></el-option> -->
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="选择设备">
|
||||
<el-form-item label="选择设备" v-if="form.connectionType === 'USB'">
|
||||
<el-select v-model="form.address">
|
||||
<el-option :label="item.name" :value="item.name" v-for="item in printList" :key="item.name"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备IP" v-if="form.connectionType === '局域网'">
|
||||
<el-input v-model="form.address" placeholder="请输入设备IP地址"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品分类">
|
||||
<div style="cursor: pointer" @click="classifyRef.show()">
|
||||
<span style="color: #409eff" v-if="form.categoryList.length">
|
||||
{{form.categoryList.map(item => item.name).join(',')}}
|
||||
</span>
|
||||
<span style="color: #e65d6e" v-else>
|
||||
请选择分类
|
||||
</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否打印交班小票">
|
||||
<el-radio-group v-model="form.handoverSwitch">
|
||||
<el-radio-button label="否" :value="0"></el-radio-button>
|
||||
<el-radio-button label="是" :value="1"></el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="打印份数">
|
||||
<el-select v-model="form.printQty">
|
||||
<el-option :label="item" :value="item" v-for="item in 4" :key="item"></el-option>
|
||||
@@ -125,6 +144,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<classify ref="classifyRef" @success="(e) => (form.categoryList = e)" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -136,6 +156,11 @@ import { ElMessage } from "element-plus";
|
||||
import { useUser } from "@/store/user.js";
|
||||
import { usePrint } from "@/store/print.js";
|
||||
import { printerAdd, printerDetail } from "@/api/account.js";
|
||||
import classify from "@/components/classify/index.vue";
|
||||
import { useGoods } from '@/store/goods.js'
|
||||
const goodsStore = useGoods()
|
||||
|
||||
const classifyRef = ref(null);
|
||||
|
||||
const printStore = usePrint();
|
||||
const store = useUser();
|
||||
@@ -150,7 +175,7 @@ const requestLoading = ref(false);
|
||||
const form = ref({
|
||||
id: "",
|
||||
name: '', // 设备名称
|
||||
connectionType: 'USB', // 现在打印机支持USB 和 网络、蓝牙
|
||||
connectionType: 'USB', // 现在打印机支持USB 和 网络、蓝牙、局域网
|
||||
address: '', // 打印机名称
|
||||
port: '', // 端口
|
||||
subType: 'cash', // 打印类型(分类)label标签cash小票kitchen出品
|
||||
@@ -163,7 +188,8 @@ const form = ref({
|
||||
printQty: '', // 打印数量 c1m1^2 = 顾客+商家[2张] m1^1 = 商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
||||
printMethod: 'all', // 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」queue-仅打印排队取号
|
||||
printType: [], // 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||
status: 1
|
||||
status: 1,
|
||||
handoverSwitch: 0, // 交班单开关 0-关闭 1-开启
|
||||
});
|
||||
|
||||
const printDataLoading = ref(false);
|
||||
@@ -210,16 +236,29 @@ function getPrintList() {
|
||||
|
||||
// 测试打印
|
||||
function printHandle() {
|
||||
if (!form.value.address) {
|
||||
if (form.value.connectionType === 'USB' && !form.value.address) {
|
||||
ElMessage.error("请选择打印设备");
|
||||
return;
|
||||
}
|
||||
if (form.value.connectionType === '局域网' && !form.value.address) {
|
||||
ElMessage.error("请输入设备IP地址");
|
||||
return;
|
||||
}
|
||||
|
||||
printDataLoading.value = true;
|
||||
printData.shop_name = store.shopInfo.shopName
|
||||
printData.loginAccount = store.userInfo.name
|
||||
printData.deviceName = form.value.address;
|
||||
printData.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||
printStore.pushReceiptData(printData, false);
|
||||
|
||||
if (form.value.connectionType === 'USB') {
|
||||
printStore.pushReceiptData(printData, false);
|
||||
} else if (form.value.connectionType === '局域网') {
|
||||
ipcRenderer.send('networkPrint', JSON.stringify({
|
||||
printerIp: form.value.address,
|
||||
orderData: printData
|
||||
}))
|
||||
}
|
||||
setTimeout(() => {
|
||||
printDataLoading.value = false;
|
||||
}, 2500);
|
||||
@@ -232,11 +271,16 @@ async function submitHandle() {
|
||||
ElMessage.error("请输入设备名称");
|
||||
return;
|
||||
}
|
||||
if (!form.value.address) {
|
||||
if (form.value.connectionType === 'USB' && !form.value.address) {
|
||||
ElMessage.error("请选择打印设备");
|
||||
return;
|
||||
}
|
||||
if (form.value.connectionType === '局域网' && !form.value.address) {
|
||||
ElMessage.error("请输入设备IP地址");
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
form.value.categoryIds = form.value.categoryList.map(item => item.id)
|
||||
await printerAdd(form.value, form.value.id ? "put" : "post");
|
||||
ElMessage.success(form.value.id ? "编辑成功" : "添加成功");
|
||||
printStore.init();
|
||||
@@ -253,6 +297,19 @@ async function tbPrintMachineDetailAjax(id) {
|
||||
requestLoading.value = true;
|
||||
const res = await printerDetail({ id: id });
|
||||
form.value = res;
|
||||
|
||||
let arr = []
|
||||
goodsStore.originCategoryList.map(item => {
|
||||
res.categoryList.map(val => {
|
||||
if (item.id == val) {
|
||||
arr.push({
|
||||
id: item.id,
|
||||
name: item.name
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
form.value.categoryList = arr
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
@@ -251,18 +251,21 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import _ from 'lodash'
|
||||
import { ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import takeFoodCode from '@/components/takeFoodCode.vue'
|
||||
import TableMerging from './tableMerging.vue'
|
||||
import skuModal from '@/components/skuModal.vue'
|
||||
import { useGoods } from '@/store/goods.js'
|
||||
import { inputFilterFloat, formatDecimal } from '@/utils/index.js'
|
||||
import { inputFilterFloat, formatDecimal, getOrderByIdAjax, commOrderPrintData } from '@/utils/index.js'
|
||||
import { refundOrder } from '@/api/order.js'
|
||||
import { useSocket } from '@/store/socket.js'
|
||||
import { usePrint } from '@/store/print.js'
|
||||
|
||||
const goodsStore = useGoods()
|
||||
const socket = useSocket()
|
||||
const printStore = usePrint()
|
||||
|
||||
const tableMergingRef = ref(null)
|
||||
|
||||
@@ -339,6 +342,25 @@ async function returnOrderItemAjax(num = 1) {
|
||||
await refundOrder(data)
|
||||
goodsStore.cartOrderItem.returnNum += num
|
||||
goodsStore.calcCartInfo()
|
||||
|
||||
getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
|
||||
let originOrderInfo = res
|
||||
console.log('originOrderInfo1===', originOrderInfo);
|
||||
|
||||
console.log('goodsStore.cartOrderItem.id', goodsStore.cartOrderItem.id);
|
||||
|
||||
let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
|
||||
|
||||
console.log('index===', index);
|
||||
|
||||
originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
|
||||
console.log('originOrderInfo2===', originOrderInfo);
|
||||
// return
|
||||
|
||||
printStore.printRefund(commOrderPrintData({ ...originOrderInfo, isGuest: false, isBefore: false, title: '退菜单' }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
// await goodsStore.historyOrderAjax('', data.orderId)
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -212,6 +212,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import _ from 'lodash'
|
||||
import { ref } from "vue";
|
||||
import { useGlobal } from '@/store/global.js'
|
||||
import SelectVipUser from "@/components/selectVipUser.vue";
|
||||
@@ -224,7 +225,7 @@ import fastCashier from "@/views/home/components/fastCashier.vue";
|
||||
import pendingCartModal from "@/views/home/components/pendingCartModal.vue";
|
||||
import tableMerging from '@/views/home/components/tableMerging.vue'
|
||||
import CartItem from './components/cartItem.vue'
|
||||
import { formatDecimal, formatPhoneNumber } from '@/utils/index.js'
|
||||
import { formatDecimal, formatPhoneNumber, getOrderByIdAjax, commOrderPrintData } from '@/utils/index.js'
|
||||
import { useGoods } from '@/store/goods.js'
|
||||
import { staffPermission } from '@/api/user.js'
|
||||
import { createOrder } from '@/api/order.js'
|
||||
@@ -299,6 +300,7 @@ async function quickCashHandle() {
|
||||
// 生成订单 t=0 先下单后结算 t=1直接结算
|
||||
async function createOrderHandle(t = 0) {
|
||||
try {
|
||||
let placeNum = goodsStore.orderListInfo.placeNum || 0
|
||||
if (goodsStore.cartList.length) {
|
||||
const data = {
|
||||
orderId: goodsStore.orderListInfo.id || '', // 订单id
|
||||
@@ -309,7 +311,7 @@ async function createOrderHandle(t = 0) {
|
||||
tableCode: goodsStore.cartList[0].table_code, // 台桌号
|
||||
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||
remark: remark.value, // 备注
|
||||
placeNum: (goodsStore.orderListInfo.placeNum || 0) + 1, // 下单次数
|
||||
placeNum: placeNum + 1, // 下单次数
|
||||
waitCall: 0, // 是否叫号
|
||||
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||
limitRate: goodsStore.limitDiscountRes
|
||||
@@ -328,6 +330,17 @@ async function createOrderHandle(t = 0) {
|
||||
settleAccountRef.value.show(t)
|
||||
} else {
|
||||
goodsStore.clearCart()
|
||||
// 开始打印客看单,可看单需要剔除其他历史下单
|
||||
getOrderByIdAjax(res.id).then(res => {
|
||||
let originOrderInfo = res
|
||||
originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum + 1);
|
||||
|
||||
console.log('originOrderInfo', originOrderInfo);
|
||||
|
||||
printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: true }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
// 清除购物车,更新历史订单
|
||||
goodsStore.updateOrderList()
|
||||
|
||||
@@ -26,8 +26,9 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog> -->
|
||||
<el-input v-model="authCode" placeholder="请扫描支付码"></el-input>
|
||||
<el-button type="primary" @click="microPayAjax">反扫支付</el-button>
|
||||
<!-- <el-input v-model="authCode" placeholder="请扫描支付码"></el-input>
|
||||
<el-button type="primary" @click="microPayAjax">反扫支付</el-button> -->
|
||||
<el-button type="primary" @click="printReceipt">调用本地网络打印机</el-button>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -47,6 +48,26 @@ const tempFilePath = ref('')
|
||||
|
||||
const authCode = ref('')
|
||||
|
||||
function printReceipt() {
|
||||
let data = {
|
||||
printerIp: '192.168.1.53',
|
||||
orderData: {
|
||||
orderNo: '20260327008',
|
||||
shopName: '川味小馆',
|
||||
createTime: new Date().toLocaleString(),
|
||||
products: [
|
||||
{ name: '回锅肉', price: '32.00', num: 1 },
|
||||
{ name: '米饭', price: '2.00', num: 2 },
|
||||
{ name: '紫菜蛋花汤', price: '8.00', num: 1 }
|
||||
],
|
||||
total: '42.00',
|
||||
payType: '支付宝',
|
||||
remark: '微辣'
|
||||
}
|
||||
}
|
||||
ipcRenderer.send('portPrint', JSON.stringify(data))
|
||||
}
|
||||
|
||||
// 检查版本更新
|
||||
async function findVersionAjax() {
|
||||
try {
|
||||
|
||||
303
src/views/member/components/StoreWineManagement.vue
Normal file
303
src/views/member/components/StoreWineManagement.vue
Normal file
@@ -0,0 +1,303 @@
|
||||
<template>
|
||||
<el-drawer v-model="drawerVisible" size="100%" :with-header="false" direction="btt">
|
||||
<div class="drawer_wrap">
|
||||
<div class="header">
|
||||
<div class="left">
|
||||
<div class="return" @click="drawerVisible = false">
|
||||
<el-icon size="26" color="#555">
|
||||
<Back />
|
||||
</el-icon>
|
||||
</div>
|
||||
<div class="user_info">
|
||||
<el-image :src="userInfo.headImg" fit="cover"
|
||||
style="width: 40px; height: 40px; border-radius: 50%;background-color: #efefef;">
|
||||
<template #error>
|
||||
<el-icon style="font-size: 40px; color: #ccc;">
|
||||
<user />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-image>
|
||||
<el-text>{{ userInfo.nickName }}/{{ userInfo.phone }}</el-text>
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
<!-- <el-button type="danger" @click="dialogVisible = true">取酒</el-button> -->
|
||||
<el-button type="primary" @click="dialogVisible = true">新增存酒</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pay_wrap">
|
||||
<div class="tab">
|
||||
<el-table :data="list" height="100%" border stripe>
|
||||
<el-table-column label="记录" prop="name"></el-table-column>
|
||||
<el-table-column label="数量" prop="num"></el-table-column>
|
||||
<el-table-column label="操作时间" prop="expTime"></el-table-column>
|
||||
<el-table-column label="操作" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-button type="danger" :disabled="row.num <= 0"
|
||||
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">取酒</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-drawer>
|
||||
<el-dialog v-model="dialogVisible" title="新增存酒" width="350px" :close-on-click-modal="false" destroy-on-close>
|
||||
<el-form :model="form" :rules="rules" label-width="100px" label-position="left">
|
||||
<el-form-item label="选择酒品">
|
||||
<el-select v-model="form.shopStorageGoodId" placeholder="请选择存酒商品" style="width: 180px;">
|
||||
<el-option v-for="item in storageGoodList" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="存酒数量">
|
||||
<el-input-number v-model="form.num" :min="1"></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item label="存酒有效期">
|
||||
<el-input-number v-model="form.expDay" :min="1"></el-input-number>
|
||||
<span style="margin-left: 8px;">天</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="dialog-footer">
|
||||
<div class="btn">
|
||||
<el-button style="width: 100%;" @click="dialogVisible = false">取 消</el-button>
|
||||
</div>
|
||||
<div class="btn">
|
||||
<el-button style="width: 100%;" type="primary" :loading="confirmLoading" @click="confirmHandle">确
|
||||
定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!-- 取酒对话框,只选择数量即可,不可超过存酒的数量 -->
|
||||
<el-dialog v-model="takeWineDialogVisible" title="取酒" width="350px" :close-on-click-modal="false" destroy-on-close>
|
||||
<el-form :model="takeWineForm" :rules="takeWineRules" label-width="100px" label-position="left">
|
||||
<el-form-item label="取酒数量">
|
||||
<el-input-number v-model="takeWineForm.num" :min="1" :max="maxTakeNum"></el-input-number>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="dialog-footer">
|
||||
<div class="btn">
|
||||
<el-button style="width: 100%;" @click="takeWineDialogVisible = false">取 消</el-button>
|
||||
</div>
|
||||
<div class="btn">
|
||||
<el-button style="width: 100%;" type="primary" :loading="takeWineConfirmLoading"
|
||||
@click="confirmTakeWineHandle">确 定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut } from '@/api/product_new'
|
||||
|
||||
const props = defineProps({
|
||||
userInfo: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
}
|
||||
})
|
||||
|
||||
const drawerVisible = ref(false);
|
||||
const dialogVisible = ref(false);
|
||||
|
||||
const list = ref([]);
|
||||
|
||||
// 获取存酒记录
|
||||
async function shopStorageGetAjax() {
|
||||
try {
|
||||
const res = await shopStorageGet({
|
||||
key: '',
|
||||
phone: props.userInfo.phone,
|
||||
page: 1,
|
||||
size: 999,
|
||||
});
|
||||
list.value = res.records || [];
|
||||
} catch (error) {
|
||||
console.error('获取存酒列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
const form = ref({
|
||||
userId: '',
|
||||
shopStorageGoodId: '', // 存酒商品ID
|
||||
num: 1, // 存酒数量
|
||||
expDay: 1, // 存酒有效期,单位天默认1天
|
||||
})
|
||||
|
||||
const rules = {
|
||||
shopStorageGoodId: [{ required: true, message: '请选择存酒商品', trigger: 'change' }],
|
||||
num: [{ required: true, message: '请输入存酒数量', trigger: 'change' }],
|
||||
expDay: [{ required: true, message: '请输入存酒有效期', trigger: 'change' }],
|
||||
}
|
||||
|
||||
// 确认存酒
|
||||
const confirmLoading = ref(false);
|
||||
async function confirmHandle() {
|
||||
try {
|
||||
confirmLoading.value = true;
|
||||
form.value.userId = props.userInfo.userId;
|
||||
await shopStoragePost(form.value);
|
||||
ElMessage.success('存酒成功');
|
||||
dialogVisible.value = false;
|
||||
shopStorageGetAjax(); // 刷新存酒商品列表
|
||||
} catch (error) {
|
||||
console.error('存酒失败:', error);
|
||||
} finally {
|
||||
confirmLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取存酒商品列表
|
||||
const storageGoodList = ref([]);
|
||||
async function storageGoodGetAjax() {
|
||||
try {
|
||||
const res = await storageGoodGet({
|
||||
page: 1,
|
||||
size: 999,
|
||||
});
|
||||
storageGoodList.value = res.records || [];
|
||||
} catch (error) {
|
||||
console.error('获取存酒商品列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
const takeWineDialogVisible = ref(false);
|
||||
const takeWineForm = ref({
|
||||
id: '', // 存酒记录ID
|
||||
num: 1,
|
||||
})
|
||||
const takeWineRules = {
|
||||
num: [{ required: true, message: '请输入取酒数量', trigger: 'change' }],
|
||||
}
|
||||
const maxTakeNum = ref(1);
|
||||
const takeWineConfirmLoading = ref(false);
|
||||
|
||||
function confirmTakeWineHandle() {
|
||||
shopStoragePutAjax();
|
||||
}
|
||||
|
||||
// 存酒取酒 num 必需 正数为存酒反之为取酒
|
||||
async function shopStoragePutAjax() {
|
||||
try {
|
||||
takeWineConfirmLoading.value = true;
|
||||
await shopStoragePut({
|
||||
id: takeWineForm.value.id,
|
||||
num: -takeWineForm.value.num, // 取酒数量为负数
|
||||
});
|
||||
ElMessage.success('取酒成功');
|
||||
takeWineDialogVisible.value = false;
|
||||
shopStorageGetAjax(); // 刷新存酒记录列表
|
||||
} catch (error) {
|
||||
console.error('取酒失败:', error);
|
||||
} finally {
|
||||
takeWineConfirmLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
drawerVisible.value = false;
|
||||
dialogVisible.value = false;
|
||||
takeWineDialogVisible.value = false;
|
||||
form.value = {
|
||||
userId: '',
|
||||
shopStorageGoodId: '',
|
||||
num: 1,
|
||||
expDay: 1,
|
||||
};
|
||||
takeWineForm.value = {
|
||||
id: '',
|
||||
num: 1,
|
||||
};
|
||||
maxTakeNum.value = 1;
|
||||
list.value = [];
|
||||
}
|
||||
|
||||
function show() {
|
||||
init();
|
||||
drawerVisible.value = true;
|
||||
// 刷新列表数据
|
||||
storageGoodGetAjax();
|
||||
shopStorageGetAjax();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
show,
|
||||
init,
|
||||
});
|
||||
|
||||
// 初始化
|
||||
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
storageGoodGetAjax();
|
||||
shopStorageGetAjax();
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.drawer_wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
padding: var(--el-font-size-base) 0;
|
||||
flex-direction: column;
|
||||
gap: var(--el-font-size-base);
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 var(--el-font-size-base);
|
||||
background-color: #fff;
|
||||
padding: var(--el-font-size-base);
|
||||
border-radius: var(--el-font-size-base);
|
||||
|
||||
.left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--el-font-size-base);
|
||||
|
||||
.return {
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: background-color 0.3s;
|
||||
padding: 10px 8px 4px;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.user_info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--el-font-size-base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pay_wrap {
|
||||
flex: 1;
|
||||
background: #fff;
|
||||
border-radius: var(--el-font-size-base);
|
||||
|
||||
.tab {
|
||||
height: 100%;
|
||||
padding: var(--el-font-size-base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: var(--el-font-size-base);
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -99,6 +99,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn_wrap">
|
||||
<div class="btn">
|
||||
<el-button type="success" style="width: 100%;" @click="StoreWineManagementRef.show()">存酒管理</el-button>
|
||||
</div>
|
||||
<div class="btn">
|
||||
<el-button type="warning" style="width: 100%;" @click="UserChargeRef.show()">账户充值</el-button>
|
||||
</div>
|
||||
@@ -114,6 +117,8 @@
|
||||
<RecordDialog ref="RecordDialogRef" @refund="getUserList" />
|
||||
<!-- 添加会员 -->
|
||||
<AddUserDrawer ref="AddUserDrawerRef" @success="queryHandle" />
|
||||
<!-- 存酒管理 -->
|
||||
<StoreWineManagement ref="StoreWineManagementRef" :user-info="currentRow" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -123,10 +128,12 @@ import { shopUserList } from '@/api/account.js'
|
||||
import UserCharge from './components/userCharge.vue'
|
||||
import RecordDialog from './components/recordDialog.vue'
|
||||
import AddUserDrawer from './components/addUserDrawer.vue'
|
||||
import StoreWineManagement from './components/storeWineManagement.vue'
|
||||
|
||||
const UserChargeRef = ref(null)
|
||||
const RecordDialogRef = ref(null)
|
||||
const AddUserDrawerRef = ref(null)
|
||||
const StoreWineManagementRef = ref(null)
|
||||
|
||||
const queryForm = ref({
|
||||
key: '',
|
||||
|
||||
@@ -260,6 +260,7 @@ async function printRefund(rows) {
|
||||
if (printStore.deviceNoteList.length) {
|
||||
// 本地打印
|
||||
const data = {
|
||||
title: '退款单',
|
||||
shop_name: store.shopInfo.shopName,
|
||||
loginAccount: store.userInfo.name,
|
||||
carts: [],
|
||||
@@ -268,6 +269,7 @@ async function printRefund(rows) {
|
||||
orderInfo: item.value,
|
||||
outNumber: item.value.id,
|
||||
createdAt: item.value.createTime,
|
||||
refundMethod: cash.value ? '现金' : '原路退回',
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
}
|
||||
|
||||
|
||||
@@ -179,8 +179,16 @@ const exit = async () => {
|
||||
if (loading.value) return
|
||||
loading.value = true;
|
||||
// await staffPermission('yun_xu_jiao_ban')
|
||||
const res = await handover(isPrint.value)
|
||||
const data = await handoverData(res)
|
||||
|
||||
// const res = await handover(isPrint.value)
|
||||
// const data = await handoverData(res)
|
||||
|
||||
const res = '136'
|
||||
const data = { "accountType": "merchant", "alipayAmount": 0, "cashAmount": 38.5, "categoryDataList": [{ "amount": 8.7, "categoryId": "614", "categoryName": "主食", "num": 3, "quantity": 1 }, { "amount": 29.8, "categoryId": "615", "categoryName": "炒菜", "num": 5, "quantity": 4 }], "creditAmount": 0, "handAmount": 38.5, "handoverTime": "2026-04-02 18:19:45", "id": "136", "loginTime": "2026-04-02 18:17:57", "orderCount": 1, "productDataList": [{ "amount": 8.7, "num": 3, "productId": "4037", "productName": "金镶白玉板", "skuId": "6727", "skuName": "" }, { "amount": 8.8, "num": 1, "productId": "4039", "productName": "雪底红梅", "skuId": "6729", "skuName": "" }, { "amount": 1.2, "num": 1, "productId": "4045", "productName": "清蒸鲈鱼", "skuId": "6738", "skuName": "微辣,中度酸" }, { "amount": 2, "num": 1, "productId": "4046", "productName": "四喜丸子", "skuId": "6741", "skuName": "" }, { "amount": 17.8, "num": 2, "productId": "4295", "productName": "小烤串", "skuId": "6990", "skuName": "" }], "quickInAmount": 0, "refundAmount": 0, "shopId": "151", "shopName": "高歌的小店", "staffId": "151", "staffName": "高歌的小店", "vipPay": 0, "vipRecharge": 0, "wechatAmount": 0 }
|
||||
|
||||
// console.log('res===', JSON.stringify(res));
|
||||
// console.log('data===', JSON.stringify(data));
|
||||
|
||||
if (printStore.deviceNoteList.length) {
|
||||
// 使用本地打印机 打印交班数据
|
||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
@@ -190,7 +198,8 @@ const exit = async () => {
|
||||
// 使用云打印机 打印交班数据
|
||||
await handoverNetworkPrint(data.id)
|
||||
}
|
||||
logoutHandle()
|
||||
// logoutHandle()
|
||||
loading.value = false;
|
||||
} catch (error) {
|
||||
loading.value = false;
|
||||
console.log(error);
|
||||
|
||||
Reference in New Issue
Block a user