优化最新版打印机逻辑
This commit is contained in:
File diff suppressed because one or more lines are too long
145
electron/main.js
145
electron/main.js
@@ -5,7 +5,7 @@ import axios from "axios";
|
||||
import os from "os";
|
||||
import fs from "fs";
|
||||
import { exec } from "child_process";
|
||||
import { printReceipt, printHandoverReceipt, printRefund,printRefundDish } from "./printService";
|
||||
import { ORDER, printHandoverReceipt, REFUND_ORDER, RETURN_ORDER, STOCK_CHECK, PRODUCT_REPORT, RECHARGE, STOCK, CALL, REFUND_KITCHEN, ONLY_KITCHEN, DAY_REPORT, ALL_KITCHEN, DAY_ORDER } from "./printService";
|
||||
|
||||
// ===== 核心配置:单文件缓存 =====
|
||||
// 固定的缓存文件路径(永远只存这1个文件)
|
||||
@@ -108,12 +108,12 @@ app.whenReady().then(() => {
|
||||
});
|
||||
|
||||
// 打印结算小票
|
||||
ipcMain.on('networkPrint', async (event, arg) => {
|
||||
ipcMain.on('ORDER', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
console.log(_parmas);
|
||||
console.log(_parmas.orderData.carts);
|
||||
await printReceipt(_parmas.printerIp, _parmas.orderData);
|
||||
// console.log(_parmas);
|
||||
// console.log(_parmas.orderData.carts);
|
||||
await ORDER(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -135,11 +135,11 @@ app.whenReady().then(() => {
|
||||
});
|
||||
|
||||
// 打印退款小票
|
||||
ipcMain.on('printRefund', async (event, arg) => {
|
||||
ipcMain.on('REFUND_ORDER', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await printRefund(_parmas.printerIp, _parmas.orderData);
|
||||
await REFUND_ORDER(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -148,11 +148,138 @@ app.whenReady().then(() => {
|
||||
});
|
||||
|
||||
// 打印退菜单
|
||||
ipcMain.on('printRefundDish', async (event, arg) => {
|
||||
ipcMain.on('RETURN_ORDER', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await printRefundDish(_parmas.printerIp, _parmas.orderData);
|
||||
await RETURN_ORDER(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 后厨退餐单 REFUND_KITCHEN
|
||||
ipcMain.on('REFUND_KITCHEN', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await REFUND_KITCHEN(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 后厨退餐单一菜一品 ONLY_KITCHEN
|
||||
ipcMain.on('ONLY_KITCHEN', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await ONLY_KITCHEN(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 后厨整单
|
||||
ipcMain.on('ALL_KITCHEN', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await ALL_KITCHEN(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印盘点单
|
||||
ipcMain.on('STOCK_CHECK', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await STOCK_CHECK(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印经营日报
|
||||
ipcMain.on('DAY_REPORT', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await DAY_REPORT(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印日结单
|
||||
ipcMain.on('DAY_ORDER', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await DAY_ORDER(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印排队取号单
|
||||
ipcMain.on('CALL', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
// console.log(_parmas);
|
||||
await CALL(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印商品销售数据
|
||||
ipcMain.on('PRODUCT_REPORT', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
await PRODUCT_REPORT(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印储值单
|
||||
ipcMain.on('RECHARGE', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
await RECHARGE(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return { ok: false, msg: e.message }
|
||||
}
|
||||
});
|
||||
|
||||
// 打印出入库单
|
||||
ipcMain.on('STOCK', async (event, arg) => {
|
||||
try {
|
||||
let _parmas = JSON.parse(arg);
|
||||
await STOCK(_parmas.printerIp, _parmas.orderData);
|
||||
return { ok: true }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
11
package-lock.json
generated
11
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "vite-electron",
|
||||
"version": "2.0.21",
|
||||
"version": "2.0.25",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "vite-electron",
|
||||
"version": "2.0.21",
|
||||
"version": "2.0.25",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
@@ -21,6 +21,7 @@
|
||||
"lodash": "^4.17.21",
|
||||
"pinia": "^2.1.7",
|
||||
"pinia-plugin-persistedstate": "^3.2.1",
|
||||
"qr-image": "^3.2.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"reconnecting-websocket": "^4.4.0",
|
||||
"speak-tts": "^2.0.8",
|
||||
@@ -5332,6 +5333,12 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/qr-image": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/qr-image/-/qr-image-3.2.0.tgz",
|
||||
"integrity": "sha512-rXKDS5Sx3YipVsqmlMJsJsk6jXylEpiHRC2+nJy66fxA5ExYyGa4PqwteW69SaVmAb2OQ18HbYriT7cGQMbduw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/qrcode": {
|
||||
"version": "1.5.4",
|
||||
"resolved": "https://registry.npmmirror.com/qrcode/-/qrcode-1.5.4.tgz",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vite-electron",
|
||||
"private": true,
|
||||
"version": "2.0.25",
|
||||
"version": "2.0.26",
|
||||
"main": "dist-electron/main.js",
|
||||
"scripts": {
|
||||
"dev": "chcp 65001 && vite",
|
||||
@@ -24,6 +24,7 @@
|
||||
"lodash": "^4.17.21",
|
||||
"pinia": "^2.1.7",
|
||||
"pinia-plugin-persistedstate": "^3.2.1",
|
||||
"qr-image": "^3.2.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"reconnecting-websocket": "^4.4.0",
|
||||
"speak-tts": "^2.0.8",
|
||||
|
||||
14
src/api/print.js
Normal file
14
src/api/print.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import request from "@/utils/request.js";
|
||||
|
||||
/**
|
||||
* 获取打印数据
|
||||
* @param {*} params
|
||||
* @returns
|
||||
*/
|
||||
export function printData(params) {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/order/admin/printData",
|
||||
params,
|
||||
});
|
||||
}
|
||||
@@ -129,14 +129,11 @@ async function submitHandleAjax() {
|
||||
console.log('props.selecttype===', props.selecttype);
|
||||
console.log('props.payType===', props.payType);
|
||||
|
||||
// return;
|
||||
|
||||
// 判断订单是否锁定
|
||||
await goodsStore.isOrderLock({
|
||||
table_code: goodsStore.orderListInfo.tableCode
|
||||
})
|
||||
|
||||
if (props.selecttype == 0) {
|
||||
// 判断订单是否锁定
|
||||
await goodsStore.isOrderLock({
|
||||
table_code: goodsStore.orderListInfo.tableCode
|
||||
})
|
||||
// 下单扫码支付
|
||||
if (props.payType == 'scanCode') {
|
||||
await microPay({
|
||||
@@ -151,6 +148,7 @@ async function submitHandleAjax() {
|
||||
});
|
||||
}
|
||||
} else if (props.selecttype == 1) {
|
||||
console.log('进入会员扫码充值');
|
||||
// 会员扫码充值
|
||||
await microPayVip({
|
||||
shopId: store.shopInfo.id,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ import ReconnectingWebSocket from "reconnecting-websocket";
|
||||
import { useGoods } from "@/store/goods.js";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { getOrderByIdAjax, commOrderPrintData } from "@/utils/index.js";
|
||||
import { printData } from '@/api/print.js'
|
||||
|
||||
export const useSocket = defineStore("socket", {
|
||||
state: () => ({
|
||||
@@ -17,8 +18,236 @@ export const useSocket = defineStore("socket", {
|
||||
orderListTimer: null,
|
||||
log: false,
|
||||
isPrinting: false,
|
||||
// 新增:其他打印任务队列与状态锁
|
||||
printQueue: [],
|
||||
isProcessing: false
|
||||
}),
|
||||
actions: {
|
||||
// 计算订单中所有菜品的总价总和
|
||||
calcAllCartsTotalSum(cartObj) {
|
||||
// 初始化总和为0
|
||||
let totalSum = 0;
|
||||
// 遍历原始对象的所有键(0、1、2...)
|
||||
Object.keys(cartObj).forEach(key => {
|
||||
const carts = cartObj[key] || [];
|
||||
// 累加当前分类下的菜品总价(num × unitPrice)
|
||||
carts.forEach(item => {
|
||||
const num = Number(item.num) - Number(item.returnNum) || 0; // 防错:非数字转0
|
||||
const unitPrice = Number(item.unitPrice) || 0;
|
||||
totalSum += num * unitPrice;
|
||||
});
|
||||
});
|
||||
return totalSum; // 返回所有菜品的总价总和
|
||||
},
|
||||
// 1. 添加任务到队列
|
||||
addToPrintQueue(task) {
|
||||
this.printQueue.push(task);
|
||||
if (this.log) console.log('任务已加入打印队列,当前队列长度:', this.printQueue.length);
|
||||
this.processPrintQueue(); // 尝试启动处理
|
||||
},
|
||||
// 2. 处理队列(递归执行)
|
||||
async processPrintQueue() {
|
||||
const printStore = usePrint();
|
||||
|
||||
// 如果正在处理或队列为空,直接返回
|
||||
if (this.isProcessing || this.printQueue.length === 0) return;
|
||||
|
||||
this.isProcessing = true;
|
||||
const currentTask = this.printQueue[0]; // 取出第一个任务
|
||||
|
||||
try {
|
||||
if (this.log) console.log('开始执行打印任务:', currentTask);
|
||||
|
||||
const isOrderPrint = ['GUEST_ORDER', 'PRE_ORDER', 'ORDER', 'RETURN_ORDER', 'REFUND_ORDER', 'ALL_KITCHEN', 'ONLY_KITCHEN', 'REFUND_KITCHEN',]
|
||||
|
||||
console.log('currentTask===', currentTask);
|
||||
|
||||
if (_.includes(isOrderPrint, currentTask.printType)) {
|
||||
// 订单相关打印,调用对应接口获取数据
|
||||
const data = await getOrderByIdAjax(currentTask.orderId);
|
||||
|
||||
console.log('订单相关打印,调用对应接口获取数据===', data);
|
||||
|
||||
switch (currentTask.printType) {
|
||||
case 'ORDER':
|
||||
// 打印订单小票
|
||||
printStore.ORDER(commOrderPrintData(data));
|
||||
// 打印标签小票
|
||||
printStore.labelPrint(commOrderPrintData(data));
|
||||
break;
|
||||
case 'PRE_ORDER':
|
||||
// 打印预订单小票
|
||||
data.originAmount = this.calcAllCartsTotalSum(data.detailMap)
|
||||
|
||||
if (data.seatAmount > 0 && data.dineMode == 'dine-in') {
|
||||
data.originAmount += data.seatAmount
|
||||
}
|
||||
let packFee = 0
|
||||
|
||||
data.cartList.forEach(item => {
|
||||
if (item.packNumber > 0 && (item.num - item.returnNum) >= item.packNumber) {
|
||||
packFee += (item.num - item.returnNum) * item.packAmount
|
||||
}
|
||||
})
|
||||
|
||||
if (packFee > 0) {
|
||||
data.originAmount += packFee
|
||||
data.packFee = packFee
|
||||
}
|
||||
|
||||
printStore.PRE_ORDER(commOrderPrintData({ ...data, isBefore: true }));
|
||||
break;
|
||||
case 'GUEST_ORDER':
|
||||
// 打印客看单
|
||||
data.detailMap = _.at(data.detailMap, data.placeNum);
|
||||
|
||||
let amout = 0
|
||||
data.detailMap.flat().forEach(item => {
|
||||
amout += item.num * item.unitPrice
|
||||
});
|
||||
|
||||
data.originAmount = amout
|
||||
|
||||
if (data.placeNum == 1 && data.dineMode == 'dine-in') {
|
||||
data.originAmount += data.seatAmount
|
||||
}
|
||||
|
||||
if (data.packFee > 0) {
|
||||
data.originAmount += data.packFee
|
||||
}
|
||||
|
||||
printStore.GUEST_ORDER(commOrderPrintData({ ...data, isGuest: true, isBefore: false }));
|
||||
break;
|
||||
case 'ALL_KITCHEN':
|
||||
// 打印整单厨房票
|
||||
if (data.payMode == 'after-pay') {
|
||||
// 后付费订单,只打印当前下单商品的整单厨房票
|
||||
data.detailMap = _.at(data.detailMap, data.placeNum);
|
||||
printStore.ALL_KITCHEN(commOrderPrintData({ ...data, isGuest: true, isNotPrint: true }));
|
||||
} else {
|
||||
printStore.ALL_KITCHEN(commOrderPrintData({ ...data, isNotPrint: true }));
|
||||
}
|
||||
// console.log('打印整单厨房票.data', data);
|
||||
break;
|
||||
case 'ONLY_KITCHEN':
|
||||
// 打印一菜一品厨房票
|
||||
if (data.payMode == 'after-pay') {
|
||||
// 后付费订单,只打印当前下单的一菜一品厨房票
|
||||
data.detailMap = _.at(data.detailMap, data.placeNum);
|
||||
const orderInfo = commOrderPrintData({ ...data, isGuest: true, isNotPrint: true });
|
||||
orderInfo.carts.forEach(item => {
|
||||
const ONLY_KITCHEN_DATA = {
|
||||
...orderInfo,
|
||||
carts: [item]
|
||||
}
|
||||
printStore.ONLY_KITCHEN(ONLY_KITCHEN_DATA);
|
||||
})
|
||||
} else {
|
||||
data.cartList.forEach(item => {
|
||||
const ONLY_KITCHEN_DATA = {
|
||||
...data.orderData,
|
||||
cartList: [item],
|
||||
isNotPrint: true
|
||||
}
|
||||
printStore.ONLY_KITCHEN(commOrderPrintData(ONLY_KITCHEN_DATA));
|
||||
})
|
||||
}
|
||||
break;
|
||||
case 'RETURN_ORDER':
|
||||
// 打印退菜小票
|
||||
const socketData = JSON.parse(currentTask.data);
|
||||
// console.log('打印退菜小票.socketData', socketData);
|
||||
|
||||
let cartList = _.compact(
|
||||
_.map(data.cartList, (cartItem) => {
|
||||
// 找到对应项
|
||||
const taskItem = _.find(socketData, (t) => cartItem.id == t.id);
|
||||
|
||||
// 找到就返回带 num 的对象
|
||||
if (taskItem) {
|
||||
return {
|
||||
...cartItem,
|
||||
num: taskItem.num,
|
||||
returnNum: 0,
|
||||
payAmount: taskItem.num * cartItem.price
|
||||
};
|
||||
}
|
||||
|
||||
// 没找到返回 undefined,会被 _.compact 过滤掉
|
||||
return null;
|
||||
})
|
||||
);
|
||||
|
||||
data.cartList = cartList;
|
||||
|
||||
// console.log('打印退菜小票.data', data);
|
||||
|
||||
printStore.RETURN_ORDER(commOrderPrintData({ ...data, isRefundDish: true }));
|
||||
break;
|
||||
case 'REFUND_ORDER':
|
||||
// 打印退单小票
|
||||
{
|
||||
const socketData = JSON.parse(currentTask.data);
|
||||
// console.log('打印退菜小票.socketData', socketData);
|
||||
|
||||
let cartList = _.compact(
|
||||
_.map(data.cartList, (cartItem) => {
|
||||
// 找到对应项
|
||||
const taskItem = _.find(socketData, (t) => cartItem.id == t.id);
|
||||
|
||||
// 找到就返回带 num 的对象
|
||||
if (taskItem) {
|
||||
return {
|
||||
...cartItem,
|
||||
num: taskItem.num,
|
||||
returnNum: 0,
|
||||
payAmount: taskItem.num * cartItem.price
|
||||
};
|
||||
}
|
||||
|
||||
// 没找到返回 undefined,会被 _.compact 过滤掉
|
||||
return null;
|
||||
})
|
||||
);
|
||||
|
||||
data.cartList = cartList;
|
||||
data.payAmount = currentTask.amount;
|
||||
// console.log('打印退单小票.data', data);
|
||||
|
||||
printStore.REFUND_ORDER(commOrderPrintData({ ...data, isRefundDish: true }));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 执行打印逻辑(参考你注释中的代码)
|
||||
const res = await printData({
|
||||
shopId: currentTask.shopId,
|
||||
dataId: currentTask.dataId,
|
||||
type: currentTask.printType
|
||||
});
|
||||
|
||||
console.log('printData.res===', res);
|
||||
|
||||
if (printStore[currentTask.printType]) {
|
||||
printStore[currentTask.printType](JSON.parse(res.data));
|
||||
}
|
||||
}
|
||||
if (this.log) console.log('任务执行成功');
|
||||
} catch (error) {
|
||||
console.error('打印任务执行失败:', error);
|
||||
// 失败时不移除任务,或者根据业务决定是否重试/丢弃
|
||||
} finally {
|
||||
// 无论成功失败,移除当前任务
|
||||
this.printQueue.shift();
|
||||
if (this.log) console.log('任务移除,剩余队列:', this.printQueue.length);
|
||||
|
||||
// 标记为空闲,尝试处理下一个
|
||||
this.isProcessing = false;
|
||||
this.processPrintQueue();
|
||||
}
|
||||
},
|
||||
// 关闭ws
|
||||
close() {
|
||||
if (this.log) console.log("关闭ws");
|
||||
@@ -219,10 +448,14 @@ export const useSocket = defineStore("socket", {
|
||||
}
|
||||
}
|
||||
} else if (data.data_type == "order") {
|
||||
this.addToPrintQueue(JSON.parse(data.data));
|
||||
return;
|
||||
|
||||
goodsStore.successClearCart();
|
||||
goodsStore.historyOrderAjax(data.data.table_code);
|
||||
this.cartInit();
|
||||
|
||||
this.addToPrintQueue(data.data);
|
||||
|
||||
// 收到订单消息,打印订单小票
|
||||
let orderInfo = data.data.split("_");
|
||||
@@ -277,6 +510,12 @@ export const useSocket = defineStore("socket", {
|
||||
} else if (data.data_type == "product_update") {
|
||||
// 商品更新
|
||||
this.updateGoods();
|
||||
} else if (data.data_type == 'other_print') {
|
||||
// 其他打印集合 data.data = {"shopId":148,"dataId":27,"printType":"STOCK"}
|
||||
// 用const res = printData({ shopId: shopId, dataId: dataId, type: printType })
|
||||
// 获取到数据后调用goodsStore[data.data.printType](JSON.parse(res.data))
|
||||
console.log('other_print===', data.data);
|
||||
this.addToPrintQueue(data.data);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -195,12 +195,13 @@ export function commOrderPrintData(orderInfo) {
|
||||
categoryId: item.categoryId,
|
||||
name: item.isGift === 1 ? `[赠]${item.productName}` : item.productName,
|
||||
number: item.num - item.returnNum,
|
||||
skuName: item.skuName,
|
||||
skuName: item.skuName || '',
|
||||
salePrice: formatDecimal(+price),
|
||||
totalAmount: formatDecimal(+item.payAmount),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
: "",
|
||||
remark: item.remark
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -215,18 +216,19 @@ export function commOrderPrintData(orderInfo) {
|
||||
categoryId: item.categoryId,
|
||||
name: item.isGift === 1 ? `[赠]${item.productName}` : item.productName,
|
||||
number: item.num - item.returnNum,
|
||||
skuName: item.skuName,
|
||||
skuName: item.skuName || '',
|
||||
salePrice: formatDecimal(+price),
|
||||
totalAmount: formatDecimal((item.num - item.returnNum) * price),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
: "",
|
||||
remark: item.remark || ''
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (orderInfo.dineMode == 'dine-in') {
|
||||
if (orderInfo.seatAmount > 0 && orderInfo.isGuest && orderInfo.placeNum == 1 && !orderInfo.isRefundDish) {
|
||||
if (orderInfo.seatAmount > 0 && orderInfo.isGuest && orderInfo.placeNum == 1 && !orderInfo.isRefundDish && !orderInfo.isNotPrint) {
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '餐位费',
|
||||
@@ -235,10 +237,11 @@ export function commOrderPrintData(orderInfo) {
|
||||
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||
totalAmount: orderInfo.seatAmount,
|
||||
proGroupInfo: "",
|
||||
remark: ''
|
||||
})
|
||||
}
|
||||
|
||||
if (orderInfo.seatAmount > 0 && !orderInfo.isGuest && !orderInfo.isRefundDish) {
|
||||
if (orderInfo.seatAmount > 0 && !orderInfo.isGuest && !orderInfo.isRefundDish && !orderInfo.isNotPrint) {
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '餐位费',
|
||||
@@ -247,11 +250,12 @@ export function commOrderPrintData(orderInfo) {
|
||||
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||
totalAmount: orderInfo.seatAmount,
|
||||
proGroupInfo: "",
|
||||
remark: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (orderInfo.packFee > 0 && !orderInfo.isRefundDish) {
|
||||
if (orderInfo.packFee > 0 && !orderInfo.isRefundDish && !orderInfo.isNotPrint) {
|
||||
let packNum = 0;
|
||||
orderInfo.cartList.forEach(item => {
|
||||
packNum += item.packNumber
|
||||
@@ -264,10 +268,11 @@ export function commOrderPrintData(orderInfo) {
|
||||
salePrice: '',
|
||||
totalAmount: formatDecimal(orderInfo.packFee),
|
||||
proGroupInfo: "",
|
||||
remark: ''
|
||||
})
|
||||
}
|
||||
|
||||
console.log('最终组合打印数据===', data);
|
||||
// console.log('最终组合打印数据===', data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,20 +36,32 @@
|
||||
<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 class="column">
|
||||
<el-radio-group v-model="form.classifyPrint" @change="form.categoryList = [];form.categoryIds = ''">
|
||||
<el-radio-button label="全部" value="0"></el-radio-button>
|
||||
<el-radio-button label="部分" value="1"
|
||||
v-show="printTypeList[1].values.length > 0"></el-radio-button>
|
||||
</el-radio-group>
|
||||
<div style="cursor: pointer" @click="classifyRef.show()" v-if="form.classifyPrint == '1'">
|
||||
<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>
|
||||
</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 label="打印类型">
|
||||
<div class="row" v-for="(item, index) in printTypeList" :key="index">
|
||||
<div class="title">{{ item.label }}</div>
|
||||
<div class="cont">
|
||||
<el-checkbox-group v-model="item.values" @change="printTypeChange($event, index)">
|
||||
<el-checkbox :label="item.label" :value="item.value" v-for="item in item.list"
|
||||
:key="item.value"></el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="打印份数">
|
||||
<el-select v-model="form.printQty">
|
||||
@@ -95,21 +107,25 @@
|
||||
<div class="row">收银员:{{ printData.loginAccount }}</div>
|
||||
<div class="line"></div>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td>品名</td>
|
||||
<td>单价</td>
|
||||
<td>数量</td>
|
||||
<td>小计</td>
|
||||
</tr>
|
||||
<tr v-for="(item, index) in printData.carts" :key="index">
|
||||
<td>
|
||||
<div>{{ item.name }}</div>
|
||||
<div class="sku">{{ item.skuName }}</div>
|
||||
</td>
|
||||
<td>{{ item.salePrice }}</td>
|
||||
<td>{{ item.number }}</td>
|
||||
<td>{{ item.totalAmount }}</td>
|
||||
</tr>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>品名</td>
|
||||
<td>单价</td>
|
||||
<td>数量</td>
|
||||
<td>小计</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in printData.carts" :key="index">
|
||||
<td>
|
||||
<div>{{ item.name }}</div>
|
||||
<div class="sku">{{ item.skuName }}</div>
|
||||
</td>
|
||||
<td>{{ item.salePrice }}</td>
|
||||
<td>{{ item.number }}</td>
|
||||
<td>{{ item.totalAmount }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="line"></div>
|
||||
<div class="row between">
|
||||
@@ -148,6 +164,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import _ from 'lodash'
|
||||
import dayjs from "dayjs";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
@@ -172,22 +189,61 @@ const printList = ref([]);
|
||||
const feets = ref([0, 1, 2, 3, 4, 5, 8]);
|
||||
const loading = ref(false);
|
||||
const requestLoading = ref(false);
|
||||
const printTypeList = ref([
|
||||
{
|
||||
label: '前台',
|
||||
values: [],
|
||||
list: [
|
||||
{ label: '客看单', value: 'GUEST_ORDER' },
|
||||
{ label: '预结算单', value: 'PRE_ORDER' },
|
||||
{ label: '结算单', value: 'ORDER' },
|
||||
{ label: '退菜单', value: 'RETURN_ORDER' },
|
||||
{ label: '退款单', value: 'REFUND_ORDER' },
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '后厨',
|
||||
values: [],
|
||||
list: [
|
||||
{ label: '后厨-整单', value: 'ALL_KITCHEN' },
|
||||
{ label: '后厨-分单', value: 'ONLY_KITCHEN' },
|
||||
{ label: '后厨-退菜单', value: 'REFUND_KITCHEN' },
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '其它',
|
||||
values: [],
|
||||
list: [
|
||||
{ label: '交班单', value: 'HANDOVER' },
|
||||
{ label: '排队取号', value: 'CALL' },
|
||||
{ label: '储值单', value: 'RECHARGE' },
|
||||
{ label: '出入库单', value: 'STOCK' },
|
||||
{ label: '盘点单', value: 'STOCK_CHECK' },
|
||||
{ label: '商品报表', value: 'PRODUCT_REPORT' },
|
||||
{ label: '经营日报', value: 'DAY_REPORT' },
|
||||
{ label: '日结单', value: 'DAY_ORDER' },
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
const categoryIdsType = ref('all') // all=全部 custom=部分
|
||||
|
||||
const form = ref({
|
||||
id: "",
|
||||
name: '', // 设备名称
|
||||
connectionType: 'USB', // 现在打印机支持USB 和 网络、蓝牙、局域网
|
||||
address: '', // 打印机名称
|
||||
port: '', // 端口
|
||||
subType: 'cash', // 打印类型(分类)label标签cash小票kitchen出品
|
||||
printType: 'cash', // 打印类型(分类)label标签cash小票kitchen出品
|
||||
contentType: '', // 打印机品牌
|
||||
categoryIds: [], // 打印分类Id
|
||||
categoryIds: '', // 打印分类Id
|
||||
categoryList: [], // 分类
|
||||
sort: '',
|
||||
receiptSize: '58mm', // 小票尺寸 58mm 80mm
|
||||
classifyPrint: 1, // 分类打印 0-所有 1-部分分类 2-部分商品
|
||||
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-排队取号
|
||||
classifyPrint: '1', // 分类打印 0-所有 1-部分分类 2-部分商品
|
||||
printNum: '', // 打印数量 c1m1^2 = 顾客+商家[2张] m1^1 = 商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
||||
kitchenPrintMode: 'all', // 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」queue-仅打印排队取号
|
||||
printContentType: [],
|
||||
status: 1,
|
||||
handoverSwitch: 0, // 交班单开关 0-关闭 1-开启
|
||||
});
|
||||
@@ -248,13 +304,13 @@ function printHandle() {
|
||||
printDataLoading.value = true;
|
||||
printData.shop_name = store.shopInfo.shopName
|
||||
printData.loginAccount = store.userInfo.name
|
||||
printData.deviceName = form.value.address;
|
||||
printData.deviceName = form.value.name;
|
||||
printData.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
if (form.value.connectionType === 'USB') {
|
||||
printStore.pushReceiptData(printData, false);
|
||||
} else if (form.value.connectionType === '局域网') {
|
||||
ipcRenderer.send('networkPrint', JSON.stringify({
|
||||
ipcRenderer.send('ORDER', JSON.stringify({
|
||||
printerIp: form.value.address,
|
||||
orderData: printData
|
||||
}))
|
||||
@@ -264,6 +320,16 @@ function printHandle() {
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
// 打印类型切换
|
||||
function printTypeChange(e, index) {
|
||||
if (index == 1 && printTypeList.value[index].values.length == 0) {
|
||||
form.value.categoryList = []
|
||||
form.value.classifyPrint = '0'
|
||||
} else {
|
||||
form.value.classifyPrint = '1'
|
||||
}
|
||||
}
|
||||
|
||||
// 提交打印机
|
||||
async function submitHandle() {
|
||||
try {
|
||||
@@ -279,8 +345,21 @@ async function submitHandle() {
|
||||
ElMessage.error("请输入设备IP地址");
|
||||
return;
|
||||
}
|
||||
|
||||
if (form.value.classifyPrint == '1' && !form.value.categoryList.length) {
|
||||
ElMessage.error("请选择商品分类");
|
||||
return;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
form.value.categoryIds = form.value.categoryList.map(item => item.id)
|
||||
form.value.categoryIds = form.value.categoryList.map(item => item.id).join(',')
|
||||
|
||||
let arr = []
|
||||
printTypeList.value.forEach(item => {
|
||||
arr.push(...item.values)
|
||||
})
|
||||
|
||||
form.value.printContentType = arr.join(',')
|
||||
await printerAdd(form.value, form.value.id ? "put" : "post");
|
||||
ElMessage.success(form.value.id ? "编辑成功" : "添加成功");
|
||||
printStore.init();
|
||||
@@ -298,9 +377,11 @@ async function tbPrintMachineDetailAjax(id) {
|
||||
const res = await printerDetail({ id: id });
|
||||
form.value = res;
|
||||
|
||||
// 做分类信息补全
|
||||
let arr = []
|
||||
let categoryIds = res.categoryIds.split(',')
|
||||
goodsStore.originCategoryList.map(item => {
|
||||
res.categoryList.map(val => {
|
||||
categoryIds.map(val => {
|
||||
if (item.id == val) {
|
||||
arr.push({
|
||||
id: item.id,
|
||||
@@ -310,6 +391,22 @@ async function tbPrintMachineDetailAjax(id) {
|
||||
})
|
||||
})
|
||||
form.value.categoryList = arr
|
||||
|
||||
// 补全已选中的打印类型
|
||||
const printContentTypes = res.printContentType.split(',')
|
||||
printTypeList.value.forEach(val => {
|
||||
val.values = _.map(
|
||||
_.filter(val.list, item => printContentTypes.includes(item.value)),
|
||||
'value'
|
||||
);
|
||||
})
|
||||
|
||||
console.log(form.value);
|
||||
|
||||
|
||||
// if (printTypeList.value[1].values.length > 0 && form.value.classifyPrint == 1) {
|
||||
// form.value.classifyPrint = 1
|
||||
// }
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
@@ -354,6 +451,7 @@ onMounted(() => {
|
||||
border-radius: 10px;
|
||||
background-color: #fff;
|
||||
padding: 15px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.menu_wrap {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="item" v-for="item in list" :key="item.id">
|
||||
<div class="left">
|
||||
<div class="icon">
|
||||
<el-image :src="icons[item.subType]" style="width: 40px; height: 40px"></el-image>
|
||||
<el-image :src="icons[item.printType]" style="width: 40px; height: 40px"></el-image>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="name">{{ item.name }}</div>
|
||||
@@ -28,7 +28,7 @@
|
||||
<div class="editor">
|
||||
<el-text type="primary" @click="
|
||||
router.push({
|
||||
name: deviceRoute[item.subType],
|
||||
name: deviceRoute[item.printType],
|
||||
query: { id: item.id },
|
||||
})
|
||||
">
|
||||
|
||||
@@ -359,18 +359,19 @@ async function refundNext() {
|
||||
goodsStore.cartOrderItem.returnNum += refundNum.value
|
||||
goodsStore.calcCartInfo()
|
||||
|
||||
getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
|
||||
let originOrderInfo = res
|
||||
let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
|
||||
originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
|
||||
originOrderInfo.cartList[0].num = refundNum.value
|
||||
originOrderInfo.cartList[0].returnNum = 0
|
||||
originOrderInfo.cartList[0].payAmount = refundNum.value * originOrderInfo.cartList[0].price
|
||||
// 打印退菜小票
|
||||
// getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
|
||||
// let originOrderInfo = res
|
||||
// let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
|
||||
// originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
|
||||
// originOrderInfo.cartList[0].num = refundNum.value
|
||||
// originOrderInfo.cartList[0].returnNum = 0
|
||||
// originOrderInfo.cartList[0].payAmount = refundNum.value * originOrderInfo.cartList[0].price
|
||||
|
||||
printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
// printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
|
||||
// }).catch(err => {
|
||||
// console.log(err);
|
||||
// })
|
||||
// await goodsStore.historyOrderAjax('', data.orderId)
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -226,6 +226,13 @@ function calcAllCartsTotalSum(cartObj) {
|
||||
async function printOrderLable(isBefore = false) {
|
||||
try {
|
||||
let orderId = goodsStore.orderListInfo.id
|
||||
await orderPrint({
|
||||
type: isBefore ? 1 : 0,
|
||||
id: orderId,
|
||||
});
|
||||
printLoading.value = false
|
||||
return
|
||||
|
||||
let data = await getOrderByIdAjax(orderId);
|
||||
|
||||
console.log(`打印订单标签数据${isBefore}===`, data);
|
||||
|
||||
@@ -28,15 +28,20 @@
|
||||
</el-dialog> -->
|
||||
<!-- <el-input v-model="authCode" placeholder="请扫描支付码"></el-input>
|
||||
<el-button type="primary" @click="microPayAjax">反扫支付</el-button> -->
|
||||
<el-button type="primary" @click="printReceipt">调用本地网络打印机</el-button>
|
||||
<el-button type="primary" @click="printReceipt">打印盘点单</el-button>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import dayjs from 'dayjs';
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { findVersion } from '@/api/user.js'
|
||||
import packageData from "../../../package.json";
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { microPay } from '@/api/order.js'
|
||||
import { usePrint } from '@/store/print';
|
||||
import { printData } from '@/api/print.js'
|
||||
import { useUser } from '@/store/user.js'
|
||||
import { ALL_KITCHEN, ONLY_KITCHEN, REFUND_KITCHEN } from '../../../electron/printService'
|
||||
|
||||
const showDialog = ref(false)
|
||||
const updataInfo = ref({})
|
||||
@@ -45,27 +50,88 @@ const uploadPro = ref(0)
|
||||
const uploadSucess = ref(false)
|
||||
const uploadResponse = ref({})
|
||||
const tempFilePath = ref('')
|
||||
|
||||
const printStore = usePrint()
|
||||
const authCode = ref('')
|
||||
const user = useUser()
|
||||
|
||||
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: '微辣'
|
||||
}
|
||||
// RECHARGE=22 STOCK=30 STOCK_CHECK=32 CALL=38
|
||||
async function printReceipt() {
|
||||
const order = {
|
||||
shop_name: '张三的店',
|
||||
loginAccount: '',
|
||||
isBefore: true,
|
||||
carts: [
|
||||
{
|
||||
id: 1,
|
||||
name: "菜品名称1",
|
||||
skuName: "多放香菜",
|
||||
salePrice: "1.0",
|
||||
number: "10",
|
||||
totalAmount: "10",
|
||||
remark: '多放点盐',
|
||||
proGroupInfo: [
|
||||
{
|
||||
proName: '西红柿',
|
||||
number: '2'
|
||||
}
|
||||
]
|
||||
},
|
||||
// {
|
||||
// id: 2,
|
||||
// name: "菜品名称2",
|
||||
// skuName: "500ml",
|
||||
// salePrice: "1.0",
|
||||
// number: "10",
|
||||
// totalAmount: "10",
|
||||
// remark: ''
|
||||
// },
|
||||
// {
|
||||
// id: 3,
|
||||
// name: "菜品名称3",
|
||||
// skuName: "",
|
||||
// salePrice: "1.0",
|
||||
// number: "10",
|
||||
// totalAmount: "10",
|
||||
// remark: ''
|
||||
// },
|
||||
],
|
||||
amount: "10.00",
|
||||
originAmount: '10.00',
|
||||
discountAmount: "0.00",
|
||||
discountAllAmount: 0,
|
||||
orderAmount: 10,
|
||||
discount: 0,
|
||||
remark: "给我多放点辣椒,谢谢老板",
|
||||
orderInfo: {
|
||||
masterId: "",
|
||||
orderNo: "202404021023542223445",
|
||||
orderNum: '12',
|
||||
discountAllAmount: 0,
|
||||
orderAmount: 10,
|
||||
tableName: '室内-A1',
|
||||
dineMode: 'dine-in'
|
||||
},
|
||||
loginAccount: '李四',
|
||||
printerName: '堂食打印机',
|
||||
deviceName: "",
|
||||
createdAt: "2024-04-02 10:15",
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
}
|
||||
ipcRenderer.send('portPrint', JSON.stringify(data))
|
||||
// ALL_KITCHEN('192.168.1.53', order)
|
||||
|
||||
// ONLY_KITCHEN('192.168.1.53', order)
|
||||
|
||||
REFUND_KITCHEN('192.168.1.53', order)
|
||||
|
||||
// const res = await printData({
|
||||
// shopId: user.shopInfo.id,
|
||||
// dataId: 38,
|
||||
// type: 'CALL'
|
||||
// })
|
||||
|
||||
// console.log(JSON.parse(res.data));
|
||||
|
||||
// printStore.CALL(JSON.parse(res.data))
|
||||
}
|
||||
|
||||
// 检查版本更新
|
||||
|
||||
@@ -251,7 +251,7 @@ async function refundNext() {
|
||||
|
||||
await refundOrder(data)
|
||||
ElMessage.success('退款成功')
|
||||
await printRefund(rows.value)
|
||||
// await printRefund(rows.value)
|
||||
isShow.value = false
|
||||
emits('success')
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user