优化小票 新增存酒管理

This commit is contained in:
gyq
2026-04-03 15:35:48 +08:00
parent c3a20ab2db
commit 78e88b8eb7
15 changed files with 1622 additions and 28138 deletions

View File

@@ -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,
});
}

View File

@@ -6,8 +6,8 @@ const routes = [
{
path: "/",
name: "home",
component: test,
// component: home,
// component: test,
component: home,
},
{
path: "/login",

View File

@@ -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
View 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("退单小票:未在本机查询到打印机");
}
},
},
});

View File

@@ -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: '餐位费',

View File

@@ -45,6 +45,12 @@
</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>
@@ -182,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);

View File

@@ -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);

View File

@@ -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()

View 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>

View File

@@ -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: '',

View File

@@ -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"),
}

View File

@@ -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);