Compare commits
7 Commits
78e88b8eb7
...
prod
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e03547798 | |||
| e0aba58651 | |||
| d19e1688a5 | |||
| 23b8db63b8 | |||
| c9cd3a80d9 | |||
| a5fdbd0c13 | |||
| 32d150fd15 |
File diff suppressed because one or more lines are too long
@@ -5,7 +5,6 @@ import axios from "axios";
|
|||||||
import os from "os";
|
import os from "os";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { exec } from "child_process";
|
import { exec } from "child_process";
|
||||||
import { printReceipt, printHandoverReceipt, printRefund } from "./printService";
|
|
||||||
|
|
||||||
// ===== 核心配置:单文件缓存 =====
|
// ===== 核心配置:单文件缓存 =====
|
||||||
// 固定的缓存文件路径(永远只存这1个文件)
|
// 固定的缓存文件路径(永远只存这1个文件)
|
||||||
@@ -107,46 +106,6 @@ app.whenReady().then(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 打印结算小票
|
|
||||||
ipcMain.on('networkPrint', async (event, arg) => {
|
|
||||||
try {
|
|
||||||
let _parmas = JSON.parse(arg);
|
|
||||||
console.log(_parmas);
|
|
||||||
console.log(_parmas.orderData.carts);
|
|
||||||
await printReceipt(_parmas.printerIp, _parmas.orderData);
|
|
||||||
return { ok: true }
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
return { ok: false, msg: e.message }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 打印交班小票
|
|
||||||
ipcMain.on('printHandoverReceipt', async (event, arg) => {
|
|
||||||
try {
|
|
||||||
let _parmas = JSON.parse(arg);
|
|
||||||
console.log(_parmas);
|
|
||||||
await printHandoverReceipt(_parmas.printerIp, _parmas.handoverData);
|
|
||||||
return { ok: true }
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
return { ok: false, msg: e.message }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 打印退菜单/退款小票
|
|
||||||
ipcMain.on('printRefund', async (event, arg) => {
|
|
||||||
try {
|
|
||||||
let _parmas = JSON.parse(arg);
|
|
||||||
// console.log(_parmas);
|
|
||||||
await printRefund(_parmas.printerIp, _parmas.orderData);
|
|
||||||
return { ok: true }
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
return { ok: false, msg: e.message }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on("activate", () => {
|
app.on("activate", () => {
|
||||||
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
// 在 macOS 系统内, 如果没有已开启的应用窗口
|
||||||
// 点击托盘图标时通常会重新创建一个新窗口
|
// 点击托盘图标时通常会重新创建一个新窗口
|
||||||
|
|||||||
@@ -1,529 +0,0 @@
|
|||||||
// 网口打印机管理(80mm 终极美化版 · 无多余间距最终版)
|
|
||||||
import net from 'net'
|
|
||||||
import iconv from 'iconv-lite'
|
|
||||||
|
|
||||||
// ======================== 全局工具函数 ========================
|
|
||||||
const getPrintWidth = (str) => {
|
|
||||||
let width = 0
|
|
||||||
const s = String(str || '')
|
|
||||||
for (let i = 0; i < s.length; i++) {
|
|
||||||
const char = s.charAt(i)
|
|
||||||
if (/[\u4e00-\u9fa5\u3000-\u303f\uff00-\uffef]/.test(char)) {
|
|
||||||
width += 2
|
|
||||||
} else {
|
|
||||||
width += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return width
|
|
||||||
}
|
|
||||||
|
|
||||||
const padLeftAlign = (str, targetWidth) => {
|
|
||||||
const s = String(str || '')
|
|
||||||
const currentWidth = getPrintWidth(s)
|
|
||||||
const spaceNum = Math.max(0, targetWidth - currentWidth)
|
|
||||||
return s + ' '.repeat(spaceNum)
|
|
||||||
}
|
|
||||||
|
|
||||||
const padRightAlign = (str, targetWidth) => {
|
|
||||||
const s = String(str || '')
|
|
||||||
const currentWidth = getPrintWidth(s)
|
|
||||||
const spaceNum = Math.max(0, targetWidth - currentWidth)
|
|
||||||
return ' '.repeat(spaceNum) + s
|
|
||||||
}
|
|
||||||
|
|
||||||
const truncateByPrintWidth = (str, maxWidth) => {
|
|
||||||
const s = String(str || '')
|
|
||||||
let width = 0
|
|
||||||
let result = ''
|
|
||||||
for (const char of s) {
|
|
||||||
const charWidth = /[\u4e00-\u9fa5\u3000-\u303f\uff00-\uffef]/.test(char) ? 2 : 1
|
|
||||||
if (width + charWidth > maxWidth) break
|
|
||||||
result += char
|
|
||||||
width += charWidth
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
const centerAlign = (str, lineWidth = 48) => {
|
|
||||||
const s = String(str || '').trim(); // 去除首尾空格,避免干扰
|
|
||||||
const currentWidth = getPrintWidth(s);
|
|
||||||
if (currentWidth >= lineWidth) return s; // 内容超宽时直接返回,不居中
|
|
||||||
|
|
||||||
const totalPad = lineWidth - currentWidth;
|
|
||||||
const leftPad = Math.floor(totalPad / 2);
|
|
||||||
const rightPad = totalPad - leftPad; // 避免奇数宽度时总长度超行宽
|
|
||||||
|
|
||||||
// 用空格填充左右,保证总宽度严格等于 lineWidth
|
|
||||||
return ' '.repeat(leftPad) + s + ' '.repeat(rightPad);
|
|
||||||
};
|
|
||||||
|
|
||||||
const createDivider = (lineWidth = 48, type = 'full') => {
|
|
||||||
const fullChar = '═'
|
|
||||||
const thinChar = '─'
|
|
||||||
const char = type === 'full' ? fullChar : thinChar
|
|
||||||
return char.repeat(Math.ceil(lineWidth / 2)).substring(0, lineWidth)
|
|
||||||
}
|
|
||||||
|
|
||||||
const setupPrinter = (socket, options = {}) => {
|
|
||||||
socket.write(Buffer.from([0x1B, 0x40]))
|
|
||||||
if (options.fontSize) {
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, options.fontSize]))
|
|
||||||
}
|
|
||||||
if (options.bold) {
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, options.bold ? 0x01 : 0x00]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 用餐模式 堂食 dine-in 外带 take-out 外卖 take-away
|
|
||||||
const dineModeFilter = t => {
|
|
||||||
if (t === 'dine-in') return '堂食'
|
|
||||||
if (t === 'take-out') return '外带'
|
|
||||||
if (t === 'take-away') return '外卖'
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======================== 打印结算小票 ========================
|
|
||||||
export function printReceipt(printerIp, order) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const socket = new net.Socket()
|
|
||||||
const lineWidth = 48
|
|
||||||
socket.setTimeout(8000)
|
|
||||||
|
|
||||||
const formatAmount = (amount) => Number(amount || 0).toFixed(2)
|
|
||||||
|
|
||||||
socket.connect(9100, printerIp, () => {
|
|
||||||
try {
|
|
||||||
setupPrinter(socket)
|
|
||||||
|
|
||||||
// ======================== 标题区域(彻底修复居中问题!) ========================
|
|
||||||
const title1 = order.shop_name || '';
|
|
||||||
let title2 = `结算单 #${order.orderInfo.orderNum}`
|
|
||||||
if (order.isBefore && !order.isGuest) {
|
|
||||||
title2 = `${order.isBefore ? '预' : ''}结算单 #${order.orderInfo.orderNum}`;
|
|
||||||
}
|
|
||||||
if (order.isGuest && order.isBefore) {
|
|
||||||
title2 = `客看单 #${order.orderInfo.orderNum}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
|
||||||
socket.write(iconv.encode('\n', 'gbk'));
|
|
||||||
|
|
||||||
// 步骤1:重置打印机格式(避免残留格式影响)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x40]));
|
|
||||||
// 步骤2:居中对齐标题
|
|
||||||
socket.write(Buffer.from([0x1B, 0x61, 0x01])); // 1 = center
|
|
||||||
// 步骤3:设置标题1的格式(加粗+大号字体)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 字号放大(0x11 是常用放大值)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(title1 + '\n', 'gbk'));
|
|
||||||
|
|
||||||
// 步骤4:恢复格式,打印标题2(常规字体)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
socket.write(iconv.encode(title2 + '\n\n', 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x61, 0x00])); // 0 = left
|
|
||||||
|
|
||||||
// ======================== 订单信息(修复显示+换行问题) ========================
|
|
||||||
const tableLine = padLeftAlign('桌台号:', 8) + padLeftAlign(order.orderInfo.tableName || '无', 14) + '\n'
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 正常字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(tableLine, 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
|
|
||||||
let orderInfo = ''
|
|
||||||
|
|
||||||
// 修复:打印机-用餐模式 + 就餐人数 展示逻辑
|
|
||||||
const dineModeText = dineModeFilter(order.orderInfo.dineMode)
|
|
||||||
// 1. 拼接打印机+用餐模式文本,空值兜底
|
|
||||||
const printerDineText = `${order.printerName || '未知打印机'}-${dineModeText || '未知模式'}`
|
|
||||||
// 2. 截断超长文本(左侧分配20宽度,保证不超限)
|
|
||||||
const truncatedPrinterDine = truncateByPrintWidth(printerDineText, 20)
|
|
||||||
// 3. 左侧左对齐填充20宽度(保证占满分配空间,不浪费空白)
|
|
||||||
const leftPart = padLeftAlign(truncatedPrinterDine, 20)
|
|
||||||
// 4. 右侧就餐人数:空值兜底为“无”,右对齐填充28宽度(20+28=48,刚好行宽)
|
|
||||||
const seatNumText = order.orderInfo.seatNum || '0'
|
|
||||||
const rightPart = padRightAlign(`${seatNumText}人`, 28) // 加标签更清晰,也可只显示数字
|
|
||||||
|
|
||||||
orderInfo += leftPart + rightPart + '\n'
|
|
||||||
if (!order.isBefore) {
|
|
||||||
orderInfo += padLeftAlign('结账时间:', 10) + padLeftAlign(order.createdAt || '-', 38) + '\n'
|
|
||||||
}
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
// ======================== 商品表格 ========================
|
|
||||||
orderInfo += padLeftAlign('品名', 18)
|
|
||||||
orderInfo += padLeftAlign('单价', 8)
|
|
||||||
orderInfo += padLeftAlign('数量', 6)
|
|
||||||
orderInfo += padRightAlign('小计', 16) + '\n'
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
order.carts.forEach(item => {
|
|
||||||
const name = truncateByPrintWidth(item.name || '未知商品', 18)
|
|
||||||
const price = formatAmount(item.salePrice)
|
|
||||||
const num = item.number || 1
|
|
||||||
const total = formatAmount(item.totalAmount)
|
|
||||||
orderInfo += padLeftAlign(name, 18)
|
|
||||||
orderInfo += padLeftAlign(price, 8)
|
|
||||||
orderInfo += padLeftAlign(num, 6)
|
|
||||||
orderInfo += padRightAlign(total, 16) + '\n'
|
|
||||||
})
|
|
||||||
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
orderInfo += padLeftAlign('原价', 10) + padRightAlign(formatAmount(order.originAmount), 38) + '\n'
|
|
||||||
orderInfo += padLeftAlign('优惠金额', 10) + padRightAlign(`-${formatAmount(order.discountAllAmount)}`, 38) + '\n'
|
|
||||||
orderInfo += padLeftAlign('备注:', 6) + padLeftAlign(order.remark || '无', 38) + '\n'
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
socket.write(iconv.encode(orderInfo, 'gbk'))
|
|
||||||
|
|
||||||
// ======================== 付款信息 ========================
|
|
||||||
const payableLine = padLeftAlign('应付', 10) + padRightAlign(formatAmount(order.originAmount), 51) + '\n'
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 放大字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(payableLine, 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
|
||||||
if (!order.isBefore) {
|
|
||||||
const paidLine = padLeftAlign('已付', 10) + padRightAlign(formatAmount(order.orderInfo.payAmount), 51) + '\n'
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x11]));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01]));
|
|
||||||
socket.write(iconv.encode(paidLine, 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00]));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00]));
|
|
||||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======================== 底部 ========================
|
|
||||||
let bottom = ''
|
|
||||||
bottom += padLeftAlign('操作员:', 8) + padLeftAlign(order.loginAccount || '无', 38) + '\n'
|
|
||||||
bottom += padLeftAlign('打印时间:', 10) + padLeftAlign(new Date().toLocaleString(), 38) + '\n'
|
|
||||||
bottom += padLeftAlign('订单号:', 8) + padLeftAlign(order.orderInfo.orderNo || '-', 38) + '\n'
|
|
||||||
bottom += createDivider(lineWidth, 'full') + '\n'
|
|
||||||
bottom += '\n\n'
|
|
||||||
bottom += '\n\n'
|
|
||||||
|
|
||||||
socket.write(iconv.encode(bottom, 'gbk'))
|
|
||||||
socket.write(Buffer.from([0x1D, 0x56, 0x00]))
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
socket.end()
|
|
||||||
resolve('success')
|
|
||||||
}, 400)
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
socket.destroy()
|
|
||||||
resolve('error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('error', () => resolve('error'))
|
|
||||||
socket.on('timeout', () => resolve('timeout'))
|
|
||||||
socket.on('close', () => { })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ======================== 打印退菜单/退款小票 ========================
|
|
||||||
export function printRefund(printerIp, order) {
|
|
||||||
console.log(JSON.stringify(order));
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const socket = new net.Socket()
|
|
||||||
const lineWidth = 48
|
|
||||||
socket.setTimeout(8000)
|
|
||||||
|
|
||||||
const formatAmount = (amount) => Number(amount || 0).toFixed(2)
|
|
||||||
|
|
||||||
socket.connect(9100, printerIp, () => {
|
|
||||||
try {
|
|
||||||
setupPrinter(socket)
|
|
||||||
|
|
||||||
// ======================== 标题区域(彻底修复居中问题!) ========================
|
|
||||||
const title1 = order.shop_name || '';
|
|
||||||
let title2 = order.title || '退款单'
|
|
||||||
|
|
||||||
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
|
||||||
socket.write(iconv.encode('\n', 'gbk'));
|
|
||||||
|
|
||||||
// 步骤1:重置打印机格式(避免残留格式影响)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x40]));
|
|
||||||
// 步骤2:居中对齐标题
|
|
||||||
socket.write(Buffer.from([0x1B, 0x61, 0x01])); // 1 = center
|
|
||||||
// 步骤3:设置标题1的格式(加粗+大号字体)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 字号放大(0x11 是常用放大值)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(title1 + '\n', 'gbk'));
|
|
||||||
|
|
||||||
// 步骤4:恢复格式,打印标题2(常规字体)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
socket.write(iconv.encode(title2 + '\n\n', 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x61, 0x00])); // 0 = left
|
|
||||||
|
|
||||||
// ======================== 订单信息(修复显示+换行问题) ========================
|
|
||||||
const tableLine = padLeftAlign('桌台号:', 8) + padLeftAlign(order.orderInfo.tableName || '无', 14) + '\n'
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 正常字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(tableLine, 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
|
|
||||||
let orderInfo = ''
|
|
||||||
|
|
||||||
// 修复:打印机-用餐模式 + 就餐人数 展示逻辑
|
|
||||||
const dineModeText = dineModeFilter(order.orderInfo.dineMode)
|
|
||||||
// 1. 拼接打印机+用餐模式文本,空值兜底
|
|
||||||
const printerDineText = `${order.printerName || '未知打印机'}-${dineModeText || '未知模式'}`
|
|
||||||
// 2. 截断超长文本(左侧分配20宽度,保证不超限)
|
|
||||||
const truncatedPrinterDine = truncateByPrintWidth(printerDineText, 20)
|
|
||||||
// 3. 左侧左对齐填充20宽度(保证占满分配空间,不浪费空白)
|
|
||||||
const leftPart = padLeftAlign(truncatedPrinterDine, 20)
|
|
||||||
// 4. 右侧就餐人数:空值兜底为“无”,右对齐填充28宽度(20+28=48,刚好行宽)
|
|
||||||
const seatNumText = order.orderInfo.seatNum || '0'
|
|
||||||
const rightPart = padRightAlign(`${seatNumText}人`, 28) // 加标签更清晰,也可只显示数字
|
|
||||||
|
|
||||||
if (order.carts.length > 0) {
|
|
||||||
orderInfo += leftPart + rightPart + '\n'
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
// ======================== 商品表格 ========================
|
|
||||||
orderInfo += padLeftAlign('品名', 18)
|
|
||||||
orderInfo += padLeftAlign('单价', 8)
|
|
||||||
orderInfo += padLeftAlign('数量', 6)
|
|
||||||
orderInfo += padRightAlign('小计', 16) + '\n'
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
order.carts.forEach(item => {
|
|
||||||
const name = truncateByPrintWidth(item.name || '未知商品', 18)
|
|
||||||
const price = formatAmount(item.salePrice)
|
|
||||||
const num = item.number || 1
|
|
||||||
const total = formatAmount(item.totalAmount)
|
|
||||||
orderInfo += padLeftAlign(name, 18)
|
|
||||||
orderInfo += padLeftAlign(price, 8)
|
|
||||||
orderInfo += padLeftAlign(num, 6)
|
|
||||||
orderInfo += padRightAlign(total, 16) + '\n'
|
|
||||||
})
|
|
||||||
|
|
||||||
orderInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
socket.write(iconv.encode(orderInfo, 'gbk'))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======================== 付款信息 ========================
|
|
||||||
let payableLine = ''
|
|
||||||
payableLine += padLeftAlign('退款总计', 10) + padRightAlign(formatAmount(order.amount), 51) + '\n'
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 放大字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(payableLine, 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
let refundInfo = ''
|
|
||||||
refundInfo += padLeftAlign('退款方式:', 10) + padLeftAlign(order.refundMethod || '无', 38) + '\n'
|
|
||||||
refundInfo += padLeftAlign('退款原因:', 10) + padLeftAlign(order.remark || '无', 38) + '\n'
|
|
||||||
socket.write(iconv.encode(refundInfo, 'gbk'));
|
|
||||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
|
||||||
|
|
||||||
// ======================== 底部 ========================
|
|
||||||
let bottom = ''
|
|
||||||
bottom += padLeftAlign('操作员:', 8) + padLeftAlign(order.loginAccount || '无', 38) + '\n'
|
|
||||||
bottom += padLeftAlign('打印时间:', 10) + padLeftAlign(new Date().toLocaleString(), 38) + '\n'
|
|
||||||
bottom += padLeftAlign('原订单号:', 10) + padLeftAlign(order.orderInfo.orderNo || '-', 38) + '\n'
|
|
||||||
bottom += createDivider(lineWidth, 'full') + '\n'
|
|
||||||
bottom += '\n\n'
|
|
||||||
bottom += '\n\n'
|
|
||||||
|
|
||||||
socket.write(iconv.encode(bottom, 'gbk'))
|
|
||||||
socket.write(Buffer.from([0x1D, 0x56, 0x00]))
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
socket.end()
|
|
||||||
resolve('success')
|
|
||||||
}, 400)
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
socket.destroy()
|
|
||||||
resolve('error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('error', () => resolve('error'))
|
|
||||||
socket.on('timeout', () => resolve('timeout'))
|
|
||||||
socket.on('close', () => { })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======================== 打印交班小票(完整版 · 补齐分类/商品数据) ========================
|
|
||||||
export function printHandoverReceipt(printerIp, data) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const socket = new net.Socket()
|
|
||||||
const lineWidth = 48
|
|
||||||
socket.setTimeout(8000)
|
|
||||||
|
|
||||||
const formatAmount = (v) => Number(v || 0).toFixed(2)
|
|
||||||
|
|
||||||
socket.connect(9100, printerIp, () => {
|
|
||||||
try {
|
|
||||||
setupPrinter(socket)
|
|
||||||
|
|
||||||
// ======================== 标题区域(统一结算小票的居中修复逻辑) ========================
|
|
||||||
const title1 = data.shopName || '店铺';
|
|
||||||
const title2 = '交班小票';
|
|
||||||
|
|
||||||
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
|
||||||
socket.write(iconv.encode('\n', 'gbk'));
|
|
||||||
|
|
||||||
// 步骤1:重置打印机格式(避免残留格式影响)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x40]));
|
|
||||||
// 步骤2:居中对齐标题
|
|
||||||
socket.write(Buffer.from([0x1B, 0x61, 0x01])); // 1 = center
|
|
||||||
// 步骤3:设置标题1的格式(加粗+大号字体)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x11])); // 字号放大(0x11 是常用放大值)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
socket.write(iconv.encode(title1 + '\n', 'gbk'));
|
|
||||||
|
|
||||||
// 步骤4:恢复格式,打印标题2(常规字体)
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 恢复默认字号
|
|
||||||
socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
socket.write(iconv.encode(title2 + '\n\n', 'gbk'));
|
|
||||||
socket.write(Buffer.from([0x1B, 0x61, 0x00])); // 0 = left
|
|
||||||
socket.write(iconv.encode(createDivider(lineWidth, 'thin') + '\n', 'gbk'));
|
|
||||||
|
|
||||||
// ======================== 基础信息区域(拆分当班/交班时间) ========================
|
|
||||||
let basicInfo = ''
|
|
||||||
// 优化:拆分当班时间和交班时间,空值兜底
|
|
||||||
basicInfo += padLeftAlign('交班时间:', 10) + padLeftAlign(data.handoverTime || '-', 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('收银员:', 8) + padLeftAlign(data.staffName || '-', 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('交班周期:', 10) + padLeftAlign(`${data.loginTime}-${data.handoverTime}` || '-', 36) + '\n\n'
|
|
||||||
|
|
||||||
// basicInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
// 收入明细 - 补充会员支付/充值字段
|
|
||||||
basicInfo += padLeftAlign('当班营业总额:', 10) + padLeftAlign(formatAmount(data.handAmount), 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('实际收款的支付方式', 10) + '\n'
|
|
||||||
basicInfo += padLeftAlign('现金', 10) + padRightAlign(formatAmount(data.cashAmount), 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('微信', 10) + padRightAlign(formatAmount(data.wechatAmount), 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('支付宝', 10) + padRightAlign(formatAmount(data.alipayAmount), 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('二维码收款', 10) + padRightAlign(formatAmount(data.vipPay), 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('扫码收款', 10) + padRightAlign(formatAmount(data.vipRecharge), 36) + '\n\n'
|
|
||||||
basicInfo += padLeftAlign('非实际收款的支付方式', 10) + '\n'
|
|
||||||
basicInfo += padLeftAlign('挂账', 10) + padRightAlign(formatAmount(data.creditAmount), 36) + '\n'
|
|
||||||
basicInfo += padLeftAlign('余额', 10) + padRightAlign(formatAmount(data.vipPay), 36) + '\n'
|
|
||||||
basicInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
socket.write(Buffer.from([0x1B, 0x21, 0x00])); // 正常字号
|
|
||||||
socket.write(iconv.encode(basicInfo, 'gbk'))
|
|
||||||
|
|
||||||
let refundInfo = ''
|
|
||||||
refundInfo += padLeftAlign('退款/退菜', 10) + '\n'
|
|
||||||
refundInfo += padLeftAlign('退款金额', 10) + padRightAlign(formatAmount(data.refundAmount), 36) + '\n'
|
|
||||||
refundInfo += padLeftAlign('退菜数量', 10) + padRightAlign(formatAmount(data.refundAmount), 36) + '\n'
|
|
||||||
refundInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
socket.write(iconv.encode(refundInfo, 'gbk'))
|
|
||||||
|
|
||||||
let orderInfo = ''
|
|
||||||
const orderLabel = '订单(数量/订单总额)'
|
|
||||||
const orderValue = `${data.orderCount}/${formatAmount(data.orderAmount)}`
|
|
||||||
const orderLabelWidth = lineWidth - getPrintWidth(orderValue)
|
|
||||||
orderInfo += padLeftAlign(orderLabel, orderLabelWidth) + orderValue + '\n\n'
|
|
||||||
socket.write(iconv.encode(orderInfo, 'gbk'))
|
|
||||||
|
|
||||||
// ======================== 分类数据区域 ========================
|
|
||||||
let categoryInfo = ''
|
|
||||||
if (data.categoryDataList && data.categoryDataList.length) {
|
|
||||||
categoryInfo += centerAlign('销售数据', lineWidth) + '\n'
|
|
||||||
categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
// 分类表头
|
|
||||||
categoryInfo += padLeftAlign('名称', 24) + padLeftAlign('数量', 12) + padRightAlign('总计', 12) + '\n'
|
|
||||||
// categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
// 分类数据行
|
|
||||||
data.categoryDataList.forEach(item => {
|
|
||||||
const catName = truncateByPrintWidth(item.categoryName || '未知分类', 24)
|
|
||||||
const num = item.num || 0
|
|
||||||
const amount = formatAmount(item.amount)
|
|
||||||
categoryInfo += padLeftAlign(catName, 24) + padLeftAlign(num, 12) + padRightAlign(amount, 12) + '\n'
|
|
||||||
})
|
|
||||||
categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
}
|
|
||||||
socket.write(iconv.encode(categoryInfo, 'gbk'))
|
|
||||||
|
|
||||||
// ======================== 商品数据区域 ========================
|
|
||||||
let productInfo = ''
|
|
||||||
if (data.printShop && data.productDataList && data.productDataList.length) {
|
|
||||||
productInfo += centerAlign('商品数据', lineWidth) + '\n'
|
|
||||||
productInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
// 商品表头
|
|
||||||
productInfo += padLeftAlign('商品', 36) + padRightAlign('数量', 12) + '\n'
|
|
||||||
// productInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
// 商品数据行
|
|
||||||
data.productDataList.forEach(item => {
|
|
||||||
const prodName = truncateByPrintWidth(item.productName || '未知商品', 36)
|
|
||||||
const num = item.num || 0
|
|
||||||
productInfo += padLeftAlign(prodName, 36) + padRightAlign(num, 12) + '\n'
|
|
||||||
})
|
|
||||||
productInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
}
|
|
||||||
socket.write(iconv.encode(productInfo, 'gbk'))
|
|
||||||
|
|
||||||
// ======================== 收入明细区域(优化对齐和格式) ========================
|
|
||||||
// let incomeInfo = ''
|
|
||||||
// incomeInfo += centerAlign('【收支汇总】', lineWidth) + '\n'
|
|
||||||
// incomeInfo += createDivider(lineWidth, 'thin') + '\n'
|
|
||||||
|
|
||||||
// // 收支汇总项(补充挂账金额)
|
|
||||||
// const incomeItems = [
|
|
||||||
// { label: '快捷收款金额:', val: data.quickInAmount },
|
|
||||||
// { label: '退款金额:', val: data.refundAmount },
|
|
||||||
// { label: '总收入:', val: data.handAmount },
|
|
||||||
// { label: '挂账金额:', val: data.creditAmount },
|
|
||||||
// { label: '总订单数:', val: data.orderCount || 0 }
|
|
||||||
// ]
|
|
||||||
|
|
||||||
// incomeItems.forEach((item, index) => {
|
|
||||||
// const labelPart = padLeftAlign(item.label, 16)
|
|
||||||
// let valPart = ''
|
|
||||||
// // 总收入/总订单数加粗显示
|
|
||||||
// if (index === 2 || index === 4) {
|
|
||||||
// socket.write(Buffer.from([0x1B, 0x45, 0x01])); // 加粗
|
|
||||||
// valPart = padRightAlign(index === 4 ? item.val : formatAmount(item.val), 32)
|
|
||||||
// incomeInfo += labelPart + valPart + '\n'
|
|
||||||
// socket.write(Buffer.from([0x1B, 0x45, 0x00])); // 取消加粗
|
|
||||||
// } else {
|
|
||||||
// valPart = padRightAlign(formatAmount(item.val), 32)
|
|
||||||
// incomeInfo += labelPart + valPart + '\n'
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// incomeInfo += createDivider(lineWidth, 'full') + '\n'
|
|
||||||
// socket.write(iconv.encode(incomeInfo, 'gbk'))
|
|
||||||
|
|
||||||
// ======================== 底部区域(统一结算小票风格) ========================
|
|
||||||
let bottomInfo = ''
|
|
||||||
bottomInfo += padLeftAlign('打印时间:', 12) + padRightAlign(data.printTime || new Date().toLocaleString(), 36) + '\n'
|
|
||||||
bottomInfo += createDivider(lineWidth, 'full') + '\n'
|
|
||||||
// 增加空行,避免打印内容紧贴纸边
|
|
||||||
bottomInfo += '\n\n'
|
|
||||||
bottomInfo += '\n\n'
|
|
||||||
|
|
||||||
socket.write(iconv.encode(bottomInfo, 'gbk'))
|
|
||||||
// 切纸指令(统一结算小票的切纸逻辑)
|
|
||||||
socket.write(Buffer.from([0x1D, 0x56, 0x00]))
|
|
||||||
|
|
||||||
// 统一延迟关闭连接,保证数据完整发送
|
|
||||||
setTimeout(() => {
|
|
||||||
socket.end()
|
|
||||||
resolve('success')
|
|
||||||
}, 400)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('打印交班小票异常:', err)
|
|
||||||
socket.destroy()
|
|
||||||
resolve('error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 统一错误处理(对齐结算小票的错误处理逻辑)
|
|
||||||
socket.on('error', (err) => {
|
|
||||||
console.error('打印机连接错误:', err)
|
|
||||||
resolve('error')
|
|
||||||
})
|
|
||||||
socket.on('timeout', () => resolve('timeout'))
|
|
||||||
socket.on('close', () => { })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
1145
package-lock.json
generated
1145
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "vite-electron",
|
"name": "vite-electron",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "2.0.15",
|
"version": "2.0.21",
|
||||||
"main": "dist-electron/main.js",
|
"main": "dist-electron/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "chcp 65001 && vite",
|
"dev": "chcp 65001 && vite",
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
"electron-pos-printer": "^1.3.6",
|
"electron-pos-printer": "^1.3.6",
|
||||||
"electron-pos-printer-vue": "^1.0.9",
|
"electron-pos-printer-vue": "^1.0.9",
|
||||||
"element-plus": "^2.4.3",
|
"element-plus": "^2.4.3",
|
||||||
"iconv-lite": "^0.7.2",
|
|
||||||
"js-md5": "^0.8.3",
|
"js-md5": "^0.8.3",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
@@ -31,13 +30,13 @@
|
|||||||
"uuid": "^10.0.0",
|
"uuid": "^10.0.0",
|
||||||
"vue": "^3.3.8",
|
"vue": "^3.3.8",
|
||||||
"vue-router": "^4.2.5",
|
"vue-router": "^4.2.5",
|
||||||
"win32-api": "^26.1.2",
|
|
||||||
"ysk-utils": "^1.0.84"
|
"ysk-utils": "^1.0.84"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^4.5.0",
|
"@vitejs/plugin-vue": "^4.5.0",
|
||||||
"electron": "^28.3.3",
|
"electron": "^28.3.3",
|
||||||
"electron-builder": "^24.13.3",
|
"electron-builder": "^24.13.3",
|
||||||
|
"electron-rebuild": "^3.2.9",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"sass": "^1.69.5",
|
"sass": "^1.69.5",
|
||||||
"sass-loader": "^13.3.2",
|
"sass-loader": "^13.3.2",
|
||||||
@@ -80,4 +79,4 @@
|
|||||||
"createStartMenuShortcut": true
|
"createStartMenuShortcut": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
printer.sdk.dll
BIN
printer.sdk.dll
Binary file not shown.
@@ -321,7 +321,7 @@ export function printerList(subType = "") {
|
|||||||
params: {
|
params: {
|
||||||
name: "",
|
name: "",
|
||||||
subType: subType,
|
subType: subType,
|
||||||
connectionType: "",
|
connectionType: "USB",
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,56 +51,3 @@ export function markIsSoldOut(data) {
|
|||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
<div class="input_wrap">
|
<div class="input_wrap">
|
||||||
<div class="input" style="flex: 1">付款:¥{{ formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount
|
<div class="input" style="flex: 1">付款:¥{{ formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount
|
||||||
|| 0) }}</div>
|
|| 0) }}</div>
|
||||||
|
<!-- <el-button type="warning" style="width: 80px;border-radius: 6px; height: 60px;" @click="applyRounding">抹零</el-button> -->
|
||||||
<el-button type="primary" style="width: 120px;border-radius: 6px; height: 60px;"
|
<el-button type="primary" style="width: 120px;border-radius: 6px; height: 60px;"
|
||||||
@click="showCouponHandle">添加优惠</el-button>
|
@click="showCouponHandle">添加优惠</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,11 +140,25 @@
|
|||||||
<el-button type="danger" @click="clearCouponUser">清除</el-button>
|
<el-button type="danger" @click="clearCouponUser">清除</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="整单折扣">
|
<el-form-item label="优惠金额">
|
||||||
<el-input v-model="couponForm.discountRatio" placeholder="请输入折扣" style="width: 180px;"
|
<div class="column">
|
||||||
@input="discountInput">
|
<div>
|
||||||
<template #append>折</template>
|
<el-radio-group v-model="discountType" @change="clearDiscountChange">
|
||||||
</el-input>
|
<el-radio-button label="按金额优惠" :value="1"></el-radio-button>
|
||||||
|
<el-radio-button label="按折扣优惠" :value="2"></el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<el-input v-model="couponForm.discountAmount" placeholder="请输入金额" style="width: 239px;"
|
||||||
|
@input="amountDiscountInput" v-if="discountType == 1">
|
||||||
|
<template #append>元</template>
|
||||||
|
</el-input>
|
||||||
|
<el-input v-model="couponForm.discountRatio" placeholder="请输入折扣" style="width: 239px;"
|
||||||
|
@input="discountInput" v-if="discountType == 2">
|
||||||
|
<template #append>折</template>
|
||||||
|
</el-input>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="优惠券">
|
<el-form-item label="优惠券">
|
||||||
<div style="width: 100%;">
|
<div style="width: 100%;">
|
||||||
@@ -258,6 +273,7 @@ import { staffPermission } from "@/api/user.js";
|
|||||||
import { cashPay, buyerPage, creditPay, vipPay } from "@/api/order.js";
|
import { cashPay, buyerPage, creditPay, vipPay } from "@/api/order.js";
|
||||||
import { calcUsablePoints } from '@/api/account.js'
|
import { calcUsablePoints } from '@/api/account.js'
|
||||||
import { useGoods } from "@/store/goods.js";
|
import { useGoods } from "@/store/goods.js";
|
||||||
|
import { createOrder } from '@/api/order.js';
|
||||||
|
|
||||||
const emit = defineEmits(["paySuccess", 'orderExpired', 'reset']);
|
const emit = defineEmits(["paySuccess", 'orderExpired', 'reset']);
|
||||||
|
|
||||||
@@ -475,8 +491,44 @@ function upadatePayData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 结算支付
|
// 结算支付
|
||||||
async function confirmOrder() {
|
async function confirmOrder(t = 1) {
|
||||||
try {
|
try {
|
||||||
|
// if (goodsStore.cartList.length >= 0) {
|
||||||
|
// // 如果购物还存在商品,先下单后进行支付操作
|
||||||
|
// const data = {
|
||||||
|
// orderId: goodsStore.orderListInfo.id || '', // 订单id
|
||||||
|
// shopId: store.shopInfo.id, // 店铺id
|
||||||
|
// seatNum: goodsStore.tableInfo.num || 0, // 用餐人数
|
||||||
|
// packFee: goodsStore.cartInfo.packFee, // 打包费
|
||||||
|
// 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: goodsStore.remark, // 备注
|
||||||
|
// placeNum: (goodsStore.orderListInfo.placeNum || 0) + 1, // 下单次数
|
||||||
|
// waitCall: 0, // 是否叫号
|
||||||
|
// userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||||
|
// limitRate: goodsStore.limitDiscountRes
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // goodsStore.calcCartInfo()
|
||||||
|
// const res = await createOrder(data)
|
||||||
|
// if (res.id) {
|
||||||
|
// // 设置订单信息
|
||||||
|
// // goodsStore.orderListInfo = res
|
||||||
|
// // if (t == 1) {
|
||||||
|
// // // 向其他端发送清空购物车消息
|
||||||
|
// // goodsStore.operateCart({ table_code: goodsStore.orderListInfo.tableCode }, "cleanup");
|
||||||
|
// // console.log('生成订单===', res);
|
||||||
|
// // } else {
|
||||||
|
// // goodsStore.clearCart()
|
||||||
|
// // }
|
||||||
|
// // 清除购物车,更新历史订单
|
||||||
|
// // goodsStore.updateOrderList()
|
||||||
|
// } else {
|
||||||
|
// ElMessage.error('订单成功失败,请重新下单')
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// 判断订单是否锁定
|
// 判断订单是否锁定
|
||||||
await goodsStore.isOrderLock({
|
await goodsStore.isOrderLock({
|
||||||
table_code: goodsStore.orderListInfo.tableCode
|
table_code: goodsStore.orderListInfo.tableCode
|
||||||
@@ -486,7 +538,6 @@ async function confirmOrder() {
|
|||||||
|
|
||||||
upadatePayData()
|
upadatePayData()
|
||||||
|
|
||||||
|
|
||||||
payType.value = payList.value[payActive.value].payType
|
payType.value = payList.value[payActive.value].payType
|
||||||
if (payList.value[payActive.value].payType == "arrears") {
|
if (payList.value[payActive.value].payType == "arrears") {
|
||||||
showBuyerHandle();
|
showBuyerHandle();
|
||||||
@@ -576,6 +627,20 @@ function amountInput(num) {
|
|||||||
payData.value.checkOrderPay.orderAmount = money.value;
|
payData.value.checkOrderPay.orderAmount = money.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 应用抹零
|
||||||
|
function applyRounding() {
|
||||||
|
if (discountAmount.value !== null) {
|
||||||
|
money.value = formatDecimal(discountAmount.value)
|
||||||
|
roundAmount.value = 0
|
||||||
|
} else {
|
||||||
|
money.value = formatDecimal(props.amount)
|
||||||
|
roundAmount.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
payData.value.checkOrderPay.roundAmount = roundAmount.value;
|
||||||
|
payData.value.checkOrderPay.orderAmount = money.value;
|
||||||
|
}
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
function delHandle() {
|
function delHandle() {
|
||||||
if (!money.value) return; money.value = money.value.substring(0, money.value.length - 1);
|
if (!money.value) return; money.value = money.value.substring(0, money.value.length - 1);
|
||||||
@@ -718,6 +783,32 @@ function clearCouponUser() {
|
|||||||
// resetCouponFormHandle()
|
// resetCouponFormHandle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 按照金额优惠
|
||||||
|
const discountType = ref(1)
|
||||||
|
|
||||||
|
// 清除优惠方式变更时的优惠数据
|
||||||
|
function clearDiscountChange() {
|
||||||
|
couponForm.value.discountRatio = ''
|
||||||
|
couponForm.value.discountAmount = ''
|
||||||
|
discountRateNumber.value = 0
|
||||||
|
|
||||||
|
updateCartCalc()
|
||||||
|
}
|
||||||
|
|
||||||
|
const amountDiscountInput = _.debounce(function (e) {
|
||||||
|
couponForm.value.discountAmount = inputFilterFloat(e)
|
||||||
|
if (couponForm.value.discountAmount > goodsStore.cartInfo.costSummary.goodsRealAmount) {
|
||||||
|
couponForm.value.discountAmount = goodsStore.cartInfo.costSummary.goodsRealAmount
|
||||||
|
}
|
||||||
|
if (couponForm.value.discountAmount < 0) {
|
||||||
|
couponForm.value.discountAmount = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
discountRateNumber.value = couponForm.value.discountAmount
|
||||||
|
|
||||||
|
updateCartCalc()
|
||||||
|
}, 500)
|
||||||
|
|
||||||
// 折扣格式化
|
// 折扣格式化
|
||||||
const discountRateNumber = ref(0)
|
const discountRateNumber = ref(0)
|
||||||
const discountInput = _.debounce(function (e) {
|
const discountInput = _.debounce(function (e) {
|
||||||
@@ -1251,6 +1342,12 @@ defineExpose({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
.column {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.point_tips {
|
.point_tips {
|
||||||
&.err {
|
&.err {
|
||||||
color: var(--el-color-danger);
|
color: var(--el-color-danger);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export const useGoods = defineStore("goods", {
|
|||||||
}, // 台桌信息
|
}, // 台桌信息
|
||||||
cartActiveIndex: 0, // 购物车激活索引,
|
cartActiveIndex: 0, // 购物车激活索引,
|
||||||
isCartInit: false,
|
isCartInit: false,
|
||||||
|
payType: "cart", // 结算类型,cart 购物车结算 table 桌台结算 order 订单结算,
|
||||||
cartList: [], // 购物车列表
|
cartList: [], // 购物车列表
|
||||||
// 购物车信息,
|
// 购物车信息,
|
||||||
cartInfo: {
|
cartInfo: {
|
||||||
@@ -889,7 +890,11 @@ export const useGoods = defineStore("goods", {
|
|||||||
.map((item) => item.goods)
|
.map((item) => item.goods)
|
||||||
.flat()
|
.flat()
|
||||||
.map(this.comleteOrderInfo);
|
.map(this.comleteOrderInfo);
|
||||||
return [...currentGoods, ...giftGoods, ...oldOrderGoods];
|
if (this.payType == 'table' || this.payType == 'order') {
|
||||||
|
return [...giftGoods, ...oldOrderGoods];
|
||||||
|
} else {
|
||||||
|
return [...currentGoods, ...giftGoods, ...oldOrderGoods];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并所有商品列表
|
// 合并所有商品列表
|
||||||
|
|||||||
@@ -11,28 +11,30 @@ import { useSocket } from './socket.js';
|
|||||||
|
|
||||||
export const usePrint = defineStore("print", {
|
export const usePrint = defineStore("print", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
isPrintService: false,
|
isPrintService: false, // 打印服务是否启动
|
||||||
printServiceTimer: null,
|
printServiceTimer: false, // 打印服务定时器
|
||||||
printServiceTimerCount: 0,
|
printServiceTimerCount: 0, // 打印服务定时器计数
|
||||||
printServiceTimerMaxCount: 10,
|
printServiceTimerMaxCount: 10, // 打印服务定时器最大计数
|
||||||
showPrintNotService: false,
|
showPrintNotService: false, // 是否显示重启软件,
|
||||||
localDevices: [],
|
localDevices: [], // 本地打印机列表
|
||||||
deviceNoteList: [],
|
deviceNoteList: [], // 添加的打印机
|
||||||
deviceLableList: [],
|
deviceLableList: [], // 添加的打印机
|
||||||
labelList: [],
|
labelList: [], // 要打印的队列数据
|
||||||
printTimer: null,
|
printTimer: null,
|
||||||
receiptList: [],
|
receiptList: [], // 小票队列数据
|
||||||
receiptTimer: null,
|
receiptTimer: null,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
// 获取本地打印机和已添加的可以用打印机列表
|
||||||
async init() {
|
async init() {
|
||||||
|
// 获取本地打印机
|
||||||
ipcRenderer.send("getPrintList");
|
ipcRenderer.send("getPrintList");
|
||||||
ipcRenderer.on("printList", (event, arg) => {
|
ipcRenderer.on("printList", (event, arg) => {
|
||||||
this.localDevices = arg;
|
this.localDevices = arg;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 获取已添加的打印机
|
||||||
const res = await printerList();
|
const res = await printerList();
|
||||||
this.deviceNoteList = res.records.filter(
|
this.deviceNoteList = res.records.filter(
|
||||||
(item) => item.status && item.subType == "cash"
|
(item) => item.status && item.subType == "cash"
|
||||||
@@ -40,12 +42,18 @@ export const usePrint = defineStore("print", {
|
|||||||
this.deviceLableList = res.records.filter(
|
this.deviceLableList = res.records.filter(
|
||||||
(item) => item.status && item.subType == "label"
|
(item) => item.status && item.subType == "label"
|
||||||
);
|
);
|
||||||
|
console.log("打印队列初始化成功", {
|
||||||
|
deviceNoteList: this.deviceNoteList,
|
||||||
|
deviceLableList: this.deviceLableList,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取打印机列表失败", error);
|
console.error("获取已添加的打印机列表失败", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测打印服务是否启动
|
||||||
this.checkPrintService();
|
this.checkPrintService();
|
||||||
},
|
},
|
||||||
|
// 检测打印组件服务是否启动
|
||||||
checkPrintService() {
|
checkPrintService() {
|
||||||
this.printServiceTimer = setInterval(() => {
|
this.printServiceTimer = setInterval(() => {
|
||||||
if (
|
if (
|
||||||
@@ -53,154 +61,26 @@ export const usePrint = defineStore("print", {
|
|||||||
LODOP.webskt &&
|
LODOP.webskt &&
|
||||||
LODOP.webskt.readyState == 1
|
LODOP.webskt.readyState == 1
|
||||||
) {
|
) {
|
||||||
|
// 准备好
|
||||||
this.isPrintService = true;
|
this.isPrintService = true;
|
||||||
clearInterval(this.printServiceTimer);
|
clearInterval(this.printServiceTimer);
|
||||||
this.printServiceTimer = null;
|
this.printServiceTimer = null;
|
||||||
} else {
|
} else {
|
||||||
this.printServiceTimerCount++;
|
this.printServiceTimerCount++;
|
||||||
|
console.log("打印服务未启动", this.printServiceTimerCount);
|
||||||
|
|
||||||
if (this.printServiceTimerCount >= this.printServiceTimerMaxCount) {
|
if (this.printServiceTimerCount >= this.printServiceTimerMaxCount) {
|
||||||
|
// 超过最大次数
|
||||||
this.isPrintService = false;
|
this.isPrintService = false;
|
||||||
this.showPrintNotService = true;
|
this.showPrintNotService = true;
|
||||||
clearInterval(this.printServiceTimer);
|
clearInterval(this.printServiceTimer);
|
||||||
this.printServiceTimer = null;
|
this.printServiceTimer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log("打印服务是否启动:", this.isPrintService);
|
||||||
}, 1000);
|
}, 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) {
|
checkLocalPrint(address) {
|
||||||
let print = "";
|
let print = "";
|
||||||
for (let item of this.localDevices) {
|
for (let item of this.localDevices) {
|
||||||
@@ -208,15 +88,17 @@ export const usePrint = defineStore("print", {
|
|||||||
print = item;
|
print = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!print.name) {
|
if (!print.name) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 打印标签小票
|
||||||
labelPrint(props) {
|
labelPrint(props) {
|
||||||
const store = useUser();
|
const store = useUser();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.deviceLableList.length &&
|
this.deviceLableList.length &&
|
||||||
this.checkLocalPrint(this.deviceLableList[0].address)
|
this.checkLocalPrint(this.deviceLableList[0].address)
|
||||||
@@ -224,6 +106,7 @@ export const usePrint = defineStore("print", {
|
|||||||
let pids = this.deviceLableList[0].categoryList;
|
let pids = this.deviceLableList[0].categoryList;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
|
|
||||||
props.carts.map((item) => {
|
props.carts.map((item) => {
|
||||||
if (pids.some((el) => el == item.categoryId)) {
|
if (pids.some((el) => el == item.categoryId)) {
|
||||||
for (let i = 0; i < item.number; i++) {
|
for (let i = 0; i < item.number; i++) {
|
||||||
@@ -231,6 +114,7 @@ export const usePrint = defineStore("print", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
props.carts.map((item) => {
|
props.carts.map((item) => {
|
||||||
if (pids.some((el) => el == item.categoryId)) {
|
if (pids.some((el) => el == item.categoryId)) {
|
||||||
for (let i = 0; i < item.number; i++) {
|
for (let i = 0; i < item.number; i++) {
|
||||||
@@ -249,12 +133,17 @@ export const usePrint = defineStore("print", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("this.labelList===", this.labelList);
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// 执行打印操作
|
||||||
this.startLabelPrint();
|
this.startLabelPrint();
|
||||||
} else {
|
} else {
|
||||||
console.log("标签打印:未在本机查询到打印机");
|
console.log("标签打印:未在本机查询到打印机");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 开始打印标签数据
|
||||||
startLabelPrint() {
|
startLabelPrint() {
|
||||||
if (this.printTimer != null) return;
|
if (this.printTimer != null) return;
|
||||||
this.printTimer = setInterval(() => {
|
this.printTimer = setInterval(() => {
|
||||||
@@ -272,55 +161,88 @@ export const usePrint = defineStore("print", {
|
|||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
},
|
||||||
|
// 添加小票打印队列数据
|
||||||
// 打印交班小票(优化:1. 新增handoverSwitch=1才打印 2. 兼容局域网打印机)
|
pushReceiptData(props, isDevice = true) {
|
||||||
printWork(data) {
|
// console.log("pushReceiptData===", props);
|
||||||
// 筛选条件:
|
if (!isDevice) {
|
||||||
// 1. 状态启用 + 小票类型 + handoverSwitch=1
|
// 测试打印,无需校验本地打印机
|
||||||
// 2. 打印机可用
|
this.receiptList.push(props);
|
||||||
// 3. 打印服务正常
|
this.startReceiptPrint();
|
||||||
const validPrinters = this.deviceNoteList.filter(p => {
|
} else {
|
||||||
return p.status
|
if (
|
||||||
&& p.subType === "cash"
|
this.deviceNoteList.length &&
|
||||||
&& p.handoverSwitch === 1 // 新增:只有handoverSwitch为1的打印机才打印交班小票
|
this.checkLocalPrint(this.deviceNoteList[0].address) &&
|
||||||
&& this.checkPrinterAvailable(p)
|
this.isPrintService
|
||||||
&& this.isPrintService;
|
) {
|
||||||
});
|
const store = useUser();
|
||||||
|
props.deviceId = this.deviceNoteList[0].id;
|
||||||
if (validPrinters.length === 0) {
|
props.deviceName = this.deviceNoteList[0].address;
|
||||||
console.log("交班小票:无符合条件的可用打印机(handoverSwitch≠1 或 打印机不可用)");
|
props.shop_name = store.shopInfo.shopName;
|
||||||
return;
|
props.loginAccount = store.userInfo.name;
|
||||||
}
|
props.createdAt = dayjs(props.createdAt).format(
|
||||||
|
"YYYY-MM-DD HH:mm:ss"
|
||||||
// 遍历符合条件的打印机打印
|
);
|
||||||
validPrinters.forEach(printer => {
|
props.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||||
const printData = {
|
if (!props.orderInfo.masterId) {
|
||||||
...data,
|
props.orderInfo.masterId = props.orderInfo.tableName;
|
||||||
deviceId: printer.id,
|
}
|
||||||
deviceName: printer.address,
|
props.orderInfo.outNumber = props.outNumber;
|
||||||
connectionType: printer.connectionType,
|
if (!props.discountAmount) {
|
||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
props.discountAmount = props.amount;
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
|
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) {
|
printInvoice(data) {
|
||||||
if (
|
if (
|
||||||
this.deviceNoteList.length &&
|
this.deviceNoteList.length &&
|
||||||
@@ -332,55 +254,17 @@ export const usePrint = defineStore("print", {
|
|||||||
console.log("订单发票:未在本机查询到打印机");
|
console.log("订单发票:未在本机查询到打印机");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 退菜/退款
|
// 打印退单小票
|
||||||
printRefund(data) {
|
printRefund(data) {
|
||||||
// 筛选条件:
|
if (
|
||||||
// 1. 状态启用 + 小票类型
|
this.deviceNoteList.length &&
|
||||||
// 2. 打印机可用
|
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||||
// 3. 打印服务正常
|
) {
|
||||||
const validPrinters = this.deviceNoteList.filter(p => {
|
data.deviceName = this.deviceNoteList[0].address;
|
||||||
return p.status
|
refundPrint(data);
|
||||||
&& p.subType === "cash"
|
} else {
|
||||||
&& this.checkPrinterAvailable(p)
|
console.log("退单小票:未在本机查询到打印机");
|
||||||
&& 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,270 +0,0 @@
|
|||||||
import { defineStore } from "pinia";
|
|
||||||
import { ipcRenderer } from "electron";
|
|
||||||
import { useUser } from "@/store/user.js";
|
|
||||||
import dayjs from "dayjs";
|
|
||||||
import receiptPrint from "@/components/lodop/receiptPrint.js";
|
|
||||||
import lodopPrintWork from "@/components/lodop/lodopPrintWork.js";
|
|
||||||
import invoicePrint from "@/components/lodop/invoicePrint.js";
|
|
||||||
import refundPrint from "@/components/lodop/refundPrint.js";
|
|
||||||
import { printerList } from "@/api/account.js";
|
|
||||||
import { useSocket } from './socket.js';
|
|
||||||
|
|
||||||
export const usePrint = defineStore("print", {
|
|
||||||
state: () => ({
|
|
||||||
isPrintService: false, // 打印服务是否启动
|
|
||||||
printServiceTimer: false, // 打印服务定时器
|
|
||||||
printServiceTimerCount: 0, // 打印服务定时器计数
|
|
||||||
printServiceTimerMaxCount: 10, // 打印服务定时器最大计数
|
|
||||||
showPrintNotService: false, // 是否显示重启软件,
|
|
||||||
localDevices: [], // 本地打印机列表
|
|
||||||
deviceNoteList: [], // 添加的打印机
|
|
||||||
deviceLableList: [], // 添加的打印机
|
|
||||||
labelList: [], // 要打印的队列数据
|
|
||||||
printTimer: null,
|
|
||||||
receiptList: [], // 小票队列数据
|
|
||||||
receiptTimer: null,
|
|
||||||
}),
|
|
||||||
actions: {
|
|
||||||
// 获取本地打印机和已添加的可以用打印机列表
|
|
||||||
async init() {
|
|
||||||
// 获取本地打印机
|
|
||||||
ipcRenderer.send("getPrintList");
|
|
||||||
ipcRenderer.on("printList", (event, arg) => {
|
|
||||||
this.localDevices = arg;
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 获取已添加的打印机
|
|
||||||
const res = await printerList();
|
|
||||||
this.deviceNoteList = res.records.filter(
|
|
||||||
(item) => item.status && item.subType == "cash"
|
|
||||||
);
|
|
||||||
this.deviceLableList = res.records.filter(
|
|
||||||
(item) => item.status && item.subType == "label"
|
|
||||||
);
|
|
||||||
console.log("打印队列初始化成功", {
|
|
||||||
deviceNoteList: this.deviceNoteList,
|
|
||||||
deviceLableList: this.deviceLableList,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("获取已添加的打印机列表失败", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测打印服务是否启动
|
|
||||||
this.checkPrintService();
|
|
||||||
},
|
|
||||||
// 检测打印组件服务是否启动
|
|
||||||
checkPrintService() {
|
|
||||||
this.printServiceTimer = setInterval(() => {
|
|
||||||
if (
|
|
||||||
typeof LODOP !== "undefined" &&
|
|
||||||
LODOP.webskt &&
|
|
||||||
LODOP.webskt.readyState == 1
|
|
||||||
) {
|
|
||||||
// 准备好
|
|
||||||
this.isPrintService = true;
|
|
||||||
clearInterval(this.printServiceTimer);
|
|
||||||
this.printServiceTimer = null;
|
|
||||||
} else {
|
|
||||||
this.printServiceTimerCount++;
|
|
||||||
console.log("打印服务未启动", this.printServiceTimerCount);
|
|
||||||
|
|
||||||
if (this.printServiceTimerCount >= this.printServiceTimerMaxCount) {
|
|
||||||
// 超过最大次数
|
|
||||||
this.isPrintService = false;
|
|
||||||
this.showPrintNotService = true;
|
|
||||||
clearInterval(this.printServiceTimer);
|
|
||||||
this.printServiceTimer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log("打印服务是否启动:", this.isPrintService);
|
|
||||||
}, 1000);
|
|
||||||
},
|
|
||||||
// 检查本地打印机是否能正常使用
|
|
||||||
checkLocalPrint(address) {
|
|
||||||
let print = "";
|
|
||||||
for (let item of this.localDevices) {
|
|
||||||
if (item.name == address) {
|
|
||||||
print = item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!print.name) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 打印标签小票
|
|
||||||
labelPrint(props) {
|
|
||||||
const store = useUser();
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.deviceLableList.length &&
|
|
||||||
this.checkLocalPrint(this.deviceLableList[0].address)
|
|
||||||
) {
|
|
||||||
let pids = this.deviceLableList[0].categoryList;
|
|
||||||
let count = 0;
|
|
||||||
let sum = 0;
|
|
||||||
|
|
||||||
props.carts.map((item) => {
|
|
||||||
if (pids.some((el) => el == item.categoryId)) {
|
|
||||||
for (let i = 0; i < item.number; i++) {
|
|
||||||
sum++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
props.carts.map((item) => {
|
|
||||||
if (pids.some((el) => el == item.categoryId)) {
|
|
||||||
for (let i = 0; i < item.number; i++) {
|
|
||||||
count++;
|
|
||||||
this.labelList.push({
|
|
||||||
outNumber: props.outNumber,
|
|
||||||
name: item.name,
|
|
||||||
skuName: item.skuName,
|
|
||||||
masterId: props.orderInfo.tableName,
|
|
||||||
deviceName: this.deviceLableList[0].address,
|
|
||||||
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
|
||||||
isPrint: false,
|
|
||||||
count: `${count}/${sum}`,
|
|
||||||
ticketLogo: store.shopInfo.ticketLogo,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("this.labelList===", this.labelList);
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// 执行打印操作
|
|
||||||
this.startLabelPrint();
|
|
||||||
} else {
|
|
||||||
console.log("标签打印:未在本机查询到打印机");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 开始打印标签数据
|
|
||||||
startLabelPrint() {
|
|
||||||
if (this.printTimer != null) return;
|
|
||||||
this.printTimer = setInterval(() => {
|
|
||||||
let item = "";
|
|
||||||
if (!this.labelList.length) {
|
|
||||||
clearInterval(this.printTimer);
|
|
||||||
this.printTimer = null;
|
|
||||||
} else {
|
|
||||||
item = this.labelList[0];
|
|
||||||
if (!item.isPrint) {
|
|
||||||
ipcRenderer.send("printerTagSync", JSON.stringify(item));
|
|
||||||
this.labelList[0].isPrint = true;
|
|
||||||
this.labelList.splice(0, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
},
|
|
||||||
// 添加小票打印队列数据
|
|
||||||
pushReceiptData(props, isDevice = true) {
|
|
||||||
// console.log("pushReceiptData===", props);
|
|
||||||
if (!isDevice) {
|
|
||||||
// 测试打印,无需校验本地打印机
|
|
||||||
this.receiptList.push(props);
|
|
||||||
this.startReceiptPrint();
|
|
||||||
} else {
|
|
||||||
if (
|
|
||||||
this.deviceNoteList.length &&
|
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address) &&
|
|
||||||
this.isPrintService
|
|
||||||
) {
|
|
||||||
const store = useUser();
|
|
||||||
props.deviceId = this.deviceNoteList[0].id;
|
|
||||||
props.deviceName = this.deviceNoteList[0].address;
|
|
||||||
props.shop_name = store.shopInfo.shopName;
|
|
||||||
props.loginAccount = store.userInfo.name;
|
|
||||||
props.createdAt = dayjs(props.createdAt).format(
|
|
||||||
"YYYY-MM-DD HH:mm:ss"
|
|
||||||
);
|
|
||||||
props.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
||||||
if (!props.orderInfo.masterId) {
|
|
||||||
props.orderInfo.masterId = props.orderInfo.tableName;
|
|
||||||
}
|
|
||||||
props.orderInfo.outNumber = props.outNumber;
|
|
||||||
if (!props.discountAmount) {
|
|
||||||
props.discountAmount = props.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.receiptList.push(props);
|
|
||||||
this.startReceiptPrint();
|
|
||||||
} else {
|
|
||||||
console.log("订单小票:未在本机查询到打印机");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 开始打印小票
|
|
||||||
async startReceiptPrint() {
|
|
||||||
try {
|
|
||||||
const socketStore = useSocket();
|
|
||||||
const userStore = useUser();
|
|
||||||
|
|
||||||
if (this.receiptTimer !== null) return;
|
|
||||||
this.receiptTimer = setInterval(() => {
|
|
||||||
if (!this.receiptList.length) {
|
|
||||||
clearInterval(this.receiptTimer);
|
|
||||||
this.receiptTimer = null;
|
|
||||||
} else {
|
|
||||||
receiptPrint(this.receiptList[0]);
|
|
||||||
// 在这里触发已打印操作标记
|
|
||||||
const data = {
|
|
||||||
type: "cashier",
|
|
||||||
operate_type: "order_print_status",
|
|
||||||
table_code: this.receiptList[0].orderInfo.tableCode,
|
|
||||||
account: userStore.shopInfo.account,
|
|
||||||
print_status: "1",
|
|
||||||
order_id: this.receiptList[0].orderInfo.id,
|
|
||||||
print_id: this.receiptList[0].deviceId,
|
|
||||||
shop_id: this.receiptList[0].orderInfo.shopId,
|
|
||||||
}
|
|
||||||
socketStore.ws.send(JSON.stringify(data));
|
|
||||||
this.receiptList.splice(0, 1);
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 打印交班小票
|
|
||||||
printWork(data) {
|
|
||||||
if (
|
|
||||||
this.deviceNoteList.length &&
|
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
|
||||||
) {
|
|
||||||
data.deviceName = this.deviceNoteList[0].address;
|
|
||||||
lodopPrintWork(data);
|
|
||||||
} else {
|
|
||||||
console.log("交班小票:未在本机查询到打印机");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 打印订单发票
|
|
||||||
printInvoice(data) {
|
|
||||||
if (
|
|
||||||
this.deviceNoteList.length &&
|
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
|
||||||
) {
|
|
||||||
data.deviceName = this.deviceNoteList[0].address;
|
|
||||||
invoicePrint(data);
|
|
||||||
} else {
|
|
||||||
console.log("订单发票:未在本机查询到打印机");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 打印退单小票
|
|
||||||
printRefund(data) {
|
|
||||||
if (
|
|
||||||
this.deviceNoteList.length &&
|
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
|
||||||
) {
|
|
||||||
data.deviceName = this.deviceNoteList[0].address;
|
|
||||||
refundPrint(data);
|
|
||||||
} else {
|
|
||||||
console.log("退单小票:未在本机查询到打印机");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -159,9 +159,7 @@ export async function getOrderByIdAjax(orderId) {
|
|||||||
export function commOrderPrintData(orderInfo) {
|
export function commOrderPrintData(orderInfo) {
|
||||||
const userStore = useUser();
|
const userStore = useUser();
|
||||||
let data = {
|
let data = {
|
||||||
title: orderInfo.title,
|
|
||||||
isBefore: orderInfo.isBefore || false,
|
isBefore: orderInfo.isBefore || false,
|
||||||
isGuest: orderInfo.isGuest || false,
|
|
||||||
shop_name: userStore.shopInfo.shopName,
|
shop_name: userStore.shopInfo.shopName,
|
||||||
loginAccount: userStore.userInfo.name,
|
loginAccount: userStore.userInfo.name,
|
||||||
carts: [],
|
carts: [],
|
||||||
@@ -181,38 +179,23 @@ export function commOrderPrintData(orderInfo) {
|
|||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (orderInfo.isGuest) {
|
orderInfo.cartList.map((item) => {
|
||||||
// 如果是客看单,只展示当前下单的菜品
|
data.carts.push({
|
||||||
orderInfo.detailMap[0].map((item) => {
|
categoryId: item.categoryId,
|
||||||
data.carts.push({
|
name: item.productName,
|
||||||
categoryId: item.categoryId,
|
number: item.num,
|
||||||
name: item.productName,
|
skuName: item.skuName,
|
||||||
number: item.num,
|
salePrice: formatDecimal(+item.price),
|
||||||
skuName: item.skuName,
|
totalAmount: formatDecimal(+item.payAmount),
|
||||||
salePrice: formatDecimal(+item.price),
|
proGroupInfo: item.proGroupInfo
|
||||||
totalAmount: formatDecimal(+item.payAmount),
|
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||||
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) {
|
if (orderInfo.seatAmount > 0) {
|
||||||
|
console.log('有餐位费', orderInfo.seatAmount);
|
||||||
|
|
||||||
data.carts.push({
|
data.carts.push({
|
||||||
categoryId: '',
|
categoryId: '',
|
||||||
name: '餐位费',
|
name: '餐位费',
|
||||||
|
|||||||
@@ -12,12 +12,6 @@
|
|||||||
<el-form-item label="设备名称">
|
<el-form-item label="设备名称">
|
||||||
<el-input v-model="form.name" placeholder="请输入设备名称"></el-input>
|
<el-input v-model="form.name" placeholder="请输入设备名称"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="设备类型">
|
|
||||||
<el-radio-group v-model="form.connectionType">
|
|
||||||
<el-radio-button label="USB" value="USB"></el-radio-button>
|
|
||||||
<el-radio-button label="局域网" value="局域网"></el-radio-button>
|
|
||||||
</el-radio-group>
|
|
||||||
</el-form-item>
|
|
||||||
<!-- <el-form-item label="打印机品牌">
|
<!-- <el-form-item label="打印机品牌">
|
||||||
<el-input v-model="form.contentType" placeholder="请输入打印机品牌"></el-input>
|
<el-input v-model="form.contentType" placeholder="请输入打印机品牌"></el-input>
|
||||||
</el-form-item> -->
|
</el-form-item> -->
|
||||||
@@ -27,30 +21,17 @@
|
|||||||
<el-option label="80mm" value="80mm"></el-option>
|
<el-option label="80mm" value="80mm"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="选择设备" v-if="form.connectionType === 'USB'">
|
<el-form-item label="设备类型">
|
||||||
|
<el-select v-model="form.connectionType">
|
||||||
|
<el-option label="USB" value="USB"></el-option>
|
||||||
|
<!-- <el-option label="网络" value="network"></el-option> -->
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="选择设备">
|
||||||
<el-select v-model="form.address">
|
<el-select v-model="form.address">
|
||||||
<el-option :label="item.name" :value="item.name" v-for="item in printList" :key="item.name"></el-option>
|
<el-option :label="item.name" :value="item.name" v-for="item in printList" :key="item.name"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="设备IP" v-if="form.connectionType === '局域网'">
|
|
||||||
<el-input v-model="form.address" placeholder="请输入设备IP地址"></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="商品分类">
|
|
||||||
<div style="cursor: pointer" @click="classifyRef.show()">
|
|
||||||
<span style="color: #409eff" v-if="form.categoryList.length">
|
|
||||||
{{form.categoryList.map(item => item.name).join(',')}}
|
|
||||||
</span>
|
|
||||||
<span style="color: #e65d6e" v-else>
|
|
||||||
请选择分类
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="是否打印交班小票">
|
|
||||||
<el-radio-group v-model="form.handoverSwitch">
|
|
||||||
<el-radio-button label="否" :value="0"></el-radio-button>
|
|
||||||
<el-radio-button label="是" :value="1"></el-radio-button>
|
|
||||||
</el-radio-group>
|
|
||||||
</el-form-item>
|
|
||||||
<!-- <el-form-item label="打印份数">
|
<!-- <el-form-item label="打印份数">
|
||||||
<el-select v-model="form.printQty">
|
<el-select v-model="form.printQty">
|
||||||
<el-option :label="item" :value="item" v-for="item in 4" :key="item"></el-option>
|
<el-option :label="item" :value="item" v-for="item in 4" :key="item"></el-option>
|
||||||
@@ -144,7 +125,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<classify ref="classifyRef" @success="(e) => (form.categoryList = e)" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -156,11 +136,6 @@ import { ElMessage } from "element-plus";
|
|||||||
import { useUser } from "@/store/user.js";
|
import { useUser } from "@/store/user.js";
|
||||||
import { usePrint } from "@/store/print.js";
|
import { usePrint } from "@/store/print.js";
|
||||||
import { printerAdd, printerDetail } from "@/api/account.js";
|
import { printerAdd, printerDetail } from "@/api/account.js";
|
||||||
import classify from "@/components/classify/index.vue";
|
|
||||||
import { useGoods } from '@/store/goods.js'
|
|
||||||
const goodsStore = useGoods()
|
|
||||||
|
|
||||||
const classifyRef = ref(null);
|
|
||||||
|
|
||||||
const printStore = usePrint();
|
const printStore = usePrint();
|
||||||
const store = useUser();
|
const store = useUser();
|
||||||
@@ -175,7 +150,7 @@ const requestLoading = ref(false);
|
|||||||
const form = ref({
|
const form = ref({
|
||||||
id: "",
|
id: "",
|
||||||
name: '', // 设备名称
|
name: '', // 设备名称
|
||||||
connectionType: 'USB', // 现在打印机支持USB 和 网络、蓝牙、局域网
|
connectionType: 'USB', // 现在打印机支持USB 和 网络、蓝牙
|
||||||
address: '', // 打印机名称
|
address: '', // 打印机名称
|
||||||
port: '', // 端口
|
port: '', // 端口
|
||||||
subType: 'cash', // 打印类型(分类)label标签cash小票kitchen出品
|
subType: 'cash', // 打印类型(分类)label标签cash小票kitchen出品
|
||||||
@@ -188,8 +163,7 @@ const form = ref({
|
|||||||
printQty: '', // 打印数量 c1m1^2 = 顾客+商家[2张] m1^1 = 商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
printQty: '', // 打印数量 c1m1^2 = 顾客+商家[2张] m1^1 = 商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
|
||||||
printMethod: 'all', // 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」queue-仅打印排队取号
|
printMethod: 'all', // 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」queue-仅打印排队取号
|
||||||
printType: [], // 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
printType: [], // 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||||
status: 1,
|
status: 1
|
||||||
handoverSwitch: 0, // 交班单开关 0-关闭 1-开启
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const printDataLoading = ref(false);
|
const printDataLoading = ref(false);
|
||||||
@@ -236,29 +210,16 @@ function getPrintList() {
|
|||||||
|
|
||||||
// 测试打印
|
// 测试打印
|
||||||
function printHandle() {
|
function printHandle() {
|
||||||
if (form.value.connectionType === 'USB' && !form.value.address) {
|
if (!form.value.address) {
|
||||||
ElMessage.error("请选择打印设备");
|
ElMessage.error("请选择打印设备");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (form.value.connectionType === '局域网' && !form.value.address) {
|
|
||||||
ElMessage.error("请输入设备IP地址");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
printDataLoading.value = true;
|
printDataLoading.value = true;
|
||||||
printData.shop_name = store.shopInfo.shopName
|
printData.shop_name = store.shopInfo.shopName
|
||||||
printData.loginAccount = store.userInfo.name
|
printData.loginAccount = store.userInfo.name
|
||||||
printData.deviceName = form.value.address;
|
printData.deviceName = form.value.address;
|
||||||
printData.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
printData.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
printStore.pushReceiptData(printData, false);
|
||||||
if (form.value.connectionType === 'USB') {
|
|
||||||
printStore.pushReceiptData(printData, false);
|
|
||||||
} else if (form.value.connectionType === '局域网') {
|
|
||||||
ipcRenderer.send('networkPrint', JSON.stringify({
|
|
||||||
printerIp: form.value.address,
|
|
||||||
orderData: printData
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
printDataLoading.value = false;
|
printDataLoading.value = false;
|
||||||
}, 2500);
|
}, 2500);
|
||||||
@@ -271,16 +232,11 @@ async function submitHandle() {
|
|||||||
ElMessage.error("请输入设备名称");
|
ElMessage.error("请输入设备名称");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (form.value.connectionType === 'USB' && !form.value.address) {
|
if (!form.value.address) {
|
||||||
ElMessage.error("请选择打印设备");
|
ElMessage.error("请选择打印设备");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (form.value.connectionType === '局域网' && !form.value.address) {
|
|
||||||
ElMessage.error("请输入设备IP地址");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
form.value.categoryIds = form.value.categoryList.map(item => item.id)
|
|
||||||
await printerAdd(form.value, form.value.id ? "put" : "post");
|
await printerAdd(form.value, form.value.id ? "put" : "post");
|
||||||
ElMessage.success(form.value.id ? "编辑成功" : "添加成功");
|
ElMessage.success(form.value.id ? "编辑成功" : "添加成功");
|
||||||
printStore.init();
|
printStore.init();
|
||||||
@@ -297,19 +253,6 @@ async function tbPrintMachineDetailAjax(id) {
|
|||||||
requestLoading.value = true;
|
requestLoading.value = true;
|
||||||
const res = await printerDetail({ id: id });
|
const res = await printerDetail({ id: id });
|
||||||
form.value = res;
|
form.value = res;
|
||||||
|
|
||||||
let arr = []
|
|
||||||
goodsStore.originCategoryList.map(item => {
|
|
||||||
res.categoryList.map(val => {
|
|
||||||
if (item.id == val) {
|
|
||||||
arr.push({
|
|
||||||
id: item.id,
|
|
||||||
name: item.name
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
form.value.categoryList = arr
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,21 +251,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import _ from 'lodash'
|
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import takeFoodCode from '@/components/takeFoodCode.vue'
|
import takeFoodCode from '@/components/takeFoodCode.vue'
|
||||||
import TableMerging from './tableMerging.vue'
|
import TableMerging from './tableMerging.vue'
|
||||||
import skuModal from '@/components/skuModal.vue'
|
import skuModal from '@/components/skuModal.vue'
|
||||||
import { useGoods } from '@/store/goods.js'
|
import { useGoods } from '@/store/goods.js'
|
||||||
import { inputFilterFloat, formatDecimal, getOrderByIdAjax, commOrderPrintData } from '@/utils/index.js'
|
import { inputFilterFloat, formatDecimal } from '@/utils/index.js'
|
||||||
import { refundOrder } from '@/api/order.js'
|
import { refundOrder } from '@/api/order.js'
|
||||||
import { useSocket } from '@/store/socket.js'
|
import { useSocket } from '@/store/socket.js'
|
||||||
import { usePrint } from '@/store/print.js'
|
|
||||||
|
|
||||||
const goodsStore = useGoods()
|
const goodsStore = useGoods()
|
||||||
const socket = useSocket()
|
const socket = useSocket()
|
||||||
const printStore = usePrint()
|
|
||||||
|
|
||||||
const tableMergingRef = ref(null)
|
const tableMergingRef = ref(null)
|
||||||
|
|
||||||
@@ -342,25 +339,6 @@ async function returnOrderItemAjax(num = 1) {
|
|||||||
await refundOrder(data)
|
await refundOrder(data)
|
||||||
goodsStore.cartOrderItem.returnNum += num
|
goodsStore.cartOrderItem.returnNum += num
|
||||||
goodsStore.calcCartInfo()
|
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)
|
// await goodsStore.historyOrderAjax('', data.orderId)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -55,7 +55,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="shop_list" :class="{ img: shopListType == 'img' }" v-loading="loading">
|
<div class="shop_list" :class="{ img: shopListType == 'img' }" v-loading="loading">
|
||||||
<!-- <swiper class="swiper_box" direction="vertical" @slideChange="onSlideChange"> -->
|
<!-- <swiper class="swiper_box" direction="vertical" @slideChange="onSlideChange"> -->
|
||||||
<swiper ref="swiperRef" :loop="false" class="swiper_box" direction="vertical">
|
<swiper ref="swiperRef" :loop="false" class="swiper_box" direction="vertical" :modules="[Mousewheel]"
|
||||||
|
:simulate-touch="true" :allow-touch-move="true" :mousewheel="{
|
||||||
|
enabled: true,
|
||||||
|
forceToAxis: true,
|
||||||
|
releaseOnEdges: true,
|
||||||
|
invert: false,
|
||||||
|
}">
|
||||||
<swiper-slide class="slide_item" v-for="(goods, index) in goodsStore.goodsList" :key="index">
|
<swiper-slide class="slide_item" v-for="(goods, index) in goodsStore.goodsList" :key="index">
|
||||||
<div class="item_wrap" v-for="item in goods" :key="item.id" @click="showSkuHandle(item)">
|
<div class="item_wrap" v-for="item in goods" :key="item.id" @click="showSkuHandle(item)">
|
||||||
<div class="item">
|
<div class="item">
|
||||||
@@ -294,6 +300,8 @@ import { staffPermission } from '@/api/user.js'
|
|||||||
import { clearNoNum } from '@/utils/index.js'
|
import { clearNoNum } from '@/utils/index.js'
|
||||||
import { productOnOff, markIsSoldOut } from '@/api/product_new.js'
|
import { productOnOff, markIsSoldOut } from '@/api/product_new.js'
|
||||||
|
|
||||||
|
import { Mousewheel } from 'swiper/modules'
|
||||||
|
|
||||||
const swiperRef = ref(null)
|
const swiperRef = ref(null)
|
||||||
|
|
||||||
const store = useUser()
|
const store = useUser()
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ const props = defineProps({
|
|||||||
member: {
|
member: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: {}
|
default: {}
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'cart' // cart 代客下单 table 桌台结算 order 订单结算
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -227,11 +231,11 @@ async function printOrderLable(isBefore = false) {
|
|||||||
printStore.pushReceiptData(commOrderPrintData({ ...data, isBefore: isBefore }));
|
printStore.pushReceiptData(commOrderPrintData({ ...data, isBefore: isBefore }));
|
||||||
} else {
|
} else {
|
||||||
// 本地没有可用打印机使用云打印机
|
// 本地没有可用打印机使用云打印机
|
||||||
// await orderPrint({
|
await orderPrint({
|
||||||
// type: isBefore ? 1 : 0,
|
type: isBefore ? 1 : 0,
|
||||||
// id: orderId,
|
id: orderId,
|
||||||
// });
|
});
|
||||||
// ElMessage.success(`云打印${isBefore ? '预' : ''}结算单成功`);
|
ElMessage.success(`云打印${isBefore ? '预' : ''}结算单成功`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -244,7 +248,7 @@ async function printOrderLable(isBefore = false) {
|
|||||||
|
|
||||||
// 订单已支付
|
// 订单已支付
|
||||||
function paySuccess() {
|
function paySuccess() {
|
||||||
if (isPrint.value) printOrderLable()
|
// if (isPrint.value) printOrderLable()
|
||||||
emits('success')
|
emits('success')
|
||||||
dialogVisible.value = false;
|
dialogVisible.value = false;
|
||||||
ElMessage.success('支付成功')
|
ElMessage.success('支付成功')
|
||||||
@@ -258,9 +262,14 @@ function paySuccess() {
|
|||||||
|
|
||||||
const payCardRef = ref(null)
|
const payCardRef = ref(null)
|
||||||
function show(t) {
|
function show(t) {
|
||||||
|
goodsStore.payType = props.type
|
||||||
dialogVisible.value = true;
|
dialogVisible.value = true;
|
||||||
cartInfo.value = { ...goodsStore.cartInfo }
|
cartInfo.value = { ...goodsStore.cartInfo }
|
||||||
orderList.value = [...goodsStore.cartList, ...goodsStore.orderList.map(item => item.goods).flat()]
|
if (props.type === 'table' || props.type === 'order') {
|
||||||
|
orderList.value = goodsStore.orderList.map(item => item.goods).flat()
|
||||||
|
} else {
|
||||||
|
orderList.value = [...goodsStore.cartList, ...goodsStore.orderList.map(item => item.goods).flat()]
|
||||||
|
}
|
||||||
|
|
||||||
console.log('orderListInfo===================', { ...goodsStore.orderListInfo });
|
console.log('orderListInfo===================', { ...goodsStore.orderListInfo });
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ function confirmHandle() {
|
|||||||
goodsStore.operateCart({
|
goodsStore.operateCart({
|
||||||
table_code: table_code,
|
table_code: table_code,
|
||||||
new_table_code: new_table_code,
|
new_table_code: new_table_code,
|
||||||
cart_ids: cart_ids
|
cart_id: cart_ids
|
||||||
}, 'rottable')
|
}, 'rottable')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import _ from 'lodash'
|
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useGlobal } from '@/store/global.js'
|
import { useGlobal } from '@/store/global.js'
|
||||||
import SelectVipUser from "@/components/selectVipUser.vue";
|
import SelectVipUser from "@/components/selectVipUser.vue";
|
||||||
@@ -225,7 +224,7 @@ import fastCashier from "@/views/home/components/fastCashier.vue";
|
|||||||
import pendingCartModal from "@/views/home/components/pendingCartModal.vue";
|
import pendingCartModal from "@/views/home/components/pendingCartModal.vue";
|
||||||
import tableMerging from '@/views/home/components/tableMerging.vue'
|
import tableMerging from '@/views/home/components/tableMerging.vue'
|
||||||
import CartItem from './components/cartItem.vue'
|
import CartItem from './components/cartItem.vue'
|
||||||
import { formatDecimal, formatPhoneNumber, getOrderByIdAjax, commOrderPrintData } from '@/utils/index.js'
|
import { formatDecimal, formatPhoneNumber } from '@/utils/index.js'
|
||||||
import { useGoods } from '@/store/goods.js'
|
import { useGoods } from '@/store/goods.js'
|
||||||
import { staffPermission } from '@/api/user.js'
|
import { staffPermission } from '@/api/user.js'
|
||||||
import { createOrder } from '@/api/order.js'
|
import { createOrder } from '@/api/order.js'
|
||||||
@@ -300,7 +299,6 @@ async function quickCashHandle() {
|
|||||||
// 生成订单 t=0 先下单后结算 t=1直接结算
|
// 生成订单 t=0 先下单后结算 t=1直接结算
|
||||||
async function createOrderHandle(t = 0) {
|
async function createOrderHandle(t = 0) {
|
||||||
try {
|
try {
|
||||||
let placeNum = goodsStore.orderListInfo.placeNum || 0
|
|
||||||
if (goodsStore.cartList.length) {
|
if (goodsStore.cartList.length) {
|
||||||
const data = {
|
const data = {
|
||||||
orderId: goodsStore.orderListInfo.id || '', // 订单id
|
orderId: goodsStore.orderListInfo.id || '', // 订单id
|
||||||
@@ -311,7 +309,7 @@ async function createOrderHandle(t = 0) {
|
|||||||
tableCode: goodsStore.cartList[0].table_code, // 台桌号
|
tableCode: goodsStore.cartList[0].table_code, // 台桌号
|
||||||
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||||
remark: remark.value, // 备注
|
remark: remark.value, // 备注
|
||||||
placeNum: placeNum + 1, // 下单次数
|
placeNum: (goodsStore.orderListInfo.placeNum || 0) + 1, // 下单次数
|
||||||
waitCall: 0, // 是否叫号
|
waitCall: 0, // 是否叫号
|
||||||
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||||
limitRate: goodsStore.limitDiscountRes
|
limitRate: goodsStore.limitDiscountRes
|
||||||
@@ -330,17 +328,6 @@ async function createOrderHandle(t = 0) {
|
|||||||
settleAccountRef.value.show(t)
|
settleAccountRef.value.show(t)
|
||||||
} else {
|
} else {
|
||||||
goodsStore.clearCart()
|
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()
|
goodsStore.updateOrderList()
|
||||||
|
|||||||
@@ -26,9 +26,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog> -->
|
</el-dialog> -->
|
||||||
<!-- <el-input v-model="authCode" placeholder="请扫描支付码"></el-input>
|
<el-input v-model="authCode" placeholder="请扫描支付码"></el-input>
|
||||||
<el-button type="primary" @click="microPayAjax">反扫支付</el-button> -->
|
<el-button type="primary" @click="microPayAjax">反扫支付</el-button>
|
||||||
<el-button type="primary" @click="printReceipt">调用本地网络打印机</el-button>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -48,26 +47,6 @@ const tempFilePath = ref('')
|
|||||||
|
|
||||||
const authCode = ref('')
|
const authCode = ref('')
|
||||||
|
|
||||||
function printReceipt() {
|
|
||||||
let data = {
|
|
||||||
printerIp: '192.168.1.53',
|
|
||||||
orderData: {
|
|
||||||
orderNo: '20260327008',
|
|
||||||
shopName: '川味小馆',
|
|
||||||
createTime: new Date().toLocaleString(),
|
|
||||||
products: [
|
|
||||||
{ name: '回锅肉', price: '32.00', num: 1 },
|
|
||||||
{ name: '米饭', price: '2.00', num: 2 },
|
|
||||||
{ name: '紫菜蛋花汤', price: '8.00', num: 1 }
|
|
||||||
],
|
|
||||||
total: '42.00',
|
|
||||||
payType: '支付宝',
|
|
||||||
remark: '微辣'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ipcRenderer.send('portPrint', JSON.stringify(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查版本更新
|
// 检查版本更新
|
||||||
async function findVersionAjax() {
|
async function findVersionAjax() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,303 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-drawer v-model="drawerVisible" size="100%" :with-header="false" direction="btt">
|
|
||||||
<div class="drawer_wrap">
|
|
||||||
<div class="header">
|
|
||||||
<div class="left">
|
|
||||||
<div class="return" @click="drawerVisible = false">
|
|
||||||
<el-icon size="26" color="#555">
|
|
||||||
<Back />
|
|
||||||
</el-icon>
|
|
||||||
</div>
|
|
||||||
<div class="user_info">
|
|
||||||
<el-image :src="userInfo.headImg" fit="cover"
|
|
||||||
style="width: 40px; height: 40px; border-radius: 50%;background-color: #efefef;">
|
|
||||||
<template #error>
|
|
||||||
<el-icon style="font-size: 40px; color: #ccc;">
|
|
||||||
<user />
|
|
||||||
</el-icon>
|
|
||||||
</template>
|
|
||||||
</el-image>
|
|
||||||
<el-text>{{ userInfo.nickName }}/{{ userInfo.phone }}</el-text>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="right">
|
|
||||||
<!-- <el-button type="danger" @click="dialogVisible = true">取酒</el-button> -->
|
|
||||||
<el-button type="primary" @click="dialogVisible = true">新增存酒</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="pay_wrap">
|
|
||||||
<div class="tab">
|
|
||||||
<el-table :data="list" height="100%" border stripe>
|
|
||||||
<el-table-column label="记录" prop="name"></el-table-column>
|
|
||||||
<el-table-column label="数量" prop="num"></el-table-column>
|
|
||||||
<el-table-column label="操作时间" prop="expTime"></el-table-column>
|
|
||||||
<el-table-column label="操作" width="150">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-button type="danger" :disabled="row.num <= 0"
|
|
||||||
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">取酒</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-drawer>
|
|
||||||
<el-dialog v-model="dialogVisible" title="新增存酒" width="350px" :close-on-click-modal="false" destroy-on-close>
|
|
||||||
<el-form :model="form" :rules="rules" label-width="100px" label-position="left">
|
|
||||||
<el-form-item label="选择酒品">
|
|
||||||
<el-select v-model="form.shopStorageGoodId" placeholder="请选择存酒商品" style="width: 180px;">
|
|
||||||
<el-option v-for="item in storageGoodList" :key="item.id" :label="item.name" :value="item.id">
|
|
||||||
</el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="存酒数量">
|
|
||||||
<el-input-number v-model="form.num" :min="1"></el-input-number>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="存酒有效期">
|
|
||||||
<el-input-number v-model="form.expDay" :min="1"></el-input-number>
|
|
||||||
<span style="margin-left: 8px;">天</span>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<div class="dialog-footer">
|
|
||||||
<div class="btn">
|
|
||||||
<el-button style="width: 100%;" @click="dialogVisible = false">取 消</el-button>
|
|
||||||
</div>
|
|
||||||
<div class="btn">
|
|
||||||
<el-button style="width: 100%;" type="primary" :loading="confirmLoading" @click="confirmHandle">确
|
|
||||||
定</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
<!-- 取酒对话框,只选择数量即可,不可超过存酒的数量 -->
|
|
||||||
<el-dialog v-model="takeWineDialogVisible" title="取酒" width="350px" :close-on-click-modal="false" destroy-on-close>
|
|
||||||
<el-form :model="takeWineForm" :rules="takeWineRules" label-width="100px" label-position="left">
|
|
||||||
<el-form-item label="取酒数量">
|
|
||||||
<el-input-number v-model="takeWineForm.num" :min="1" :max="maxTakeNum"></el-input-number>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<div class="dialog-footer">
|
|
||||||
<div class="btn">
|
|
||||||
<el-button style="width: 100%;" @click="takeWineDialogVisible = false">取 消</el-button>
|
|
||||||
</div>
|
|
||||||
<div class="btn">
|
|
||||||
<el-button style="width: 100%;" type="primary" :loading="takeWineConfirmLoading"
|
|
||||||
@click="confirmTakeWineHandle">确 定</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref, onMounted } from "vue";
|
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut } from '@/api/product_new'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
userInfo: {
|
|
||||||
type: Object,
|
|
||||||
default: () => ({})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const drawerVisible = ref(false);
|
|
||||||
const dialogVisible = ref(false);
|
|
||||||
|
|
||||||
const list = ref([]);
|
|
||||||
|
|
||||||
// 获取存酒记录
|
|
||||||
async function shopStorageGetAjax() {
|
|
||||||
try {
|
|
||||||
const res = await shopStorageGet({
|
|
||||||
key: '',
|
|
||||||
phone: props.userInfo.phone,
|
|
||||||
page: 1,
|
|
||||||
size: 999,
|
|
||||||
});
|
|
||||||
list.value = res.records || [];
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取存酒列表失败:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const form = ref({
|
|
||||||
userId: '',
|
|
||||||
shopStorageGoodId: '', // 存酒商品ID
|
|
||||||
num: 1, // 存酒数量
|
|
||||||
expDay: 1, // 存酒有效期,单位天默认1天
|
|
||||||
})
|
|
||||||
|
|
||||||
const rules = {
|
|
||||||
shopStorageGoodId: [{ required: true, message: '请选择存酒商品', trigger: 'change' }],
|
|
||||||
num: [{ required: true, message: '请输入存酒数量', trigger: 'change' }],
|
|
||||||
expDay: [{ required: true, message: '请输入存酒有效期', trigger: 'change' }],
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确认存酒
|
|
||||||
const confirmLoading = ref(false);
|
|
||||||
async function confirmHandle() {
|
|
||||||
try {
|
|
||||||
confirmLoading.value = true;
|
|
||||||
form.value.userId = props.userInfo.userId;
|
|
||||||
await shopStoragePost(form.value);
|
|
||||||
ElMessage.success('存酒成功');
|
|
||||||
dialogVisible.value = false;
|
|
||||||
shopStorageGetAjax(); // 刷新存酒商品列表
|
|
||||||
} catch (error) {
|
|
||||||
console.error('存酒失败:', error);
|
|
||||||
} finally {
|
|
||||||
confirmLoading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取存酒商品列表
|
|
||||||
const storageGoodList = ref([]);
|
|
||||||
async function storageGoodGetAjax() {
|
|
||||||
try {
|
|
||||||
const res = await storageGoodGet({
|
|
||||||
page: 1,
|
|
||||||
size: 999,
|
|
||||||
});
|
|
||||||
storageGoodList.value = res.records || [];
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取存酒商品列表失败:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const takeWineDialogVisible = ref(false);
|
|
||||||
const takeWineForm = ref({
|
|
||||||
id: '', // 存酒记录ID
|
|
||||||
num: 1,
|
|
||||||
})
|
|
||||||
const takeWineRules = {
|
|
||||||
num: [{ required: true, message: '请输入取酒数量', trigger: 'change' }],
|
|
||||||
}
|
|
||||||
const maxTakeNum = ref(1);
|
|
||||||
const takeWineConfirmLoading = ref(false);
|
|
||||||
|
|
||||||
function confirmTakeWineHandle() {
|
|
||||||
shopStoragePutAjax();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 存酒取酒 num 必需 正数为存酒反之为取酒
|
|
||||||
async function shopStoragePutAjax() {
|
|
||||||
try {
|
|
||||||
takeWineConfirmLoading.value = true;
|
|
||||||
await shopStoragePut({
|
|
||||||
id: takeWineForm.value.id,
|
|
||||||
num: -takeWineForm.value.num, // 取酒数量为负数
|
|
||||||
});
|
|
||||||
ElMessage.success('取酒成功');
|
|
||||||
takeWineDialogVisible.value = false;
|
|
||||||
shopStorageGetAjax(); // 刷新存酒记录列表
|
|
||||||
} catch (error) {
|
|
||||||
console.error('取酒失败:', error);
|
|
||||||
} finally {
|
|
||||||
takeWineConfirmLoading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
drawerVisible.value = false;
|
|
||||||
dialogVisible.value = false;
|
|
||||||
takeWineDialogVisible.value = false;
|
|
||||||
form.value = {
|
|
||||||
userId: '',
|
|
||||||
shopStorageGoodId: '',
|
|
||||||
num: 1,
|
|
||||||
expDay: 1,
|
|
||||||
};
|
|
||||||
takeWineForm.value = {
|
|
||||||
id: '',
|
|
||||||
num: 1,
|
|
||||||
};
|
|
||||||
maxTakeNum.value = 1;
|
|
||||||
list.value = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function show() {
|
|
||||||
init();
|
|
||||||
drawerVisible.value = true;
|
|
||||||
// 刷新列表数据
|
|
||||||
storageGoodGetAjax();
|
|
||||||
shopStorageGetAjax();
|
|
||||||
}
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
show,
|
|
||||||
init,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 初始化
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
storageGoodGetAjax();
|
|
||||||
shopStorageGetAjax();
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.drawer_wrap {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
padding: var(--el-font-size-base) 0;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--el-font-size-base);
|
|
||||||
|
|
||||||
.header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0 var(--el-font-size-base);
|
|
||||||
background-color: #fff;
|
|
||||||
padding: var(--el-font-size-base);
|
|
||||||
border-radius: var(--el-font-size-base);
|
|
||||||
|
|
||||||
.left {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: var(--el-font-size-base);
|
|
||||||
|
|
||||||
.return {
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 4px;
|
|
||||||
transition: background-color 0.3s;
|
|
||||||
padding: 10px 8px 4px;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.user_info {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: var(--el-font-size-base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.pay_wrap {
|
|
||||||
flex: 1;
|
|
||||||
background: #fff;
|
|
||||||
border-radius: var(--el-font-size-base);
|
|
||||||
|
|
||||||
.tab {
|
|
||||||
height: 100%;
|
|
||||||
padding: var(--el-font-size-base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialog-footer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: var(--el-font-size-base);
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -99,9 +99,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn_wrap">
|
<div class="btn_wrap">
|
||||||
<div class="btn">
|
|
||||||
<el-button type="success" style="width: 100%;" @click="StoreWineManagementRef.show()">存酒管理</el-button>
|
|
||||||
</div>
|
|
||||||
<div class="btn">
|
<div class="btn">
|
||||||
<el-button type="warning" style="width: 100%;" @click="UserChargeRef.show()">账户充值</el-button>
|
<el-button type="warning" style="width: 100%;" @click="UserChargeRef.show()">账户充值</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -117,8 +114,6 @@
|
|||||||
<RecordDialog ref="RecordDialogRef" @refund="getUserList" />
|
<RecordDialog ref="RecordDialogRef" @refund="getUserList" />
|
||||||
<!-- 添加会员 -->
|
<!-- 添加会员 -->
|
||||||
<AddUserDrawer ref="AddUserDrawerRef" @success="queryHandle" />
|
<AddUserDrawer ref="AddUserDrawerRef" @success="queryHandle" />
|
||||||
<!-- 存酒管理 -->
|
|
||||||
<StoreWineManagement ref="StoreWineManagementRef" :user-info="currentRow" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -128,12 +123,10 @@ import { shopUserList } from '@/api/account.js'
|
|||||||
import UserCharge from './components/userCharge.vue'
|
import UserCharge from './components/userCharge.vue'
|
||||||
import RecordDialog from './components/recordDialog.vue'
|
import RecordDialog from './components/recordDialog.vue'
|
||||||
import AddUserDrawer from './components/addUserDrawer.vue'
|
import AddUserDrawer from './components/addUserDrawer.vue'
|
||||||
import StoreWineManagement from './components/storeWineManagement.vue'
|
|
||||||
|
|
||||||
const UserChargeRef = ref(null)
|
const UserChargeRef = ref(null)
|
||||||
const RecordDialogRef = ref(null)
|
const RecordDialogRef = ref(null)
|
||||||
const AddUserDrawerRef = ref(null)
|
const AddUserDrawerRef = ref(null)
|
||||||
const StoreWineManagementRef = ref(null)
|
|
||||||
|
|
||||||
const queryForm = ref({
|
const queryForm = ref({
|
||||||
key: '',
|
key: '',
|
||||||
|
|||||||
@@ -260,7 +260,6 @@ async function printRefund(rows) {
|
|||||||
if (printStore.deviceNoteList.length) {
|
if (printStore.deviceNoteList.length) {
|
||||||
// 本地打印
|
// 本地打印
|
||||||
const data = {
|
const data = {
|
||||||
title: '退款单',
|
|
||||||
shop_name: store.shopInfo.shopName,
|
shop_name: store.shopInfo.shopName,
|
||||||
loginAccount: store.userInfo.name,
|
loginAccount: store.userInfo.name,
|
||||||
carts: [],
|
carts: [],
|
||||||
@@ -269,7 +268,6 @@ async function printRefund(rows) {
|
|||||||
orderInfo: item.value,
|
orderInfo: item.value,
|
||||||
outNumber: item.value.id,
|
outNumber: item.value.id,
|
||||||
createdAt: item.value.createTime,
|
createdAt: item.value.createTime,
|
||||||
refundMethod: cash.value ? '现金' : '原路退回',
|
|
||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@
|
|||||||
<!-- 打印操作 -->
|
<!-- 打印操作 -->
|
||||||
<PrintDrawer ref="PrintDrawerRef" />
|
<PrintDrawer ref="PrintDrawerRef" />
|
||||||
<!-- 结算订单 -->
|
<!-- 结算订单 -->
|
||||||
<SettleAccount ref="SettleAccountRef" @success="orderListAjax" />
|
<SettleAccount ref="SettleAccountRef" type="order" @success="orderListAjax" />
|
||||||
<!-- 全部商品 -->
|
<!-- 全部商品 -->
|
||||||
<allGoodsDialog ref="allGoodsDialogRef" />
|
<allGoodsDialog ref="allGoodsDialogRef" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!-- 空闲台桌 -->
|
<!-- 空闲台桌 -->
|
||||||
<template>
|
<template>
|
||||||
<div class="table_wrap">
|
<div class="table_wrap">
|
||||||
<div class="header">
|
<!-- <div class="header">
|
||||||
<span class="t">{{ props.tableInfo.name }}</span>
|
<span class="t">{{ props.tableInfo.name }}</span>
|
||||||
<div class="close" @click="close">
|
<div class="close" @click="close">
|
||||||
<el-icon class="icon">
|
<el-icon class="icon">
|
||||||
@@ -14,14 +14,29 @@
|
|||||||
<Clock />
|
<Clock />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
<span class="t">{{tableStatusList.find(val => val.type == props.tableInfo.status).label}}</span>
|
<span class="t">{{tableStatusList.find(val => val.type == props.tableInfo.status).label}}</span>
|
||||||
</div>
|
</div> -->
|
||||||
<div class="cart" v-loading="payLoading" v-if="props.tableInfo.status == 'unsettled'">
|
<div class="cart" v-loading="payLoading" v-if="props.tableInfo.status == 'unsettled'">
|
||||||
<div class="cart_list">
|
<div class="cart_list">
|
||||||
<div class="item" v-for="item in cartList" :key="item.id">
|
<div class="item" v-for="item in cartList" :key="item.id">
|
||||||
<div class="top">
|
<div class="top">
|
||||||
<span class="name">{{ item.productName }}</span>
|
<span class="name">
|
||||||
<span class="n">x{{ item.num }}</span>
|
<span v-if="item.isTemporary" style="color: #999;">[临时菜]</span>
|
||||||
<span class="p">¥{{ item.price }}</span>
|
<span v-if="item.isGift" style="color: #999;">[赠]</span>
|
||||||
|
{{ item.productName }}
|
||||||
|
</span>
|
||||||
|
<span class="n">x{{ item.num - item.returnNum }}</span>
|
||||||
|
<span class="p">¥{{ item.unitPrice }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="top" v-if="item.returnNum > 0" style="font-size: 12px;color: #999;">
|
||||||
|
<span class="name">[退菜]</span>
|
||||||
|
<span class="n">x{{ item.returnNum }}</span>
|
||||||
|
<span class="p">-¥{{ item.returnNum * item.price }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="top" v-if="item.discountSaleAmount > 0 && item.isTemporary == 0"
|
||||||
|
style="font-size: 12px;color: #999;">
|
||||||
|
<span class="name">[改价优惠]</span>
|
||||||
|
<span class="n"></span>
|
||||||
|
<span class="p">-¥{{ item.price - item.unitPrice }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="tag_wrap" v-if="item.skuName">
|
<div class="tag_wrap" v-if="item.skuName">
|
||||||
<div class="tag" v-for="item in item.skuName.split(',')">
|
<div class="tag" v-for="item in item.skuName.split(',')">
|
||||||
@@ -56,6 +71,9 @@
|
|||||||
<div class="btn_wrap" v-if="props.tableInfo.status == 'settled'">
|
<div class="btn_wrap" v-if="props.tableInfo.status == 'settled'">
|
||||||
<el-button type="primary" style="width: 100%;" @click="clearTableStatus">清理完成</el-button>
|
<el-button type="primary" style="width: 100%;" @click="clearTableStatus">清理完成</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="btn_wrap" v-if="props.tableInfo.status == 'unbound'">
|
||||||
|
<el-button type="default" disabled style="width: 100%;">{{ props.tableInfo.statusMsg }}</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<transition name="el-fade-in">
|
<transition name="el-fade-in">
|
||||||
<div class="people_num_wrap" v-show="showPeopleNum">
|
<div class="people_num_wrap" v-show="showPeopleNum">
|
||||||
@@ -77,7 +95,7 @@
|
|||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
<!-- 结算订单 -->
|
<!-- 结算订单 -->
|
||||||
<SettleAccount ref="SettleAccountRef" @success="emits('success')" />
|
<SettleAccount ref="SettleAccountRef" type="table" @success="emits('success')" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -182,9 +200,8 @@ async function getOrderDetail() {
|
|||||||
|
|
||||||
let total = 0
|
let total = 0
|
||||||
res.cartList.forEach(item => {
|
res.cartList.forEach(item => {
|
||||||
total += item.payAmount * item.num
|
total += +item.payAmount - (item.returnNum * item.price)
|
||||||
})
|
})
|
||||||
|
|
||||||
orderInfo.value.orderAmount = formatDecimal(total)
|
orderInfo.value.orderAmount = formatDecimal(total)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -257,7 +274,8 @@ onMounted(() => {
|
|||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.table_wrap {
|
.table_wrap {
|
||||||
padding: 20px;
|
// padding: 20px;
|
||||||
|
padding-top: 14px;
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -299,14 +317,14 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cart {
|
.cart {
|
||||||
height: calc(100vh - 160px);
|
height: calc(100vh - 75px);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
.cart_list {
|
.cart_list {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background-color: #efefef;
|
background-color: #fff;
|
||||||
padding: 0 var(--el-font-size-base);
|
padding: 0 var(--el-font-size-base);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
|
|||||||
@@ -5,42 +5,57 @@
|
|||||||
<div class="menus">
|
<div class="menus">
|
||||||
<div class="item" :class="{ active: tabActive == index }" v-for="(item, index) in tabAreas"
|
<div class="item" :class="{ active: tabActive == index }" v-for="(item, index) in tabAreas"
|
||||||
:key="item.id" @click="tabChange(item, index)">
|
:key="item.id" @click="tabChange(item, index)">
|
||||||
|
<div class="dot" :style="{ backgroundColor: item.color }" v-if="item.color"></div>
|
||||||
<el-text>{{ item.label }}</el-text>
|
<el-text>{{ item.label }}</el-text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="all">
|
<!-- <div class="all">
|
||||||
<el-button type="link" icon="Clock">预定管理</el-button>
|
<el-button type="link" icon="Clock">预定管理</el-button>
|
||||||
</div> -->
|
</div> -->
|
||||||
|
<div class="order_info">
|
||||||
|
<div class="title">
|
||||||
|
<el-icon>
|
||||||
|
<Tickets />
|
||||||
|
</el-icon>
|
||||||
|
<el-text>未结账:</el-text>
|
||||||
|
</div>
|
||||||
|
<el-text type="primary">
|
||||||
|
{{ orderInfo.num }}笔 | {{ orderInfo.personNum }}人 | ¥{{ formatDecimal(orderInfo.amount) }}
|
||||||
|
</el-text>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab_container">
|
<div class="tab_container">
|
||||||
<div class="tab_head">
|
<div class="tab_head" ref="tabHeadRef">
|
||||||
<el-radio-group v-model="area" @change="shopTableAjax">
|
<div class="item" :class="{ active: tabItemActive == -1 }" @click="tabItemChange('', -1)">全部</div>
|
||||||
<el-radio-button label="全部" value=""></el-radio-button>
|
<div class="item" :class="{ active: index == tabItemActive }" v-for="(item, index) in areaList"
|
||||||
<el-radio-button :label="item.name" :value="item.id" v-for="item in areaList"
|
:key="item.id" @click="tabItemChange(item, index)">
|
||||||
:key="item.id"></el-radio-button>
|
{{ item.name }}
|
||||||
</el-radio-group>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="overflow_y" v-loading="loading">
|
<div class="overflow_y" v-loading="loading">
|
||||||
<div class="tab_list">
|
<div class="tab_list">
|
||||||
<div class="item" :class="{ active: tableItemActive == index }"
|
<div class="item"
|
||||||
:style="{ '--color': tableStatusList.find(val => val.type == item.status).color }"
|
:style="{ '--color': tableStatusList.find(val => val.type == item.status).color }"
|
||||||
v-for="(item, index) in tableList" :key="item.id" @click="slectTableHandle(index, item)">
|
v-for="(item, index) in tableList" :key="item.id" @click="slectTableHandle(index, item)">
|
||||||
<div class="tab_title" :class="`${item.status}`">
|
<div class="tab_title" :class="`${item.status}`">
|
||||||
<span>{{ item.name }}</span>
|
<span>{{ item.areaName }} | {{ item.name }}</span>
|
||||||
<span>0/{{ item.maxCapacity }}</span>
|
<span>{{ item.personNum || 0 }}/{{ item.maxCapacity }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab_cont">
|
<div class="tab_cont">
|
||||||
<el-icon class="icon" v-if="item.status != 'using'">
|
<div class="using"
|
||||||
<CircleClose />
|
v-if="item.status == 'unsettled' || item.status == 'unsettled' || item.status == 'paying' || item.status == 'settled' || item.status == 'unpaid'">
|
||||||
</el-icon>
|
<div class="t1">¥{{ formatDecimal(+item.orderAmount) }}</div>
|
||||||
<div class="using" v-else>
|
<div class="t2">
|
||||||
<div class="t1">开台中</div>
|
<el-icon color="#333">
|
||||||
<!-- <div class="t2">
|
|
||||||
<el-icon>
|
|
||||||
<Timer />
|
<Timer />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
<span>{{ countTime(item.updatedAt) }}</span>
|
<span :key="refreshKey">{{ countTime(item.orderCreateTime) }}</span>
|
||||||
</div> -->
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="icon_wrap" v-else>
|
||||||
|
<el-icon class="icon">
|
||||||
|
<CircleClose />
|
||||||
|
</el-icon>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -49,19 +64,22 @@
|
|||||||
<el-empty description="空空如也~" />
|
<el-empty description="空空如也~" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pagination">
|
<!-- <div class="pagination">
|
||||||
<el-pagination background v-model:current-page="query.page" :pager-count="5"
|
<el-pagination background v-model:current-page="query.page" :pager-count="5"
|
||||||
layout=" pager, jumper, total" :total="query.total"
|
layout=" pager, jumper, total" :total="query.total"
|
||||||
@current-change="shopTableAjax"></el-pagination>
|
@current-change="shopTableAjax"></el-pagination>
|
||||||
</div>
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="right_card card">
|
<el-drawer v-model="drawerVisible"
|
||||||
<!-- 台桌统计 -->
|
:title="`${tableList[tableItemActive].areaName} | ${tableList[tableItemActive].name} (${tableList[tableItemActive].personNum || 0}/${tableList[tableItemActive].maxCapacity})`"
|
||||||
|
size="35%" v-if="tableList.length">
|
||||||
|
<tableInfo :tableInfo="tableList[tableItemActive]" @success="paySuccess" />
|
||||||
|
</el-drawer>
|
||||||
|
<!-- <div class="right_card card">
|
||||||
<countCard v-if="!slectTable.id" />
|
<countCard v-if="!slectTable.id" />
|
||||||
<!-- 台桌信息 -->
|
|
||||||
<tableInfo v-else :tableInfo="slectTable" @close="slectTableClose" @success="paySuccess" />
|
<tableInfo v-else :tableInfo="slectTable" @close="slectTableClose" @success="paySuccess" />
|
||||||
</div>
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -69,9 +87,16 @@
|
|||||||
import { shopArea, shopTable } from "@/api/account.js";
|
import { shopArea, shopTable } from "@/api/account.js";
|
||||||
import countCard from '@/views/table/components/countCard.vue'
|
import countCard from '@/views/table/components/countCard.vue'
|
||||||
import tableInfo from '@/views/table/components/tableInfo.vue'
|
import tableInfo from '@/views/table/components/tableInfo.vue'
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
|
||||||
import { dayjs } from 'element-plus'
|
import { dayjs } from 'element-plus'
|
||||||
import tableStatusList from './statusList.js'
|
import tableStatusList from './statusList.js'
|
||||||
|
import { formatDecimal } from '@/utils/index.js'
|
||||||
|
|
||||||
|
const orderInfo = ref({
|
||||||
|
num: 0,
|
||||||
|
personNum: 0,
|
||||||
|
amount: 0
|
||||||
|
})
|
||||||
|
|
||||||
const tabActive = ref(0)
|
const tabActive = ref(0)
|
||||||
const tabAreas = ref([
|
const tabAreas = ref([
|
||||||
@@ -82,18 +107,22 @@ const tabAreas = ref([
|
|||||||
{
|
{
|
||||||
label: '空闲',
|
label: '空闲',
|
||||||
type: 'idle',
|
type: 'idle',
|
||||||
|
color: "#187CAA",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '使用中',
|
label: '使用中',
|
||||||
type: 'unsettled'
|
type: 'unsettled',
|
||||||
|
color: "#DD3F41",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '待清理',
|
label: '待清理',
|
||||||
type: 'settled',
|
type: 'settled',
|
||||||
|
color: "#FF9500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '已预订',
|
label: '已预订',
|
||||||
type: 'subscribe',
|
type: 'subscribe',
|
||||||
|
color: "#58B22C",
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -110,7 +139,7 @@ const tableList = ref([])
|
|||||||
// 所选区域
|
// 所选区域
|
||||||
const area = ref('')
|
const area = ref('')
|
||||||
// 选择台桌索引
|
// 选择台桌索引
|
||||||
const tableItemActive = ref(-1)
|
const tableItemActive = ref(0)
|
||||||
// 选择台桌信息
|
// 选择台桌信息
|
||||||
const slectTable = ref('')
|
const slectTable = ref('')
|
||||||
|
|
||||||
@@ -120,33 +149,89 @@ function tabChange(item, index) {
|
|||||||
shopTableAjax()
|
shopTableAjax()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tabItemActive = ref(-1)
|
||||||
|
function tabItemChange(item, index) {
|
||||||
|
tabItemActive.value = index
|
||||||
|
if (index == -1) {
|
||||||
|
area.value = ''
|
||||||
|
} else {
|
||||||
|
area.value = item.id
|
||||||
|
}
|
||||||
|
shopTableAjax()
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
scrollTabToCenter()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动居中滚动
|
||||||
|
const tabHeadRef = ref(null)
|
||||||
|
function scrollTabToCenter() {
|
||||||
|
const container = tabHeadRef.value
|
||||||
|
if (!container) return
|
||||||
|
|
||||||
|
// 获取当前激活的 item
|
||||||
|
const activeItem = container.querySelector('.item.active')
|
||||||
|
if (!activeItem) return
|
||||||
|
|
||||||
|
// 计算居中位置
|
||||||
|
const containerWidth = container.offsetWidth
|
||||||
|
const itemWidth = activeItem.offsetWidth
|
||||||
|
const itemLeft = activeItem.offsetLeft
|
||||||
|
|
||||||
|
// 滚动到中间(核心公式)
|
||||||
|
container.scrollTo({
|
||||||
|
left: itemLeft - containerWidth / 2 + itemWidth / 2,
|
||||||
|
behavior: 'smooth' // 丝滑滚动
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 计算当前的时间差
|
// 计算当前的时间差
|
||||||
function countTime(t) {
|
function countTime(t) {
|
||||||
let ctime = dayjs().valueOf()
|
if (!t) return '0小时1分'
|
||||||
return dayjs(ctime - t).format('H小时m分')
|
|
||||||
|
const now = dayjs().valueOf()
|
||||||
|
const createTime = dayjs(t).valueOf()
|
||||||
|
|
||||||
|
let diff = now - createTime
|
||||||
|
|
||||||
|
// 负数 或 小于1分钟,都强制显示 0小时1分
|
||||||
|
if (diff < 0 || diff < 60 * 1000) {
|
||||||
|
return '0小时1分'
|
||||||
|
}
|
||||||
|
|
||||||
|
const h = Math.floor(diff / 3600000)
|
||||||
|
const m = Math.floor((diff % 3600000) / 60000)
|
||||||
|
|
||||||
|
return `${h}小时${m}分`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 支付成功,刷新状态
|
// 支付成功,刷新状态
|
||||||
async function paySuccess() {
|
async function paySuccess() {
|
||||||
|
drawerVisible.value = false
|
||||||
await shopTableAjax()
|
await shopTableAjax()
|
||||||
slectTableHandle(tableItemActive.value, tableList.value[tableItemActive.value])
|
// slectTableHandle(tableItemActive.value, tableList.value[tableItemActive.value])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选择台桌
|
// 选择台桌
|
||||||
|
const drawerVisible = ref(false)
|
||||||
function slectTableHandle(index, item) {
|
function slectTableHandle(index, item) {
|
||||||
if (tableItemActive.value == index) {
|
tableItemActive.value = index
|
||||||
tableItemActive.value = -1
|
drawerVisible.value = true
|
||||||
slectTable.value = ''
|
// if (tableItemActive.value == index) {
|
||||||
} else {
|
// tableItemActive.value = -1
|
||||||
tableItemActive.value = index
|
// slectTable.value = ''
|
||||||
slectTable.value = item
|
// } else {
|
||||||
}
|
// tableItemActive.value = index
|
||||||
|
// slectTable.value = item
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭台桌
|
// 关闭台桌
|
||||||
function slectTableClose() {
|
function slectTableClose() {
|
||||||
tableItemActive.value = -1
|
tableItemActive.value = -1
|
||||||
slectTable.value = ''
|
slectTable.value = ''
|
||||||
|
drawerVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取台桌区域
|
// 获取台桌区域
|
||||||
@@ -163,12 +248,21 @@ async function shopAreaAjax() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取台桌列表
|
// 获取台桌列表
|
||||||
async function shopTableAjax() {
|
async function shopTableAjax(isLoading = true) {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
orderInfo.value = {
|
||||||
|
num: 0,
|
||||||
|
personNum: 0,
|
||||||
|
amount: 0
|
||||||
|
}
|
||||||
|
if (isLoading) {
|
||||||
|
loading.value = true
|
||||||
|
}
|
||||||
const res = await shopTable({
|
const res = await shopTable({
|
||||||
page: query.value.page,
|
// page: query.value.page,
|
||||||
size: query.value.size,
|
// size: query.value.size,
|
||||||
|
page: 1,
|
||||||
|
size: 999,
|
||||||
areaId: area.value,
|
areaId: area.value,
|
||||||
tableCode: '',
|
tableCode: '',
|
||||||
name: '',
|
name: '',
|
||||||
@@ -176,19 +270,60 @@ async function shopTableAjax() {
|
|||||||
})
|
})
|
||||||
tableList.value = res.records
|
tableList.value = res.records
|
||||||
query.value.total = +res.totalRow
|
query.value.total = +res.totalRow
|
||||||
setTimeout(() => {
|
|
||||||
loading.value = false
|
tableList.value.forEach(item => {
|
||||||
}, 500)
|
if (item.status == 'unsettled') {
|
||||||
|
orderInfo.value.num += 1
|
||||||
|
orderInfo.value.personNum += item.personNum || 0
|
||||||
|
orderInfo.value.amount += item.orderAmount || 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (isLoading) {
|
||||||
|
setTimeout(() => {
|
||||||
|
loading.value = false
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loading.value = false
|
if (isLoading) {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refreshKey = ref(0)
|
||||||
|
|
||||||
|
// 精准【每分钟 00 秒】自动刷新时间(和时钟完全同步)
|
||||||
|
let timeTimer = null
|
||||||
|
|
||||||
|
function syncMinuteRefresh() {
|
||||||
|
// 1. 计算当前时间距离下一个 00 秒还剩多少毫秒
|
||||||
|
const now = new Date()
|
||||||
|
const seconds = now.getSeconds()
|
||||||
|
const delay = (60 - seconds) * 1000 // 等到下一个整分钟
|
||||||
|
|
||||||
|
// 2. 等到整分钟时,执行一次刷新
|
||||||
|
setTimeout(() => {
|
||||||
|
refreshKey.value++ // 刷新时间
|
||||||
|
|
||||||
|
// 3. 之后每 60 秒执行一次(永远在 00 秒刷新)
|
||||||
|
timeTimer = setInterval(() => {
|
||||||
|
refreshKey.value++
|
||||||
|
}, 60000)
|
||||||
|
}, delay)
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
shopAreaAjax()
|
shopAreaAjax()
|
||||||
shopTableAjax()
|
shopTableAjax()
|
||||||
|
syncMinuteRefresh()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 销毁清理
|
||||||
|
onUnmounted(() => {
|
||||||
|
clearInterval(timeTimer)
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@@ -219,7 +354,7 @@ onMounted(() => {
|
|||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
|
||||||
.item {
|
.item {
|
||||||
padding: 0 10px;
|
padding: 0 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -228,6 +363,13 @@ onMounted(() => {
|
|||||||
font-size: var(--el-font-size-base);
|
font-size: var(--el-font-size-base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
@@ -252,35 +394,82 @@ onMounted(() => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.order_info {
|
||||||
|
display: flex;
|
||||||
|
padding-right: 14px;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab_container {
|
.tab_container {
|
||||||
padding: var(--el-font-size-base);
|
padding: var(--el-font-size-base);
|
||||||
|
|
||||||
.tab_head {
|
.tab_head {
|
||||||
|
width: calc(100vw - 125px);
|
||||||
padding-bottom: var(--el-font-size-base);
|
padding-bottom: var(--el-font-size-base);
|
||||||
|
overflow-x: auto;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
/* 隐藏滚动条(通用) */
|
||||||
|
scrollbar-width: none;
|
||||||
|
-ms-overflow-style: none;
|
||||||
|
|
||||||
|
|
||||||
|
.item {
|
||||||
|
height: 42px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
margin-right: 10px;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 隐藏滚动条(Chrome / Electron / Edge) */
|
||||||
|
.tab_head::-webkit-scrollbar {
|
||||||
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.overflow_y {
|
.overflow_y {
|
||||||
height: calc(100vh - 220px);
|
// height: calc(100vh - 220px);
|
||||||
|
height: calc(100vh - 162px);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab_list {
|
.tab_list {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
|
||||||
grid-template-rows: auto;
|
grid-template-rows: auto;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
|
||||||
.item {
|
.item {
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 2px;
|
padding: 4px;
|
||||||
background-color: var(--color);
|
background-color: var(--color);
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
.tab_cont {
|
.tab_cont {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
content: "";
|
content: "";
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -306,23 +495,66 @@ onMounted(() => {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
span:nth-child(1) {
|
||||||
|
/* 核心:最多两行,超出... */
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
/* 最多2行 */
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
|
/* 保证换行正常 */
|
||||||
|
white-space: normal;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab_cont {
|
.tab_cont {
|
||||||
height: 112px;
|
height: 108px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
.icon {
|
.icon_wrap {
|
||||||
color: var(--color);
|
width: 100%;
|
||||||
font-size: 30px;
|
height: 100%;
|
||||||
transform: rotate(45deg);
|
display: flex;
|
||||||
position: relative;
|
align-items: center;
|
||||||
z-index: 2
|
justify-content: center;
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
color: var(--color);
|
||||||
|
font-size: 30px;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
position: relative;
|
||||||
|
z-index: 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.using {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 20px;
|
||||||
|
padding-left: 14px;
|
||||||
|
|
||||||
|
.t1 {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.t2 {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
span {
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
331
src/views/table/index20260328.vue
Normal file
331
src/views/table/index20260328.vue
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
<template>
|
||||||
|
<div class="content">
|
||||||
|
<div class="cart_wrap card">
|
||||||
|
<div class="header">
|
||||||
|
<div class="menus">
|
||||||
|
<div class="item" :class="{ active: tabActive == index }" v-for="(item, index) in tabAreas"
|
||||||
|
:key="item.id" @click="tabChange(item, index)">
|
||||||
|
<el-text>{{ item.label }}</el-text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- <div class="all">
|
||||||
|
<el-button type="link" icon="Clock">预定管理</el-button>
|
||||||
|
</div> -->
|
||||||
|
</div>
|
||||||
|
<div class="tab_container">
|
||||||
|
<div class="tab_head">
|
||||||
|
<el-radio-group v-model="area" @change="shopTableAjax">
|
||||||
|
<el-radio-button label="全部" value=""></el-radio-button>
|
||||||
|
<el-radio-button :label="item.name" :value="item.id" v-for="item in areaList"
|
||||||
|
:key="item.id"></el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
</div>
|
||||||
|
<div class="overflow_y" v-loading="loading">
|
||||||
|
<div class="tab_list">
|
||||||
|
<div class="item" :class="{ active: tableItemActive == index }"
|
||||||
|
:style="{ '--color': tableStatusList.find(val => val.type == item.status).color }"
|
||||||
|
v-for="(item, index) in tableList" :key="item.id" @click="slectTableHandle(index, item)">
|
||||||
|
<div class="tab_title" :class="`${item.status}`">
|
||||||
|
<span>{{ item.name }}</span>
|
||||||
|
<span>0/{{ item.maxCapacity }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="tab_cont">
|
||||||
|
<el-icon class="icon" v-if="item.status != 'using'">
|
||||||
|
<CircleClose />
|
||||||
|
</el-icon>
|
||||||
|
<div class="using" v-else>
|
||||||
|
<div class="t1">开台中</div>
|
||||||
|
<!-- <div class="t2">
|
||||||
|
<el-icon>
|
||||||
|
<Timer />
|
||||||
|
</el-icon>
|
||||||
|
<span>{{ countTime(item.updatedAt) }}</span>
|
||||||
|
</div> -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="empty" v-if="!tableList.length">
|
||||||
|
<el-empty description="空空如也~" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="pagination">
|
||||||
|
<el-pagination background v-model:current-page="query.page" :pager-count="5"
|
||||||
|
layout=" pager, jumper, total" :total="query.total"
|
||||||
|
@current-change="shopTableAjax"></el-pagination>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="right_card card">
|
||||||
|
<!-- 台桌统计 -->
|
||||||
|
<countCard v-if="!slectTable.id" />
|
||||||
|
<!-- 台桌信息 -->
|
||||||
|
<tableInfo v-else :tableInfo="slectTable" @close="slectTableClose" @success="paySuccess" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { shopArea, shopTable } from "@/api/account.js";
|
||||||
|
import countCard from '@/views/table/components/countCard.vue'
|
||||||
|
import tableInfo from '@/views/table/components/tableInfo.vue'
|
||||||
|
import { ref, onMounted } from 'vue'
|
||||||
|
import { dayjs } from 'element-plus'
|
||||||
|
import tableStatusList from './statusList.js'
|
||||||
|
|
||||||
|
const tabActive = ref(0)
|
||||||
|
const tabAreas = ref([
|
||||||
|
{
|
||||||
|
label: '全部',
|
||||||
|
type: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '空闲',
|
||||||
|
type: 'idle',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '使用中',
|
||||||
|
type: 'unsettled'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '待清理',
|
||||||
|
type: 'settled',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '已预订',
|
||||||
|
type: 'subscribe',
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
const query = ref({
|
||||||
|
page: 1,
|
||||||
|
size: 12,
|
||||||
|
total: 0
|
||||||
|
})
|
||||||
|
const loading = ref(false)
|
||||||
|
// 区域列表
|
||||||
|
const areaList = ref([])
|
||||||
|
// 台桌列表
|
||||||
|
const tableList = ref([])
|
||||||
|
// 所选区域
|
||||||
|
const area = ref('')
|
||||||
|
// 选择台桌索引
|
||||||
|
const tableItemActive = ref(-1)
|
||||||
|
// 选择台桌信息
|
||||||
|
const slectTable = ref('')
|
||||||
|
|
||||||
|
// 切换类型
|
||||||
|
function tabChange(item, index) {
|
||||||
|
tabActive.value = index
|
||||||
|
shopTableAjax()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算当前的时间差
|
||||||
|
function countTime(t) {
|
||||||
|
let ctime = dayjs().valueOf()
|
||||||
|
return dayjs(ctime - t).format('H小时m分')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付成功,刷新状态
|
||||||
|
async function paySuccess() {
|
||||||
|
await shopTableAjax()
|
||||||
|
slectTableHandle(tableItemActive.value, tableList.value[tableItemActive.value])
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择台桌
|
||||||
|
function slectTableHandle(index, item) {
|
||||||
|
if (tableItemActive.value == index) {
|
||||||
|
tableItemActive.value = -1
|
||||||
|
slectTable.value = ''
|
||||||
|
} else {
|
||||||
|
tableItemActive.value = index
|
||||||
|
slectTable.value = item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭台桌
|
||||||
|
function slectTableClose() {
|
||||||
|
tableItemActive.value = -1
|
||||||
|
slectTable.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取台桌区域
|
||||||
|
async function shopAreaAjax() {
|
||||||
|
try {
|
||||||
|
const res = await shopArea({
|
||||||
|
page: 1,
|
||||||
|
size: 500
|
||||||
|
})
|
||||||
|
areaList.value = res.records
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取台桌列表
|
||||||
|
async function shopTableAjax() {
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
const res = await shopTable({
|
||||||
|
page: query.value.page,
|
||||||
|
size: query.value.size,
|
||||||
|
areaId: area.value,
|
||||||
|
tableCode: '',
|
||||||
|
name: '',
|
||||||
|
status: tabAreas.value[tabActive.value].type,
|
||||||
|
})
|
||||||
|
tableList.value = res.records
|
||||||
|
query.value.total = +res.totalRow
|
||||||
|
setTimeout(() => {
|
||||||
|
loading.value = false
|
||||||
|
}, 500)
|
||||||
|
} catch (error) {
|
||||||
|
loading.value = false
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
shopAreaAjax()
|
||||||
|
shopTableAjax()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.pagination {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding-top: var(--el-font-size-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart_wrap {
|
||||||
|
flex: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right_card {
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
margin-left: var(--el-font-size-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
height: var(--el-component-size-large);
|
||||||
|
justify-content: space-between;
|
||||||
|
border-bottom: 1px solid #ececec;
|
||||||
|
|
||||||
|
.menus {
|
||||||
|
display: flex;
|
||||||
|
padding: 0 10px;
|
||||||
|
|
||||||
|
.item {
|
||||||
|
padding: 0 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size: var(--el-font-size-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: "";
|
||||||
|
width: 70%;
|
||||||
|
height: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 15%;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.all {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab_container {
|
||||||
|
padding: var(--el-font-size-base);
|
||||||
|
|
||||||
|
.tab_head {
|
||||||
|
padding-bottom: var(--el-font-size-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
.overflow_y {
|
||||||
|
height: calc(100vh - 220px);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab_list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
|
grid-template-rows: auto;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
|
.item {
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 2px;
|
||||||
|
background-color: var(--color);
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
.tab_cont {
|
||||||
|
position: relative;
|
||||||
|
&::before {
|
||||||
|
content: "";
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
background-color: var(--color);
|
||||||
|
opacity: .2;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab_title {
|
||||||
|
height: var(--el-component-size-large);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0 10px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab_cont {
|
||||||
|
height: 112px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 4px;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
color: var(--color);
|
||||||
|
font-size: 30px;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
position: relative;
|
||||||
|
z-index: 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -179,16 +179,8 @@ const exit = async () => {
|
|||||||
if (loading.value) return
|
if (loading.value) return
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
// await staffPermission('yun_xu_jiao_ban')
|
// await staffPermission('yun_xu_jiao_ban')
|
||||||
|
const res = await handover(isPrint.value)
|
||||||
// const res = await handover(isPrint.value)
|
const data = await handoverData(res)
|
||||||
// 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) {
|
if (printStore.deviceNoteList.length) {
|
||||||
// 使用本地打印机 打印交班数据
|
// 使用本地打印机 打印交班数据
|
||||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||||
@@ -198,8 +190,7 @@ const exit = async () => {
|
|||||||
// 使用云打印机 打印交班数据
|
// 使用云打印机 打印交班数据
|
||||||
await handoverNetworkPrint(data.id)
|
await handoverNetworkPrint(data.id)
|
||||||
}
|
}
|
||||||
// logoutHandle()
|
logoutHandle()
|
||||||
loading.value = false;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user