优化订单小票打印
This commit is contained in:
@@ -317,7 +317,7 @@ export function handoverNetworkPrint(id) {
|
||||
export function printerList(subType = "") {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/account/admin/printer",
|
||||
url: "/account/admin/printer/getPrintLocal",
|
||||
params: {
|
||||
name: "",
|
||||
subType: subType,
|
||||
|
||||
@@ -104,3 +104,17 @@ export function shopStoragePut(data) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询存取酒记录
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
export function shopStorageRecord(params) {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/product/admin/shopStorage/record",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { formatDecimal } from "@/utils/index.js";
|
||||
* 打印订单小票
|
||||
*/
|
||||
export default (data) => {
|
||||
// console.log("需要打印的订单数据===", data);
|
||||
console.log("需要打印的订单数据===", data);
|
||||
// console.log("data.deviceName===", data.deviceName);
|
||||
let LODOP = getLodop();
|
||||
LODOP.PRINT_INIT("打印小票");
|
||||
|
||||
@@ -486,7 +486,8 @@ function upadatePayData() {
|
||||
newCustomerDiscountId: goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.id : goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.id : '', // 新客立减Id
|
||||
newCustomerDiscountAmount: goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.amount : 0, // 新客立减金额
|
||||
vipDiscountAmount: goodsStore.cartInfo.costSummary.vipDiscountAmount, // 超级会员折扣
|
||||
remark: '', // 现金支付备注
|
||||
remark: goodsStore.remark, // 现金支付备注
|
||||
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,9 +560,9 @@ async function confirmOrder(t = 1) {
|
||||
ElMessageBox.prompt('确定现金支付?', '注意', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPlaceholder: '请输入备注(选填)',
|
||||
inputPlaceholder: goodsStore.remark ? goodsStore.remark : '请输入备注(选填)',
|
||||
}).then(async ({ value }) => {
|
||||
payData.value.checkOrderPay.remark = value;
|
||||
payData.value.checkOrderPay.remark = value ? value : goodsStore.remark;
|
||||
if (props.selecttype == 0) {
|
||||
payLoading.loading = true
|
||||
await cashPay(payData.value);
|
||||
|
||||
@@ -36,6 +36,7 @@ const initialCostSummary = {
|
||||
// 商品store + 购物车store
|
||||
export const useGoods = defineStore("goods", {
|
||||
state: () => ({
|
||||
remark: "", // 订单备注
|
||||
showVipPrice: 0,
|
||||
allSelected: 0, // 是否整单打包
|
||||
vipUserInfo: {}, // 会员信息
|
||||
|
||||
@@ -75,14 +75,22 @@ export const usePrint = defineStore("print", {
|
||||
return ipReg.test(printer.address);
|
||||
}
|
||||
|
||||
if (printer.connectionType === "usb") {
|
||||
if (printer.connectionType === "USB") {
|
||||
return this.localDevices.some(item => item.name === printer.address);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// 辅助方法:判断是否为特殊费用项(餐位费/打包费)
|
||||
isSpecialFeeItem(item) {
|
||||
// 可根据实际业务调整判断条件,比如通过名称/标识判断
|
||||
const specialNames = ["餐位费", "打包费"];
|
||||
// 条件:1. 无categoryId 2. 名称包含特殊费用关键词 或 标记了特殊标识
|
||||
return !item.categoryId && (item.isSpecialFee || specialNames.some(name => item.name?.includes(name)));
|
||||
},
|
||||
|
||||
// ==============================
|
||||
// 最终完美版 → 空数组打印全部
|
||||
// 优化:保留无categoryId的特殊费用项,兼容原有分类过滤逻辑
|
||||
// ==============================
|
||||
pushReceiptData(props, isDevice = true) {
|
||||
if (!isDevice) {
|
||||
@@ -105,15 +113,15 @@ export const usePrint = defineStore("print", {
|
||||
validPrinters.forEach(printer => {
|
||||
let filterCarts = [];
|
||||
|
||||
// ======================================
|
||||
// ✅ 核心:分类为空数组 → 打印全部菜品
|
||||
// ======================================
|
||||
// 核心过滤逻辑:
|
||||
// 1. 分类为空 → 打印全部(包含特殊费用项)
|
||||
// 2. 分类非空 → 打印「匹配分类的商品」+「无categoryId的特殊费用项」
|
||||
if (!printer.categoryList || printer.categoryList.length === 0) {
|
||||
filterCarts = props.carts || [];
|
||||
} else {
|
||||
// 有分类 → 只打印对应分类
|
||||
filterCarts = (props.carts || []).filter(item => {
|
||||
return printer.categoryList.includes(item.categoryId);
|
||||
// 保留:特殊费用项(无categoryId) + 匹配分类的商品(有categoryId)
|
||||
return this.isSpecialFeeItem(item) || printer.categoryList.includes(item.categoryId);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -199,90 +207,82 @@ export const usePrint = defineStore("print", {
|
||||
},
|
||||
|
||||
// ————————————————————————————————
|
||||
// 以下原有代码完全不动(除了printWork方法)
|
||||
// 以下原有代码完全保留,仅优化格式和可读性
|
||||
// ————————————————————————————————
|
||||
checkLocalPrint(address) {
|
||||
let print = "";
|
||||
for (let item of this.localDevices) {
|
||||
if (item.name == address) {
|
||||
print = item;
|
||||
}
|
||||
}
|
||||
if (!print.name) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
const targetPrinter = this.localDevices.find(item => item.name === address);
|
||||
return !!targetPrinter?.name;
|
||||
},
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
this.startLabelPrint();
|
||||
} else {
|
||||
const validLabelPrinter = this.deviceLableList[0];
|
||||
|
||||
if (!validLabelPrinter || !this.checkLocalPrint(validLabelPrinter.address)) {
|
||||
console.log("标签打印:未在本机查询到打印机");
|
||||
return;
|
||||
}
|
||||
|
||||
const pids = validLabelPrinter.categoryList;
|
||||
let totalCount = 0;
|
||||
let currentCount = 0;
|
||||
|
||||
// 先计算总打印数量
|
||||
props.carts.forEach(item => {
|
||||
if (pids.some(el => el === item.categoryId)) {
|
||||
totalCount += item.number;
|
||||
}
|
||||
});
|
||||
|
||||
// 构建标签打印列表
|
||||
props.carts.forEach(item => {
|
||||
if (pids.some(el => el === item.categoryId)) {
|
||||
for (let i = 0; i < item.number; i++) {
|
||||
currentCount++;
|
||||
this.labelList.push({
|
||||
outNumber: props.outNumber,
|
||||
name: item.name,
|
||||
skuName: item.skuName,
|
||||
masterId: props.orderInfo.tableName,
|
||||
deviceName: validLabelPrinter.address,
|
||||
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
||||
isPrint: false,
|
||||
count: `${currentCount}/${totalCount}`,
|
||||
ticketLogo: store.shopInfo.ticketLogo,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.startLabelPrint();
|
||||
},
|
||||
|
||||
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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const item = this.labelList[0];
|
||||
if (!item.isPrint) {
|
||||
ipcRenderer.send("printerTagSync", JSON.stringify(item));
|
||||
this.labelList[0].isPrint = true;
|
||||
this.labelList.splice(0, 1);
|
||||
}
|
||||
}, 2000);
|
||||
},
|
||||
|
||||
// 打印交班小票(优化:1. 新增handoverSwitch=1才打印 2. 兼容局域网打印机)
|
||||
printWork(data) {
|
||||
// 筛选条件:
|
||||
// 1. 状态启用 + 小票类型 + handoverSwitch=1
|
||||
// 2. 打印机可用
|
||||
// 3. 打印服务正常
|
||||
// 筛选条件:状态启用 + 小票类型 + handoverSwitch=1 + 打印机可用 + 打印服务正常
|
||||
const validPrinters = this.deviceNoteList.filter(p => {
|
||||
return p.status
|
||||
&& p.subType === "cash"
|
||||
&& p.handoverSwitch === 1 // 新增:只有handoverSwitch为1的打印机才打印交班小票
|
||||
&& p.handoverSwitch === 1
|
||||
&& this.checkPrinterAvailable(p)
|
||||
&& this.isPrintService;
|
||||
});
|
||||
@@ -305,13 +305,11 @@ export const usePrint = defineStore("print", {
|
||||
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);
|
||||
@@ -322,22 +320,19 @@ export const usePrint = defineStore("print", {
|
||||
},
|
||||
|
||||
printInvoice(data) {
|
||||
if (
|
||||
this.deviceNoteList.length &&
|
||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||
) {
|
||||
data.deviceName = this.deviceNoteList[0].address;
|
||||
invoicePrint(data);
|
||||
} else {
|
||||
const validPrinter = this.deviceNoteList[0];
|
||||
if (!validPrinter || !this.checkLocalPrint(validPrinter.address)) {
|
||||
console.log("订单发票:未在本机查询到打印机");
|
||||
return;
|
||||
}
|
||||
|
||||
data.deviceName = validPrinter.address;
|
||||
invoicePrint(data);
|
||||
},
|
||||
// 退菜/退款
|
||||
|
||||
// 退款小票打印
|
||||
printRefund(data) {
|
||||
// 筛选条件:
|
||||
// 1. 状态启用 + 小票类型
|
||||
// 2. 打印机可用
|
||||
// 3. 打印服务正常
|
||||
// 筛选条件:状态启用 + 小票类型 + 打印机可用 + 打印服务正常
|
||||
const validPrinters = this.deviceNoteList.filter(p => {
|
||||
return p.status
|
||||
&& p.subType === "cash"
|
||||
@@ -367,13 +362,11 @@ export const usePrint = defineStore("print", {
|
||||
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);
|
||||
@@ -381,6 +374,52 @@ export const usePrint = defineStore("print", {
|
||||
console.error("❌ 退单小票打印失败:", printer.address, error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 退菜小票打印
|
||||
printRefundDish(data) {
|
||||
// 筛选条件:状态启用 + 小票类型 + 打印机可用 + 打印服务正常
|
||||
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 === "局域网") {
|
||||
ipcRenderer.send('printRefundDish', JSON.stringify({
|
||||
printerIp: printer.address,
|
||||
orderData: printData
|
||||
}));
|
||||
} else {
|
||||
refundPrint(printData);
|
||||
}
|
||||
console.log("✅ 退菜小票打印成功:", printer.address);
|
||||
} catch (error) {
|
||||
console.error("❌ 退菜小票打印失败:", printer.address, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -169,11 +169,17 @@ export const useSocket = defineStore("socket", {
|
||||
}
|
||||
}
|
||||
} else if (data.data_type == "order") {
|
||||
goodsStore.successClearCart();
|
||||
goodsStore.historyOrderAjax(data.data.table_code);
|
||||
this.cartInit();
|
||||
|
||||
|
||||
// 收到订单消息,打印订单小票
|
||||
let orderInfo = data.data.split("_");
|
||||
let orderId = orderInfo[0]; // 订单ID
|
||||
let orderModel = orderInfo[1]; // 订单类型
|
||||
let orderStatus = orderInfo[2]; // 订单状态
|
||||
let orderStatus = orderInfo[2]; // 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成_第几次下单
|
||||
let placeNum = orderInfo[3]; // 下单次数
|
||||
|
||||
let printList = useStorage.get("printList") || [];
|
||||
|
||||
@@ -189,6 +195,35 @@ export const useSocket = defineStore("socket", {
|
||||
this.orderList.push(orderId);
|
||||
this.startPrintInterval();
|
||||
}
|
||||
|
||||
// 防止重复打印客看单
|
||||
if (orderStatus == 0) {
|
||||
getOrderByIdAjax(orderId).then(res => {
|
||||
let originOrderInfo = res
|
||||
originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum);
|
||||
|
||||
console.log('originOrderInfo', originOrderInfo);
|
||||
|
||||
let amout = 0
|
||||
originOrderInfo.detailMap.flat().forEach(item => {
|
||||
amout += item.num * item.unitPrice
|
||||
});
|
||||
|
||||
originOrderInfo.originAmount = amout
|
||||
|
||||
if (originOrderInfo.placeNum == 1 && originOrderInfo.dineMode == 'dine-in') {
|
||||
originOrderInfo.originAmount += originOrderInfo.seatAmount
|
||||
}
|
||||
|
||||
if (originOrderInfo.packFee > 0) {
|
||||
originOrderInfo.originAmount += originOrderInfo.packFee
|
||||
}
|
||||
|
||||
printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: false }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
} else if (data.data_type == "product_update") {
|
||||
// 商品更新
|
||||
this.updateGoods();
|
||||
|
||||
@@ -184,12 +184,19 @@ export function commOrderPrintData(orderInfo) {
|
||||
if (orderInfo.isGuest) {
|
||||
// 如果是客看单,只展示当前下单的菜品
|
||||
orderInfo.detailMap[0].map((item) => {
|
||||
let price = 0
|
||||
if (item.discountSaleAmount > 0) {
|
||||
price = item.discountSaleAmount
|
||||
} else {
|
||||
price = item.price
|
||||
}
|
||||
|
||||
data.carts.push({
|
||||
categoryId: item.categoryId,
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
name: item.isGift === 1 ? `[赠]${item.productName}` : item.productName,
|
||||
number: item.num - item.returnNum,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.price),
|
||||
salePrice: formatDecimal(+price),
|
||||
totalAmount: formatDecimal(+item.payAmount),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
@@ -198,13 +205,19 @@ export function commOrderPrintData(orderInfo) {
|
||||
});
|
||||
} else {
|
||||
orderInfo.cartList.map((item) => {
|
||||
let price = 0
|
||||
if (item.discountSaleAmount > 0) {
|
||||
price = item.discountSaleAmount
|
||||
} else {
|
||||
price = item.price
|
||||
}
|
||||
data.carts.push({
|
||||
categoryId: item.categoryId,
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
name: item.isGift === 1 ? `[赠]${item.productName}` : item.productName,
|
||||
number: item.num - item.returnNum,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.price),
|
||||
totalAmount: formatDecimal(+item.payAmount),
|
||||
salePrice: formatDecimal(+price),
|
||||
totalAmount: formatDecimal((item.num - item.returnNum) * price),
|
||||
proGroupInfo: item.proGroupInfo
|
||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||
: "",
|
||||
@@ -212,23 +225,41 @@ export function commOrderPrintData(orderInfo) {
|
||||
});
|
||||
}
|
||||
|
||||
if (orderInfo.seatAmount > 0) {
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '餐位费',
|
||||
number: orderInfo.seatNum,
|
||||
skuName: '',
|
||||
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||
totalAmount: orderInfo.seatAmount,
|
||||
proGroupInfo: "",
|
||||
})
|
||||
if (orderInfo.dineMode == 'dine-in') {
|
||||
if (orderInfo.seatAmount > 0 && orderInfo.isGuest && orderInfo.placeNum == 1 && !orderInfo.isRefundDish) {
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '餐位费',
|
||||
number: orderInfo.seatNum,
|
||||
skuName: '',
|
||||
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||
totalAmount: orderInfo.seatAmount,
|
||||
proGroupInfo: "",
|
||||
})
|
||||
}
|
||||
|
||||
if (orderInfo.seatAmount > 0 && !orderInfo.isGuest && !orderInfo.isRefundDish) {
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '餐位费',
|
||||
number: orderInfo.seatNum,
|
||||
skuName: '',
|
||||
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||
totalAmount: orderInfo.seatAmount,
|
||||
proGroupInfo: "",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (orderInfo.packFee > 0) {
|
||||
if (orderInfo.packFee > 0 && !orderInfo.isRefundDish) {
|
||||
let packNum = 0;
|
||||
orderInfo.cartList.forEach(item => {
|
||||
packNum += item.packNumber
|
||||
})
|
||||
data.carts.push({
|
||||
categoryId: '',
|
||||
name: '打包费',
|
||||
number: '',
|
||||
number: packNum,
|
||||
skuName: '',
|
||||
salePrice: '',
|
||||
totalAmount: formatDecimal(orderInfo.packFee),
|
||||
@@ -236,6 +267,7 @@ export function commOrderPrintData(orderInfo) {
|
||||
})
|
||||
}
|
||||
|
||||
console.log('最终组合打印数据===', data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -262,11 +262,12 @@ import { inputFilterFloat, formatDecimal, getOrderByIdAjax, commOrderPrintData }
|
||||
import { refundOrder } from '@/api/order.js'
|
||||
import { useSocket } from '@/store/socket.js'
|
||||
import { usePrint } from '@/store/print.js'
|
||||
import { useUser } from '@/store/user.js'
|
||||
|
||||
const goodsStore = useGoods()
|
||||
const socket = useSocket()
|
||||
const printStore = usePrint()
|
||||
|
||||
const store = useUser()
|
||||
const tableMergingRef = ref(null)
|
||||
|
||||
const props = defineProps({
|
||||
@@ -337,7 +338,9 @@ async function returnOrderItemAjax(num = 1) {
|
||||
returnAmount: goodsStore.cartOrderItem.lowPrice,
|
||||
num: num
|
||||
}
|
||||
]
|
||||
],
|
||||
operator: store.userInfo.name || store.shopInfo.shopName,
|
||||
print: printStore.deviceNoteList.length ? false : true
|
||||
}
|
||||
await refundOrder(data)
|
||||
goodsStore.cartOrderItem.returnNum += num
|
||||
@@ -345,19 +348,13 @@ async function returnOrderItemAjax(num = 1) {
|
||||
|
||||
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
|
||||
originOrderInfo.cartList[0].num = num
|
||||
originOrderInfo.cartList[0].returnNum = 0
|
||||
originOrderInfo.cartList[0].payAmount = num * originOrderInfo.cartList[0].price
|
||||
|
||||
printStore.printRefund(commOrderPrintData({ ...originOrderInfo, isGuest: false, isBefore: false, title: '退菜单' }));
|
||||
printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
|
||||
@@ -204,14 +204,55 @@ const printHandle = _.throttle(async function () {
|
||||
await printOrderLable(true)
|
||||
}, 1500, { leading: true, trailing: false })
|
||||
|
||||
|
||||
// 在 usePrint 的 actions 中添加(比如放在 pushReceiptData 方法下方)
|
||||
function 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; // 返回所有菜品的总价总和
|
||||
}
|
||||
|
||||
// 打印订单标签
|
||||
async function printOrderLable(isBefore = false) {
|
||||
try {
|
||||
let orderId = goodsStore.orderListInfo.id
|
||||
const data = await getOrderByIdAjax(orderId);
|
||||
let data = await getOrderByIdAjax(orderId);
|
||||
|
||||
console.log(`打印订单标签数据${isBefore}===`, data);
|
||||
|
||||
if (isBefore) {
|
||||
data.originAmount = calcAllCartsTotalSum(data.detailMap)
|
||||
}
|
||||
|
||||
if (data.seatAmount > 0 && data.dineMode == 'dine-in' && isBefore) {
|
||||
data.originAmount += data.seatAmount
|
||||
}
|
||||
|
||||
let packFee = 0
|
||||
|
||||
data.cartList.forEach(item => {
|
||||
packFee += item.num - item.returnNum * item.packAmount
|
||||
})
|
||||
|
||||
if (packFee > 0 && isBefore) {
|
||||
data.originAmount += packFee
|
||||
data.packFee = packFee
|
||||
}
|
||||
|
||||
let printList = useStorage.get("printList") || [];
|
||||
|
||||
console.log('printStore.deviceNoteList.length:', printStore.deviceNoteList.length);
|
||||
|
||||
// 防止重复打印
|
||||
if (!printList.some((el) => el == orderId)) {
|
||||
if (!isBefore) {
|
||||
@@ -225,7 +266,7 @@ async function printOrderLable(isBefore = false) {
|
||||
printStore.labelPrint(commOrderPrintData(data))
|
||||
}
|
||||
}
|
||||
|
||||
console.log('printStore.deviceNoteList', printStore.deviceNoteList);
|
||||
if (printStore.deviceNoteList.length) {
|
||||
// 使用本地打印机打印
|
||||
printStore.pushReceiptData(commOrderPrintData({ ...data, isBefore: isBefore }));
|
||||
@@ -248,7 +289,7 @@ async function printOrderLable(isBefore = false) {
|
||||
|
||||
// 订单已支付
|
||||
function paySuccess() {
|
||||
// if (isPrint.value) printOrderLable()
|
||||
if (isPrint.value) printOrderLable()
|
||||
emits('success')
|
||||
dialogVisible.value = false;
|
||||
ElMessage.success('支付成功')
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- 备注 -->
|
||||
<remarkModal ref="remarkRef" @success="(e) => (remark = e)" />
|
||||
<remarkModal ref="remarkRef" @success="(e) => (goodsStore.remark = e)" />
|
||||
<!-- 修改取餐号 -->
|
||||
<takeFoodCode />
|
||||
<el-drawer v-model="membershow" :with-header="true" size="90%" title="选择会员">
|
||||
@@ -197,7 +197,7 @@
|
||||
</el-drawer>
|
||||
<!-- <takeFoodCode ref="takeFoodCodeRef" title="修改取餐号" placeholder="请输入取餐号" @success="takeFoodCodeSuccess" /> -->
|
||||
<!-- 结算订单 -->
|
||||
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="cartInfo.totalAmount" :remark="remark"
|
||||
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="cartInfo.totalAmount" :remark="goodsStore.remark"
|
||||
:orderInfo="orderInfo" @success="" />
|
||||
<!-- 快捷收银 -->
|
||||
<fastCashier ref="fastCashierRef" type="0" />
|
||||
@@ -253,7 +253,6 @@ const pendingCartModalRef = ref(null);
|
||||
const settleAccountRef = ref(null);
|
||||
const fastCashierRef = ref(null);
|
||||
const tableMergingRef = ref(null)
|
||||
const remark = ref("");
|
||||
const cartListActive = ref(0);
|
||||
const cartListActiveItem = ref({})
|
||||
const cartList = ref([]);
|
||||
@@ -310,7 +309,7 @@ async function createOrderHandle(t = 0) {
|
||||
originAmount: goodsStore.cartInfo.costSummary.goodsOriginalAmount,
|
||||
tableCode: goodsStore.cartList[0].table_code, // 台桌号
|
||||
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||
remark: remark.value, // 备注
|
||||
remark: goodsStore.remark, // 备注
|
||||
placeNum: placeNum + 1, // 下单次数
|
||||
waitCall: 0, // 是否叫号
|
||||
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||
@@ -331,16 +330,31 @@ async function createOrderHandle(t = 0) {
|
||||
} else {
|
||||
goodsStore.clearCart()
|
||||
// 开始打印客看单,可看单需要剔除其他历史下单
|
||||
getOrderByIdAjax(res.id).then(res => {
|
||||
let originOrderInfo = res
|
||||
originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum + 1);
|
||||
// getOrderByIdAjax(res.id).then(res => {
|
||||
// let originOrderInfo = res
|
||||
// originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum + 1);
|
||||
|
||||
console.log('originOrderInfo', originOrderInfo);
|
||||
// console.log('originOrderInfo', originOrderInfo);
|
||||
|
||||
printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: true }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
// let amout = 0
|
||||
// originOrderInfo.detailMap.flat().forEach(item => {
|
||||
// amout += item.num * item.unitPrice
|
||||
// });
|
||||
|
||||
// originOrderInfo.originAmount = amout
|
||||
|
||||
// if (originOrderInfo.placeNum == 1 && originOrderInfo.dineMode == 'dine-in') {
|
||||
// originOrderInfo.originAmount += originOrderInfo.seatAmount
|
||||
// }
|
||||
|
||||
// if (originOrderInfo.packFee > 0) {
|
||||
// originOrderInfo.originAmount += originOrderInfo.packFee
|
||||
// }
|
||||
|
||||
// printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: false }));
|
||||
// }).catch(err => {
|
||||
// console.log(err);
|
||||
// })
|
||||
}
|
||||
// 清除购物车,更新历史订单
|
||||
goodsStore.updateOrderList()
|
||||
|
||||
@@ -30,11 +30,16 @@
|
||||
<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">
|
||||
<el-table-column label="到期时间" prop="expTime"></el-table-column>
|
||||
<el-table-column label="操作" width="250">
|
||||
<template #default="{ row }">
|
||||
<el-button type="danger" :disabled="row.num <= 0"
|
||||
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">取酒</el-button>
|
||||
<el-button type="primary" @click="viewRecord(row)">查看记录</el-button>
|
||||
<el-button type="danger" :disabled="isExpired(row.expTime) || row.num <= 0"
|
||||
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">
|
||||
<span v-if="isExpired(row.expTime) || row.status == 2">已过期</span>
|
||||
<span v-else-if="row.num <= 0">已取完</span>
|
||||
<span v-else>取酒</span>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -85,12 +90,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!-- 存取酒记录弹窗 -->
|
||||
<el-dialog title="记录" width="600px" v-model="showRecordDialogVisible">
|
||||
<el-table :data="recordList" border stripe>
|
||||
<el-table-column label="记录" prop="content"></el-table-column>
|
||||
<el-table-column label="操作时间" prop="time"></el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut } from '@/api/product_new'
|
||||
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut, shopStorageRecord } from '@/api/product_new'
|
||||
|
||||
const props = defineProps({
|
||||
userInfo: {
|
||||
@@ -214,6 +226,30 @@ function init() {
|
||||
list.value = [];
|
||||
}
|
||||
|
||||
function isExpired(expTime) {
|
||||
if (!expTime) return false;
|
||||
const now = new Date();
|
||||
const expDate = new Date(expTime);
|
||||
return expDate < now;
|
||||
}
|
||||
|
||||
// 查看记录
|
||||
const showRecordDialogVisible = ref(false);
|
||||
const recordList = ref([]);
|
||||
async function viewRecord(row) {
|
||||
try {
|
||||
showRecordDialogVisible.value = true;
|
||||
const res = await shopStorageRecord({
|
||||
id: row.id,
|
||||
page: 1,
|
||||
size: 999,
|
||||
});
|
||||
recordList.value = res || [];
|
||||
} catch (error) {
|
||||
console.error('获取存取酒记录失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function show() {
|
||||
init();
|
||||
drawerVisible.value = true;
|
||||
|
||||
@@ -174,15 +174,15 @@ async function passwordSuccess(e = '') {
|
||||
loading.value = true
|
||||
let rows = tableRef.value.getSelectionRows()
|
||||
let refundDetails = []
|
||||
if (refundType.value != 1) {
|
||||
refundDetails = tableRef.value.getSelectionRows().map(val => {
|
||||
return {
|
||||
id: val.id,
|
||||
returnAmount: val.payAmount,
|
||||
num: val.refund_number
|
||||
}
|
||||
})
|
||||
}
|
||||
// if (refundType.value != 1) {
|
||||
refundDetails = tableRef.value.getSelectionRows().map(val => {
|
||||
return {
|
||||
id: val.id,
|
||||
returnAmount: val.payAmount,
|
||||
num: val.refund_number
|
||||
}
|
||||
})
|
||||
// }
|
||||
|
||||
let data = {
|
||||
orderId: item.value.id,
|
||||
@@ -192,6 +192,8 @@ async function passwordSuccess(e = '') {
|
||||
refundReason: remark.value,
|
||||
refundDetails: refundDetails,
|
||||
pwd: e,
|
||||
operator: store.userInfo.name || store.shopInfo.shopName,
|
||||
print: printStore.deviceNoteList.length ? false : true
|
||||
};
|
||||
|
||||
await refundOrder(data)
|
||||
@@ -269,7 +271,7 @@ async function printRefund(rows) {
|
||||
orderInfo: item.value,
|
||||
outNumber: item.value.id,
|
||||
createdAt: item.value.createTime,
|
||||
refundMethod: cash.value ? '现金' : '原路退回',
|
||||
refundMethod: cash.value ? '线下退款' : '原路退回',
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
}
|
||||
|
||||
@@ -277,10 +279,10 @@ async function printRefund(rows) {
|
||||
data.carts.push(
|
||||
{
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
number: item.refund_number,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.unitPrice),
|
||||
totalAmount: formatDecimal(+item.payAmount)
|
||||
totalAmount: formatDecimal(+item.unitPrice * item.refund_number)
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -288,8 +290,8 @@ async function printRefund(rows) {
|
||||
printStore.printRefund(data);
|
||||
} else {
|
||||
// 云打印
|
||||
await orderPrint({ id: item.value.id, type: 2 })
|
||||
ElMessage.success('云打印退款单成功')
|
||||
// await orderPrint({ id: item.value.id, type: 2 })
|
||||
// ElMessage.success('云打印退款单成功')
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
<div class="box_content_left_top_item_top">
|
||||
<div style="color:#ff5252; font-size: 30px;">
|
||||
¥{{ formatDecimal(infoData.handAmount || 0) }}
|
||||
¥{{ formatDecimal(infoData.orderTurnover || 0) }}
|
||||
</div>
|
||||
<div style="margin-top: 6px; color: #666;">
|
||||
营业额
|
||||
@@ -36,7 +36,7 @@
|
||||
<div class="box_content_left_top_item">
|
||||
<div class="box_content_left_top_item_botton">
|
||||
<div style=" font-size: 20px;">
|
||||
¥{{ formatDecimal(infoData.cashAmount || 0) }}
|
||||
¥{{ formatDecimal(infoData.cash || 0) }}
|
||||
</div>
|
||||
<div style="margin-top: 6px;">
|
||||
现金支付
|
||||
@@ -179,26 +179,18 @@ 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 = '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));
|
||||
|
||||
await handover(printStore.deviceNoteList.length ? 0 : 1)
|
||||
if (printStore.deviceNoteList.length) {
|
||||
printStore.printWork(infoData.value)
|
||||
// 使用本地打印机 打印交班数据
|
||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
data.printShop = isPrint.value
|
||||
printStore.printWork(data)
|
||||
} else {
|
||||
// 使用云打印机 打印交班数据
|
||||
await handoverNetworkPrint(data.id)
|
||||
// data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
// data.printShop = isPrint.value
|
||||
}
|
||||
// logoutHandle()
|
||||
// else {
|
||||
// // 使用云打印机 打印交班数据
|
||||
// await handoverNetworkPrint(data.id)
|
||||
// }
|
||||
logoutHandle()
|
||||
loading.value = false;
|
||||
} catch (error) {
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user