Compare commits
14 Commits
33be9f2cef
...
prod
| Author | SHA1 | Date | |
|---|---|---|---|
| fa67997c86 | |||
| 50a5aeb8e5 | |||
| 1985713f28 | |||
| 8655757dd6 | |||
| 78e88b8eb7 | |||
| 7e03547798 | |||
| c3a20ab2db | |||
| e0aba58651 | |||
| d19e1688a5 | |||
| 23b8db63b8 | |||
| c9cd3a80d9 | |||
| a5fdbd0c13 | |||
| 32d150fd15 | |||
| 5fab9a857a |
17178
dist-electron/main.js
17178
dist-electron/main.js
File diff suppressed because one or more lines are too long
@@ -5,6 +5,7 @@ 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,printRefundDish } from "./printService";
|
||||||
|
|
||||||
// ===== 核心配置:单文件缓存 =====
|
// ===== 核心配置:单文件缓存 =====
|
||||||
// 固定的缓存文件路径(永远只存这1个文件)
|
// 固定的缓存文件路径(永远只存这1个文件)
|
||||||
@@ -106,6 +107,59 @@ 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 }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 打印退菜单
|
||||||
|
ipcMain.on('printRefundDish', async (event, arg) => {
|
||||||
|
try {
|
||||||
|
let _parmas = JSON.parse(arg);
|
||||||
|
// console.log(_parmas);
|
||||||
|
await printRefundDish(_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 系统内, 如果没有已开启的应用窗口
|
||||||
// 点击托盘图标时通常会重新创建一个新窗口
|
// 点击托盘图标时通常会重新创建一个新窗口
|
||||||
|
|||||||
699
electron/printService.js
Normal file
699
electron/printService.js
Normal file
@@ -0,0 +1,699 @@
|
|||||||
|
// 网口打印机管理(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支付类型 主扫 main_scan
|
||||||
|
// 被扫 back_scan
|
||||||
|
// 微信小程序 wechat_mini
|
||||||
|
// 支付宝小程序 alipay_mini
|
||||||
|
// 会员支付 vip_pay
|
||||||
|
// 现金支付 cash_pay
|
||||||
|
// 挂账支付 credit_pay
|
||||||
|
const payTypeFilter = t => {
|
||||||
|
if (t === 'main_scan') return '主扫'
|
||||||
|
if (t === 'back_scan') return '被扫'
|
||||||
|
if (t === 'wechat_mini') return '微信小程序'
|
||||||
|
if (t === 'alipay_mini') return '支付宝小程序'
|
||||||
|
if (t === 'vip_pay') return '余额支付'
|
||||||
|
if (t === 'cash_pay') return '现金支付'
|
||||||
|
if (t === 'credit_pay') return '挂账支付'
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 打印结算小票 ========================
|
||||||
|
export function printReceipt(printerIp, order) {
|
||||||
|
// console.log('Printing receipt...', 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.orderInfo.orderNum}`
|
||||||
|
if (order.isBefore) {
|
||||||
|
title2 = `${order.isBefore ? '预' : ''}结算单 #${order.orderInfo.orderNum}`;
|
||||||
|
}
|
||||||
|
if (order.isGuest) {
|
||||||
|
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 && !order.isGuest) {
|
||||||
|
orderInfo += padLeftAlign('结账时间:', 10) + padLeftAlign(order.orderInfo.paidTime || '-', 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 => {
|
||||||
|
if (item.number > 0) {
|
||||||
|
// 套餐商品逻辑
|
||||||
|
if (item.proGroupInfo) {
|
||||||
|
// 套餐主项:正常显示 名称、单价、数量、小计
|
||||||
|
const packageName = truncateByPrintWidth(item.name || '未知套餐', 18)
|
||||||
|
orderInfo += padLeftAlign(packageName, 18)
|
||||||
|
orderInfo += padLeftAlign(formatAmount(item.salePrice), 8)
|
||||||
|
orderInfo += padLeftAlign(item.number || 1, 6)
|
||||||
|
orderInfo += padRightAlign(formatAmount(item.totalAmount), 16) + '\n'
|
||||||
|
|
||||||
|
// 套餐子项:只显示名称+规格,单价、小计全部为空
|
||||||
|
const proGroupInfo = item.proGroupInfo || []
|
||||||
|
proGroupInfo.forEach(subItem => {
|
||||||
|
const subName = truncateByPrintWidth(`>${subItem.proName || '未知商品'}`, 18)
|
||||||
|
orderInfo += padLeftAlign(subName, 18)
|
||||||
|
orderInfo += padLeftAlign('', 8) // 子项单价空
|
||||||
|
orderInfo += padLeftAlign(subItem.number || 1, 6)
|
||||||
|
orderInfo += padRightAlign('', 16) + '\n' // 子项小计空
|
||||||
|
|
||||||
|
// 子项规格换行显示
|
||||||
|
if (subItem.skuName) {
|
||||||
|
const skuText = truncateByPrintWidth(` 规格:${subItem.skuName}`, 18)
|
||||||
|
orderInfo += padLeftAlign(skuText, 18)
|
||||||
|
orderInfo += padLeftAlign('', 8)
|
||||||
|
orderInfo += padLeftAlign('', 6)
|
||||||
|
orderInfo += padRightAlign('', 16) + '\n'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 普通商品:正常显示 + 规格换行
|
||||||
|
let productName = truncateByPrintWidth(item.name || '未知商品', 18)
|
||||||
|
orderInfo += padLeftAlign(productName, 18)
|
||||||
|
orderInfo += padLeftAlign(item.salePrice ? formatAmount(item.salePrice) : '', 8)
|
||||||
|
orderInfo += padLeftAlign(item.number || 1, 6)
|
||||||
|
orderInfo += padRightAlign(formatAmount(item.totalAmount), 16) + '\n'
|
||||||
|
|
||||||
|
// 规格单独换行
|
||||||
|
if (item.skuName) {
|
||||||
|
const skuLine = truncateByPrintWidth(` 规格:${item.skuName}`, 18)
|
||||||
|
orderInfo += padLeftAlign(skuLine, 18)
|
||||||
|
orderInfo += padLeftAlign('', 8)
|
||||||
|
orderInfo += padLeftAlign('', 6)
|
||||||
|
orderInfo += padRightAlign('', 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'))
|
||||||
|
|
||||||
|
// ======================== 付款信息 ========================
|
||||||
|
if (order.isBefore) {
|
||||||
|
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 && !order.isGuest) {
|
||||||
|
const payableLine = 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(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'));
|
||||||
|
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 = ''
|
||||||
|
if (!order.isBefore && !order.isGuest) {
|
||||||
|
bottom += padLeftAlign('支付方式:', 8) + padLeftAlign(payTypeFilter(order.orderInfo.payType) || '无', 38) + '\n'
|
||||||
|
}
|
||||||
|
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 = '退款单';
|
||||||
|
|
||||||
|
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
||||||
|
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 printRefundDish(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 = '退菜单'
|
||||||
|
|
||||||
|
// 核心修复:先写入空行清空打印机缓冲区,避免残留字符干扰居中起始位置
|
||||||
|
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'))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== 付款信息 ========================
|
||||||
|
// if (order.isGuest) {
|
||||||
|
// 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('交班:', 6) + padLeftAlign(`${data.loginTime} - ${data.handoverTime}` || '-', 36) + '\n\n'
|
||||||
|
|
||||||
|
// basicInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||||
|
|
||||||
|
// 收入明细 - 补充会员支付/充值字段
|
||||||
|
basicInfo += padLeftAlign('当班营业总额:', 10) + padLeftAlign(formatAmount(data.turnover), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('实际收款的支付方式', 10) + '\n'
|
||||||
|
basicInfo += padLeftAlign('现金', 10) + padRightAlign(formatAmount(data.cash), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('微信', 10) + padRightAlign(formatAmount(data.wechat), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('支付宝', 10) + padRightAlign(formatAmount(data.alipay), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('二维码收款', 10) + padRightAlign(formatAmount(data.selfScan), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('扫码收款', 10) + padRightAlign(formatAmount(data.barScan), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('充值', 10) + padRightAlign(formatAmount(data.recharge), 36) + '\n\n'
|
||||||
|
basicInfo += padLeftAlign('非实际收款的支付方式', 10) + '\n'
|
||||||
|
basicInfo += padLeftAlign('挂账', 10) + padRightAlign(formatAmount(data.owed), 36) + '\n'
|
||||||
|
basicInfo += padLeftAlign('余额', 10) + padRightAlign(formatAmount(data.balance), 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.returnDishCount), 36) + '\n'
|
||||||
|
refundInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||||
|
socket.write(iconv.encode(refundInfo, 'gbk'))
|
||||||
|
|
||||||
|
let orderInfo = ''
|
||||||
|
const orderLabel = '订单(数量/订单总额)'
|
||||||
|
const orderValue = `${data.orderCount}/${formatAmount(data.orderTurnover)}`
|
||||||
|
const orderLabelWidth = lineWidth - getPrintWidth(orderValue)
|
||||||
|
orderInfo += padLeftAlign(orderLabel, orderLabelWidth) + orderValue + '\n\n'
|
||||||
|
socket.write(iconv.encode(orderInfo, 'gbk'))
|
||||||
|
|
||||||
|
// ======================== 分类数据区域 ========================
|
||||||
|
let categoryInfo = ''
|
||||||
|
if (data.categoryList && data.categoryList.length) {
|
||||||
|
categoryInfo += centerAlign('销售数据', lineWidth) + '\n'
|
||||||
|
categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||||
|
// 分类表头
|
||||||
|
categoryInfo += padLeftAlign('商品分类', 24) + padLeftAlign('数量', 12) + padRightAlign('总计', 12) + '\n'
|
||||||
|
// categoryInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||||
|
// 分类数据行
|
||||||
|
data.categoryList.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.detailList && data.detailList.length) {
|
||||||
|
// productInfo += centerAlign('商品数据', lineWidth) + '\n'
|
||||||
|
// productInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||||
|
// // 商品表头
|
||||||
|
// productInfo += padLeftAlign('商品', 36) + padRightAlign('数量', 12) + '\n'
|
||||||
|
// // productInfo += createDivider(lineWidth, 'thin') + '\n'
|
||||||
|
// // 商品数据行
|
||||||
|
// data.detailList.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 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', () => { })
|
||||||
|
})
|
||||||
|
}
|
||||||
1154
package-lock.json
generated
1154
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.25",
|
||||||
"main": "dist-electron/main.js",
|
"main": "dist-electron/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "chcp 65001 && vite",
|
"dev": "chcp 65001 && vite",
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"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",
|
||||||
@@ -30,13 +31,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",
|
||||||
"ysk-utils": "^1.0.84"
|
"win32-api": "^26.1.2",
|
||||||
|
"ysk-utils": "^1.0.85"
|
||||||
},
|
},
|
||||||
"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",
|
||||||
|
|||||||
BIN
printer.sdk.dll
Normal file
BIN
printer.sdk.dll
Normal file
Binary file not shown.
@@ -317,11 +317,11 @@ export function handoverNetworkPrint(id) {
|
|||||||
export function printerList(subType = "") {
|
export function printerList(subType = "") {
|
||||||
return request({
|
return request({
|
||||||
method: "get",
|
method: "get",
|
||||||
url: "/account/admin/printer",
|
url: "/account/admin/printer/getPrintLocal",
|
||||||
params: {
|
params: {
|
||||||
name: "",
|
name: "",
|
||||||
subType: subType,
|
subType: subType,
|
||||||
connectionType: "USB",
|
connectionType: "",
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,3 +51,83 @@ 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询存取酒记录
|
||||||
|
* @param {*} data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function shopStorageRecord(params) {
|
||||||
|
return request({
|
||||||
|
method: "get",
|
||||||
|
url: "/product/admin/shopStorage/record",
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材库存列表接口
|
||||||
|
* @param {*} data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function consStock(params) {
|
||||||
|
return request({
|
||||||
|
method: "get",
|
||||||
|
url: "/product/admin/product/cons/consStock",
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { formatDecimal } from "@/utils/index.js";
|
|||||||
* 打印订单小票
|
* 打印订单小票
|
||||||
*/
|
*/
|
||||||
export default (data) => {
|
export default (data) => {
|
||||||
// console.log("需要打印的订单数据===", data);
|
console.log("需要打印的订单数据===", data);
|
||||||
// console.log("data.deviceName===", data.deviceName);
|
// console.log("data.deviceName===", data.deviceName);
|
||||||
let LODOP = getLodop();
|
let LODOP = getLodop();
|
||||||
LODOP.PRINT_INIT("打印小票");
|
LODOP.PRINT_INIT("打印小票");
|
||||||
|
|||||||
@@ -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']);
|
||||||
|
|
||||||
@@ -470,13 +486,50 @@ function upadatePayData() {
|
|||||||
newCustomerDiscountId: goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.id : goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.id : '', // 新客立减Id
|
newCustomerDiscountId: goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.id : goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.id : '', // 新客立减Id
|
||||||
newCustomerDiscountAmount: goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.amount : 0, // 新客立减金额
|
newCustomerDiscountAmount: goodsStore.newUserDiscount !== null ? goodsStore.newUserDiscount.amount : 0, // 新客立减金额
|
||||||
vipDiscountAmount: goodsStore.cartInfo.costSummary.vipDiscountAmount, // 超级会员折扣
|
vipDiscountAmount: goodsStore.cartInfo.costSummary.vipDiscountAmount, // 超级会员折扣
|
||||||
remark: '', // 现金支付备注
|
remark: goodsStore.remark, // 现金支付备注
|
||||||
|
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 结算支付
|
// 结算支付
|
||||||
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 +539,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();
|
||||||
@@ -508,9 +560,9 @@ async function confirmOrder() {
|
|||||||
ElMessageBox.prompt('确定现金支付?', '注意', {
|
ElMessageBox.prompt('确定现金支付?', '注意', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
inputPlaceholder: '请输入备注(选填)',
|
inputPlaceholder: goodsStore.remark ? goodsStore.remark : '请输入备注(选填)',
|
||||||
}).then(async ({ value }) => {
|
}).then(async ({ value }) => {
|
||||||
payData.value.checkOrderPay.remark = value;
|
payData.value.checkOrderPay.remark = value ? value : goodsStore.remark;
|
||||||
if (props.selecttype == 0) {
|
if (props.selecttype == 0) {
|
||||||
payLoading.loading = true
|
payLoading.loading = true
|
||||||
await cashPay(payData.value);
|
await cashPay(payData.value);
|
||||||
@@ -576,6 +628,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 +784,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 +1343,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);
|
||||||
|
|||||||
83
src/components/refundConsModal.vue
Normal file
83
src/components/refundConsModal.vue
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog title="提示" width="450px" v-model="visible">
|
||||||
|
<div class="refund_content">
|
||||||
|
<div class="title_wrap">请确认当前菜品是否已上菜</div>
|
||||||
|
<div class="list_wrap">
|
||||||
|
<div class="item" v-for="(item, index) in list" :key="index">
|
||||||
|
<span>{{ item.name }}</span>
|
||||||
|
<span>x{{ item.num }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="dialog_footer">
|
||||||
|
<div class="btn">
|
||||||
|
<el-button @click="handleCancel" style="width: 100%;">未上菜(退还库存)</el-button>
|
||||||
|
</div>
|
||||||
|
<div class="btn">
|
||||||
|
<el-button type="primary" @click="handleOk" style="width: 100%;">已上菜(不退库存)</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
const visible = ref(false)
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
list: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const emits = defineEmits(['success'])
|
||||||
|
|
||||||
|
// 未上菜 1退菜图库存
|
||||||
|
function handleCancel() {
|
||||||
|
visible.value = false
|
||||||
|
emits('success', 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 已上菜 2仅退菜不退库存
|
||||||
|
function handleOk() {
|
||||||
|
visible.value = false
|
||||||
|
emits('success', 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
visible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
show
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.refund_content {
|
||||||
|
.title_wrap {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list_wrap {
|
||||||
|
padding-top: 14px;
|
||||||
|
.item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog_footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 20px;
|
||||||
|
padding-top: 20px;
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<span class="i">¥</span>
|
<span class="i">¥</span>
|
||||||
<span class="n">{{ formatDecimal(+goodsInfo.salePrice) }}</span>
|
<span class="n">{{ formatDecimal(+goodsInfo.salePrice) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<span>库存:{{ stockNumber }}</span>
|
<span>库存:{{ stockNumber || 0 }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn_wrap">
|
<div class="btn_wrap">
|
||||||
<div class="btn">
|
<div class="btn">
|
||||||
|
|||||||
@@ -119,46 +119,20 @@ export const useGlobal = defineStore("global", {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
bizCodes: [
|
bizCodes: [
|
||||||
{
|
{ type: "cashIn", label: "会员充值" },
|
||||||
type: "freeln",
|
{ type: "cashback", label: "消费返现" },
|
||||||
label: "霸王餐",
|
{ type: "cashback_refund", label: "消费返现扣减" },
|
||||||
},
|
{ type: "freeIn", label: "霸王餐充值" },
|
||||||
{
|
{ type: "awardIn", label: "充值奖励" },
|
||||||
type: "cashIn",
|
{ type: "wechatIn", label: "微信小程序充值" },
|
||||||
label: "现金充值",
|
{ type: "alipayIn", label: "支付宝小程序充值" },
|
||||||
},
|
{ type: "orderPay", label: "订单支付奖励" },
|
||||||
{
|
{ type: "orderRefund", label: "订单退款" },
|
||||||
type: "wechatIn",
|
{ type: "rechargeRefund", label: "充值退款" },
|
||||||
label: "微信小程序充值",
|
{ type: "rechargeCashRefund", label: "会员现金退款" },
|
||||||
},
|
{ type: "adminIn", label: "管理员手动增减余额" },
|
||||||
{
|
{ type: "adminOut", label: "管理员退款充值" },
|
||||||
type: "alipayIn",
|
{ type: "rechargeRedemption", label: "充值兑换码" }
|
||||||
label: "支付宝小程序充值",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "awardIn",
|
|
||||||
label: "充值奖励",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "rechargeRefund",
|
|
||||||
label: "充值退款",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "orderPay",
|
|
||||||
label: "订单消费",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "orderRefund",
|
|
||||||
label: "订单退款",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "adminIn",
|
|
||||||
label: "管理员充值",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "adminOut",
|
|
||||||
label: "管理员消费",
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
refundType: [
|
refundType: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import _ from "lodash";
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref, computed, nextTick } from "vue";
|
import { ref, computed, nextTick } from "vue";
|
||||||
import { productPage, categoryList } from "@/api/product_new.js";
|
import { productPage, categoryList, consStock } from "@/api/product_new.js";
|
||||||
import { historyOrder, cancelOrder, rmPlaceOrder } from "@/api/order.js";
|
import { historyOrder, cancelOrder, rmPlaceOrder } from "@/api/order.js";
|
||||||
import { getLimitTimeDiscount, getDiscountActivity, getDiscountByUserId } from '@/api/market'
|
import { getLimitTimeDiscount, getDiscountActivity, getDiscountByUserId } from '@/api/market'
|
||||||
import { useUser } from "@/store/user.js";
|
import { useUser } from "@/store/user.js";
|
||||||
@@ -36,6 +36,7 @@ const initialCostSummary = {
|
|||||||
// 商品store + 购物车store
|
// 商品store + 购物车store
|
||||||
export const useGoods = defineStore("goods", {
|
export const useGoods = defineStore("goods", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
remark: "", // 订单备注
|
||||||
showVipPrice: 0,
|
showVipPrice: 0,
|
||||||
allSelected: 0, // 是否整单打包
|
allSelected: 0, // 是否整单打包
|
||||||
vipUserInfo: {}, // 会员信息
|
vipUserInfo: {}, // 会员信息
|
||||||
@@ -46,6 +47,7 @@ export const useGoods = defineStore("goods", {
|
|||||||
}, // 台桌信息
|
}, // 台桌信息
|
||||||
cartActiveIndex: 0, // 购物车激活索引,
|
cartActiveIndex: 0, // 购物车激活索引,
|
||||||
isCartInit: false,
|
isCartInit: false,
|
||||||
|
payType: "cart", // 结算类型,cart 购物车结算 table 桌台结算 order 订单结算,
|
||||||
cartList: [], // 购物车列表
|
cartList: [], // 购物车列表
|
||||||
// 购物车信息,
|
// 购物车信息,
|
||||||
cartInfo: {
|
cartInfo: {
|
||||||
@@ -60,6 +62,7 @@ export const useGoods = defineStore("goods", {
|
|||||||
goodsListLoading: false, // 商品列表加载状态
|
goodsListLoading: false, // 商品列表加载状态
|
||||||
goodsList: [], // 商品列表
|
goodsList: [], // 商品列表
|
||||||
originGoodsList: [], // 原始商品列表
|
originGoodsList: [], // 原始商品列表
|
||||||
|
consList: [], // 耗材列表
|
||||||
orderList: [], // 订单列表
|
orderList: [], // 订单列表
|
||||||
orderListInfo: "", // 历史订单信息
|
orderListInfo: "", // 历史订单信息
|
||||||
cartType: "cart", // cart order
|
cartType: "cart", // cart order
|
||||||
@@ -86,7 +89,6 @@ export const useGoods = defineStore("goods", {
|
|||||||
// 清除会员信息
|
// 清除会员信息
|
||||||
async clearVipUserInfo() {
|
async clearVipUserInfo() {
|
||||||
// console.log('清除会员信息');
|
// console.log('清除会员信息');
|
||||||
|
|
||||||
this.vipUserInfo = {};
|
this.vipUserInfo = {};
|
||||||
this.showVipPrice = 0;
|
this.showVipPrice = 0;
|
||||||
|
|
||||||
@@ -302,8 +304,18 @@ export const useGoods = defineStore("goods", {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 耗材库存列表接口
|
||||||
|
async consStockAjax() {
|
||||||
|
try {
|
||||||
|
const store = useUser()
|
||||||
|
this.consList = await consStock({ shopId: store.shopInfo.id })
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
// 初始化商品
|
// 初始化商品
|
||||||
async initGoods() {
|
async initGoods() {
|
||||||
|
await this.consStockAjax()
|
||||||
await this.getCategoryList();
|
await this.getCategoryList();
|
||||||
await this.getGoodsList();
|
await this.getGoodsList();
|
||||||
|
|
||||||
@@ -371,6 +383,50 @@ export const useGoods = defineStore("goods", {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 给商品列表批量添加 isSoldOut 售罄状态字段
|
||||||
|
* @param {Array} goodsList - 商品列表 [ { consList, isAutoSoldStock } ]
|
||||||
|
* @param {Array} consStockList - 真实耗材库存列表 [ { consId, stockNumber } ]
|
||||||
|
* @returns 带 isSoldOut 字段的新商品列表
|
||||||
|
*/
|
||||||
|
addGoodsSoldOutStatus(goodsList, consStockList) {
|
||||||
|
// console.log('addGoodsSoldOutStatus.goodsList', goodsList);
|
||||||
|
// console.log('addGoodsSoldOutStatus.consStockList', consStockList);
|
||||||
|
|
||||||
|
// 耗材ID映射真实库存(保留)
|
||||||
|
const consMap = _.keyBy(consStockList, item => String(item.consId));
|
||||||
|
|
||||||
|
return _.map(goodsList, goods => {
|
||||||
|
let isSoldOut = false;
|
||||||
|
|
||||||
|
// 开启自动售罄才判断
|
||||||
|
if (goods.isAutoSoldStock === 1 || goods.isAutoSoldStock === true) {
|
||||||
|
const goodsConsList = goods.consList || [];
|
||||||
|
|
||||||
|
// 无耗材 → 不售罄
|
||||||
|
if (goodsConsList.length === 0) {
|
||||||
|
isSoldOut = false;
|
||||||
|
} else {
|
||||||
|
// 核心:只要有一个耗材 真实库存 < 商品需要量 → 售罄
|
||||||
|
isSoldOut = _.some(goodsConsList, consItem => {
|
||||||
|
// 商品绑定的耗材ID(对应真实库存ID)
|
||||||
|
const consId = String(consItem.consInfoId);
|
||||||
|
// 商品需要消耗的数量(你的需求量)
|
||||||
|
const needStock = consItem.surplusStock || 0;
|
||||||
|
// 起售数量
|
||||||
|
const suitNum = goods.type == 'single' ? goods.skuList[0].suitNum : 1;
|
||||||
|
// 真实库存
|
||||||
|
const realStock = _.get(consMap, [consId, 'stockNumber'], 0);
|
||||||
|
|
||||||
|
// 真实库存 < 需要量 → 不足 → 售罄
|
||||||
|
return realStock < needStock * suitNum;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...goods, isSoldOut };
|
||||||
|
});
|
||||||
|
},
|
||||||
// 获取商品列表/更新商品列表
|
// 获取商品列表/更新商品列表
|
||||||
async getGoodsList() {
|
async getGoodsList() {
|
||||||
try {
|
try {
|
||||||
@@ -386,7 +442,11 @@ export const useGoods = defineStore("goods", {
|
|||||||
name: this.goodsName,
|
name: this.goodsName,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.originGoodsList = await productPage();
|
let ores = await productPage();
|
||||||
|
|
||||||
|
this.originGoodsList = this.addGoodsSoldOutStatus(ores, this.consList)
|
||||||
|
|
||||||
|
console.log('添加库存售罄的商品原始数据', this.originGoodsList);
|
||||||
|
|
||||||
// 获取限时折扣
|
// 获取限时折扣
|
||||||
this.limitDiscountRes = await getLimitTimeDiscount({ shopId: store.shopInfo.id })
|
this.limitDiscountRes = await getLimitTimeDiscount({ shopId: store.shopInfo.id })
|
||||||
@@ -441,18 +501,6 @@ export const useGoods = defineStore("goods", {
|
|||||||
|
|
||||||
this.goodsList.forEach(val => {
|
this.goodsList.forEach(val => {
|
||||||
val.forEach((item, index) => {
|
val.forEach((item, index) => {
|
||||||
// console.log('this.goodsList.index', index);
|
|
||||||
// console.log('this.goodsList.item', item);
|
|
||||||
// console.log('this.goodsList.limitDiscountRes', this.limitDiscountRes);
|
|
||||||
// console.log('this.goodsList.store.shopInfo', store.shopInfo);
|
|
||||||
// console.log('this.goodsList.this.vipUserInfo', this.vipUserInfo);
|
|
||||||
// console.log('this.goodsList.this.vipUserInfo', JSON.stringify(this.vipUserInfo));
|
|
||||||
// console.log('this.goodsList.this.canUseLimitTimeDiscount', limitUtils.canUseLimitTimeDiscount(item,
|
|
||||||
// this.limitDiscountRes,
|
|
||||||
// store.shopInfo,
|
|
||||||
// this.vipUserInfo, 'id'));
|
|
||||||
|
|
||||||
|
|
||||||
item.showMore = false;
|
item.showMore = false;
|
||||||
item.orderCount = 0;
|
item.orderCount = 0;
|
||||||
item.memberPrice = item.lowMemberPrice
|
item.memberPrice = item.lowMemberPrice
|
||||||
@@ -889,7 +937,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,30 +11,28 @@ import { useSocket } from './socket.js';
|
|||||||
|
|
||||||
export const usePrint = defineStore("print", {
|
export const usePrint = defineStore("print", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
isPrintService: false, // 打印服务是否启动
|
isPrintService: false,
|
||||||
printServiceTimer: false, // 打印服务定时器
|
printServiceTimer: null,
|
||||||
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"
|
||||||
@@ -42,18 +40,12 @@ 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 (
|
||||||
@@ -61,210 +53,373 @@ 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);
|
||||||
},
|
},
|
||||||
// 检查本地打印机是否能正常使用
|
|
||||||
checkLocalPrint(address) {
|
// 检查打印机是否可用
|
||||||
let print = "";
|
checkPrinterAvailable(printer) {
|
||||||
for (let item of this.localDevices) {
|
if (printer.connectionType === "局域网") {
|
||||||
if (item.name == address) {
|
const ipReg = /^(\d{1,3}\.){3}\d{1,3}$/;
|
||||||
print = item;
|
return ipReg.test(printer.address);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!print.name) {
|
if (printer.connectionType === "USB") {
|
||||||
return false;
|
return this.localDevices.some(item => item.name === printer.address);
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
// 打印标签小票
|
|
||||||
labelPrint(props) {
|
|
||||||
const store = useUser();
|
|
||||||
|
|
||||||
if (
|
// 辅助方法:判断是否为特殊费用项(餐位费/打包费)
|
||||||
this.deviceLableList.length &&
|
isSpecialFeeItem(item) {
|
||||||
this.checkLocalPrint(this.deviceLableList[0].address)
|
// 可根据实际业务调整判断条件,比如通过名称/标识判断
|
||||||
) {
|
const specialNames = ["餐位费", "打包费"];
|
||||||
let pids = this.deviceLableList[0].categoryList;
|
// 条件:1. 无categoryId 2. 名称包含特殊费用关键词 或 标记了特殊标识
|
||||||
let count = 0;
|
return !item.categoryId && (item.isSpecialFee || specialNames.some(name => item.name?.includes(name)));
|
||||||
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;
|
// 优化:保留无categoryId的特殊费用项,兼容原有分类过滤逻辑
|
||||||
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) {
|
pushReceiptData(props, isDevice = true) {
|
||||||
// console.log("pushReceiptData===", props);
|
|
||||||
if (!isDevice) {
|
if (!isDevice) {
|
||||||
// 测试打印,无需校验本地打印机
|
|
||||||
this.receiptList.push(props);
|
this.receiptList.push(props);
|
||||||
this.startReceiptPrint();
|
this.startReceiptPrint();
|
||||||
} else {
|
return;
|
||||||
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);
|
const validPrinters = this.deviceNoteList.filter(p => {
|
||||||
this.startReceiptPrint();
|
return this.checkPrinterAvailable(p) && this.isPrintService;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validPrinters.length === 0) {
|
||||||
|
console.log("无可用小票打印机");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = useUser();
|
||||||
|
|
||||||
|
validPrinters.forEach(printer => {
|
||||||
|
let filterCarts = [];
|
||||||
|
|
||||||
|
// 核心过滤逻辑:
|
||||||
|
// 1. 分类为空 → 打印全部(包含特殊费用项)
|
||||||
|
// 2. 分类非空 → 打印「匹配分类的商品」+「无categoryId的特殊费用项」
|
||||||
|
if (!printer.categoryList || printer.categoryList.length === 0) {
|
||||||
|
filterCarts = props.carts || [];
|
||||||
} else {
|
} else {
|
||||||
console.log("订单小票:未在本机查询到打印机");
|
filterCarts = (props.carts || []).filter(item => {
|
||||||
|
// 保留:特殊费用项(无categoryId) + 匹配分类的商品(有categoryId)
|
||||||
|
return this.isSpecialFeeItem(item) || 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() {
|
async startReceiptPrint() {
|
||||||
try {
|
try {
|
||||||
const socketStore = useSocket();
|
const socketStore = useSocket();
|
||||||
const userStore = useUser();
|
const userStore = useUser();
|
||||||
|
|
||||||
if (this.receiptTimer !== null) return;
|
if (this.receiptTimer !== null) return;
|
||||||
|
|
||||||
this.receiptTimer = setInterval(() => {
|
this.receiptTimer = setInterval(() => {
|
||||||
if (!this.receiptList.length) {
|
if (!this.receiptList.length) {
|
||||||
clearInterval(this.receiptTimer);
|
clearInterval(this.receiptTimer);
|
||||||
this.receiptTimer = null;
|
this.receiptTimer = null;
|
||||||
} else {
|
return;
|
||||||
receiptPrint(this.receiptList[0]);
|
}
|
||||||
// 在这里触发已打印操作标记
|
|
||||||
const data = {
|
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",
|
type: "cashier",
|
||||||
operate_type: "order_print_status",
|
operate_type: "order_print_status",
|
||||||
table_code: this.receiptList[0].orderInfo.tableCode,
|
table_code: printData.orderInfo.tableCode,
|
||||||
account: userStore.shopInfo.account,
|
account: userStore.shopInfo.account,
|
||||||
print_status: "1",
|
print_status: "1",
|
||||||
order_id: this.receiptList[0].orderInfo.id,
|
order_id: printData.orderInfo.id,
|
||||||
print_id: this.receiptList[0].deviceId,
|
print_id: printData.deviceId,
|
||||||
shop_id: this.receiptList[0].orderInfo.shopId,
|
shop_id: printData.orderInfo.shopId,
|
||||||
}
|
};
|
||||||
socketStore.ws.send(JSON.stringify(data));
|
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);
|
this.receiptList.splice(0, 1);
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log("打印定时器异常", error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 打印交班小票
|
|
||||||
|
// ————————————————————————————————
|
||||||
|
// 以下原有代码完全保留,仅优化格式和可读性
|
||||||
|
// ————————————————————————————————
|
||||||
|
checkLocalPrint(address) {
|
||||||
|
const targetPrinter = this.localDevices.find(item => item.name === address);
|
||||||
|
return !!targetPrinter?.name;
|
||||||
|
},
|
||||||
|
|
||||||
|
labelPrint(props) {
|
||||||
|
const store = useUser();
|
||||||
|
const validLabelPrinter = this.deviceLableList[0];
|
||||||
|
|
||||||
|
if (!validLabelPrinter || !this.checkLocalPrint(validLabelPrinter.address)) {
|
||||||
|
console.log("标签打印:未在本机查询到打印机");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pids = validLabelPrinter.categoryList;
|
||||||
|
let totalCount = 0;
|
||||||
|
let currentCount = 0;
|
||||||
|
|
||||||
|
// 先计算总打印数量
|
||||||
|
props.carts.forEach(item => {
|
||||||
|
if (pids.some(el => el === item.categoryId)) {
|
||||||
|
totalCount += item.number;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 构建标签打印列表
|
||||||
|
props.carts.forEach(item => {
|
||||||
|
if (pids.some(el => el === item.categoryId)) {
|
||||||
|
for (let i = 0; i < item.number; i++) {
|
||||||
|
currentCount++;
|
||||||
|
this.labelList.push({
|
||||||
|
outNumber: props.outNumber,
|
||||||
|
name: item.name,
|
||||||
|
skuName: item.skuName,
|
||||||
|
masterId: props.orderInfo.tableName,
|
||||||
|
deviceName: validLabelPrinter.address,
|
||||||
|
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
isPrint: false,
|
||||||
|
count: `${currentCount}/${totalCount}`,
|
||||||
|
ticketLogo: store.shopInfo.ticketLogo,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.startLabelPrint();
|
||||||
|
},
|
||||||
|
|
||||||
|
startLabelPrint() {
|
||||||
|
if (this.printTimer != null) return;
|
||||||
|
|
||||||
|
this.printTimer = setInterval(() => {
|
||||||
|
if (!this.labelList.length) {
|
||||||
|
clearInterval(this.printTimer);
|
||||||
|
this.printTimer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = this.labelList[0];
|
||||||
|
if (!item.isPrint) {
|
||||||
|
ipcRenderer.send("printerTagSync", JSON.stringify(item));
|
||||||
|
this.labelList[0].isPrint = true;
|
||||||
|
this.labelList.splice(0, 1);
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 打印交班小票(优化:1. 新增handoverSwitch=1才打印 2. 兼容局域网打印机)
|
||||||
printWork(data) {
|
printWork(data) {
|
||||||
if (
|
// 筛选条件:状态启用 + 小票类型 + handoverSwitch=1 + 打印机可用 + 打印服务正常
|
||||||
this.deviceNoteList.length &&
|
const validPrinters = this.deviceNoteList.filter(p => {
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
return p.status
|
||||||
) {
|
&& p.subType === "cash"
|
||||||
data.deviceName = this.deviceNoteList[0].address;
|
&& p.handoverSwitch === 1
|
||||||
lodopPrintWork(data);
|
&& this.checkPrinterAvailable(p)
|
||||||
} else {
|
&& this.isPrintService;
|
||||||
console.log("交班小票:未在本机查询到打印机");
|
});
|
||||||
|
|
||||||
|
if (validPrinters.length === 0) {
|
||||||
|
console.log("交班小票:无符合条件的可用打印机(handoverSwitch≠1 或 打印机不可用)");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 遍历符合条件的打印机打印
|
||||||
|
validPrinters.forEach(printer => {
|
||||||
|
const printData = {
|
||||||
|
...data,
|
||||||
|
deviceId: printer.id,
|
||||||
|
deviceName: printer.address,
|
||||||
|
connectionType: printer.connectionType,
|
||||||
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 区分局域网和USB打印机
|
||||||
|
if (printer.connectionType === "局域网") {
|
||||||
|
ipcRenderer.send('printHandoverReceipt', JSON.stringify({
|
||||||
|
printerIp: printer.address,
|
||||||
|
handoverData: printData
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
lodopPrintWork(printData);
|
||||||
|
}
|
||||||
|
console.log("✅ 交班小票打印成功:", printer.address);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 交班小票打印失败:", printer.address, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
// 打印订单发票
|
|
||||||
printInvoice(data) {
|
printInvoice(data) {
|
||||||
if (
|
const validPrinter = this.deviceNoteList[0];
|
||||||
this.deviceNoteList.length &&
|
if (!validPrinter || !this.checkLocalPrint(validPrinter.address)) {
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
|
||||||
) {
|
|
||||||
data.deviceName = this.deviceNoteList[0].address;
|
|
||||||
invoicePrint(data);
|
|
||||||
} else {
|
|
||||||
console.log("订单发票:未在本机查询到打印机");
|
console.log("订单发票:未在本机查询到打印机");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.deviceName = validPrinter.address;
|
||||||
|
invoicePrint(data);
|
||||||
},
|
},
|
||||||
// 打印退单小票
|
|
||||||
|
// 退款小票打印
|
||||||
printRefund(data) {
|
printRefund(data) {
|
||||||
if (
|
// 筛选条件:状态启用 + 小票类型 + 打印机可用 + 打印服务正常
|
||||||
this.deviceNoteList.length &&
|
const validPrinters = this.deviceNoteList.filter(p => {
|
||||||
this.checkLocalPrint(this.deviceNoteList[0].address)
|
return p.status
|
||||||
) {
|
&& p.subType === "cash"
|
||||||
data.deviceName = this.deviceNoteList[0].address;
|
&& this.checkPrinterAvailable(p)
|
||||||
refundPrint(data);
|
&& this.isPrintService;
|
||||||
} else {
|
});
|
||||||
console.log("退单小票:未在本机查询到打印机");
|
|
||||||
|
if (validPrinters.length === 0) {
|
||||||
|
console.log("退单小票:无符合条件的可用打印机");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const store = useUser();
|
||||||
|
// 遍历符合条件的打印机打印
|
||||||
|
validPrinters.forEach(printer => {
|
||||||
|
const printData = {
|
||||||
|
...data,
|
||||||
|
deviceId: printer.id,
|
||||||
|
deviceName: printer.address,
|
||||||
|
printerName: printer.name,
|
||||||
|
connectionType: printer.connectionType,
|
||||||
|
shop_name: store.shopInfo.shopName,
|
||||||
|
loginAccount: store.userInfo.name,
|
||||||
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 区分局域网和USB打印机
|
||||||
|
if (printer.connectionType === "局域网") {
|
||||||
|
ipcRenderer.send('printRefund', JSON.stringify({
|
||||||
|
printerIp: printer.address,
|
||||||
|
orderData: printData
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
refundPrint(printData);
|
||||||
|
}
|
||||||
|
console.log("✅ 退单小票打印成功:", printer.address);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 退单小票打印失败:", printer.address, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 退菜小票打印
|
||||||
|
printRefundDish(data) {
|
||||||
|
// 筛选条件:状态启用 + 小票类型 + 打印机可用 + 打印服务正常
|
||||||
|
const validPrinters = this.deviceNoteList.filter(p => {
|
||||||
|
return p.status
|
||||||
|
&& p.subType === "cash"
|
||||||
|
&& this.checkPrinterAvailable(p)
|
||||||
|
&& this.isPrintService;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validPrinters.length === 0) {
|
||||||
|
console.log("退菜:无符合条件的可用打印机");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = useUser();
|
||||||
|
// 遍历符合条件的打印机打印
|
||||||
|
validPrinters.forEach(printer => {
|
||||||
|
const printData = {
|
||||||
|
...data,
|
||||||
|
deviceId: printer.id,
|
||||||
|
deviceName: printer.address,
|
||||||
|
printerName: printer.name,
|
||||||
|
connectionType: printer.connectionType,
|
||||||
|
shop_name: store.shopInfo.shopName,
|
||||||
|
loginAccount: store.userInfo.name,
|
||||||
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 区分局域网和USB打印机
|
||||||
|
if (printer.connectionType === "局域网") {
|
||||||
|
ipcRenderer.send('printRefundDish', JSON.stringify({
|
||||||
|
printerIp: printer.address,
|
||||||
|
orderData: printData
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
refundPrint(printData);
|
||||||
|
}
|
||||||
|
console.log("✅ 退菜小票打印成功:", printer.address);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 退菜小票打印失败:", printer.address, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
270
src/store/print20260331.js
Normal file
270
src/store/print20260331.js
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
import { ipcRenderer } from "electron";
|
||||||
|
import { useUser } from "@/store/user.js";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import receiptPrint from "@/components/lodop/receiptPrint.js";
|
||||||
|
import lodopPrintWork from "@/components/lodop/lodopPrintWork.js";
|
||||||
|
import invoicePrint from "@/components/lodop/invoicePrint.js";
|
||||||
|
import refundPrint from "@/components/lodop/refundPrint.js";
|
||||||
|
import { printerList } from "@/api/account.js";
|
||||||
|
import { useSocket } from './socket.js';
|
||||||
|
|
||||||
|
export const usePrint = defineStore("print", {
|
||||||
|
state: () => ({
|
||||||
|
isPrintService: false, // 打印服务是否启动
|
||||||
|
printServiceTimer: false, // 打印服务定时器
|
||||||
|
printServiceTimerCount: 0, // 打印服务定时器计数
|
||||||
|
printServiceTimerMaxCount: 10, // 打印服务定时器最大计数
|
||||||
|
showPrintNotService: false, // 是否显示重启软件,
|
||||||
|
localDevices: [], // 本地打印机列表
|
||||||
|
deviceNoteList: [], // 添加的打印机
|
||||||
|
deviceLableList: [], // 添加的打印机
|
||||||
|
labelList: [], // 要打印的队列数据
|
||||||
|
printTimer: null,
|
||||||
|
receiptList: [], // 小票队列数据
|
||||||
|
receiptTimer: null,
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
// 获取本地打印机和已添加的可以用打印机列表
|
||||||
|
async init() {
|
||||||
|
// 获取本地打印机
|
||||||
|
ipcRenderer.send("getPrintList");
|
||||||
|
ipcRenderer.on("printList", (event, arg) => {
|
||||||
|
this.localDevices = arg;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取已添加的打印机
|
||||||
|
const res = await printerList();
|
||||||
|
this.deviceNoteList = res.records.filter(
|
||||||
|
(item) => item.status && item.subType == "cash"
|
||||||
|
);
|
||||||
|
this.deviceLableList = res.records.filter(
|
||||||
|
(item) => item.status && item.subType == "label"
|
||||||
|
);
|
||||||
|
console.log("打印队列初始化成功", {
|
||||||
|
deviceNoteList: this.deviceNoteList,
|
||||||
|
deviceLableList: this.deviceLableList,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取已添加的打印机列表失败", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测打印服务是否启动
|
||||||
|
this.checkPrintService();
|
||||||
|
},
|
||||||
|
// 检测打印组件服务是否启动
|
||||||
|
checkPrintService() {
|
||||||
|
this.printServiceTimer = setInterval(() => {
|
||||||
|
if (
|
||||||
|
typeof LODOP !== "undefined" &&
|
||||||
|
LODOP.webskt &&
|
||||||
|
LODOP.webskt.readyState == 1
|
||||||
|
) {
|
||||||
|
// 准备好
|
||||||
|
this.isPrintService = true;
|
||||||
|
clearInterval(this.printServiceTimer);
|
||||||
|
this.printServiceTimer = null;
|
||||||
|
} else {
|
||||||
|
this.printServiceTimerCount++;
|
||||||
|
console.log("打印服务未启动", this.printServiceTimerCount);
|
||||||
|
|
||||||
|
if (this.printServiceTimerCount >= this.printServiceTimerMaxCount) {
|
||||||
|
// 超过最大次数
|
||||||
|
this.isPrintService = false;
|
||||||
|
this.showPrintNotService = true;
|
||||||
|
clearInterval(this.printServiceTimer);
|
||||||
|
this.printServiceTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("打印服务是否启动:", this.isPrintService);
|
||||||
|
}, 1000);
|
||||||
|
},
|
||||||
|
// 检查本地打印机是否能正常使用
|
||||||
|
checkLocalPrint(address) {
|
||||||
|
let print = "";
|
||||||
|
for (let item of this.localDevices) {
|
||||||
|
if (item.name == address) {
|
||||||
|
print = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!print.name) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 打印标签小票
|
||||||
|
labelPrint(props) {
|
||||||
|
const store = useUser();
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.deviceLableList.length &&
|
||||||
|
this.checkLocalPrint(this.deviceLableList[0].address)
|
||||||
|
) {
|
||||||
|
let pids = this.deviceLableList[0].categoryList;
|
||||||
|
let count = 0;
|
||||||
|
let sum = 0;
|
||||||
|
|
||||||
|
props.carts.map((item) => {
|
||||||
|
if (pids.some((el) => el == item.categoryId)) {
|
||||||
|
for (let i = 0; i < item.number; i++) {
|
||||||
|
sum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
props.carts.map((item) => {
|
||||||
|
if (pids.some((el) => el == item.categoryId)) {
|
||||||
|
for (let i = 0; i < item.number; i++) {
|
||||||
|
count++;
|
||||||
|
this.labelList.push({
|
||||||
|
outNumber: props.outNumber,
|
||||||
|
name: item.name,
|
||||||
|
skuName: item.skuName,
|
||||||
|
masterId: props.orderInfo.tableName,
|
||||||
|
deviceName: this.deviceLableList[0].address,
|
||||||
|
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
isPrint: false,
|
||||||
|
count: `${count}/${sum}`,
|
||||||
|
ticketLogo: store.shopInfo.ticketLogo,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("this.labelList===", this.labelList);
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// 执行打印操作
|
||||||
|
this.startLabelPrint();
|
||||||
|
} else {
|
||||||
|
console.log("标签打印:未在本机查询到打印机");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 开始打印标签数据
|
||||||
|
startLabelPrint() {
|
||||||
|
if (this.printTimer != null) return;
|
||||||
|
this.printTimer = setInterval(() => {
|
||||||
|
let item = "";
|
||||||
|
if (!this.labelList.length) {
|
||||||
|
clearInterval(this.printTimer);
|
||||||
|
this.printTimer = null;
|
||||||
|
} else {
|
||||||
|
item = this.labelList[0];
|
||||||
|
if (!item.isPrint) {
|
||||||
|
ipcRenderer.send("printerTagSync", JSON.stringify(item));
|
||||||
|
this.labelList[0].isPrint = true;
|
||||||
|
this.labelList.splice(0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
},
|
||||||
|
// 添加小票打印队列数据
|
||||||
|
pushReceiptData(props, isDevice = true) {
|
||||||
|
// console.log("pushReceiptData===", props);
|
||||||
|
if (!isDevice) {
|
||||||
|
// 测试打印,无需校验本地打印机
|
||||||
|
this.receiptList.push(props);
|
||||||
|
this.startReceiptPrint();
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
this.deviceNoteList.length &&
|
||||||
|
this.checkLocalPrint(this.deviceNoteList[0].address) &&
|
||||||
|
this.isPrintService
|
||||||
|
) {
|
||||||
|
const store = useUser();
|
||||||
|
props.deviceId = this.deviceNoteList[0].id;
|
||||||
|
props.deviceName = this.deviceNoteList[0].address;
|
||||||
|
props.shop_name = store.shopInfo.shopName;
|
||||||
|
props.loginAccount = store.userInfo.name;
|
||||||
|
props.createdAt = dayjs(props.createdAt).format(
|
||||||
|
"YYYY-MM-DD HH:mm:ss"
|
||||||
|
);
|
||||||
|
props.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
if (!props.orderInfo.masterId) {
|
||||||
|
props.orderInfo.masterId = props.orderInfo.tableName;
|
||||||
|
}
|
||||||
|
props.orderInfo.outNumber = props.outNumber;
|
||||||
|
if (!props.discountAmount) {
|
||||||
|
props.discountAmount = props.amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.receiptList.push(props);
|
||||||
|
this.startReceiptPrint();
|
||||||
|
} else {
|
||||||
|
console.log("订单小票:未在本机查询到打印机");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 开始打印小票
|
||||||
|
async startReceiptPrint() {
|
||||||
|
try {
|
||||||
|
const socketStore = useSocket();
|
||||||
|
const userStore = useUser();
|
||||||
|
|
||||||
|
if (this.receiptTimer !== null) return;
|
||||||
|
this.receiptTimer = setInterval(() => {
|
||||||
|
if (!this.receiptList.length) {
|
||||||
|
clearInterval(this.receiptTimer);
|
||||||
|
this.receiptTimer = null;
|
||||||
|
} else {
|
||||||
|
receiptPrint(this.receiptList[0]);
|
||||||
|
// 在这里触发已打印操作标记
|
||||||
|
const data = {
|
||||||
|
type: "cashier",
|
||||||
|
operate_type: "order_print_status",
|
||||||
|
table_code: this.receiptList[0].orderInfo.tableCode,
|
||||||
|
account: userStore.shopInfo.account,
|
||||||
|
print_status: "1",
|
||||||
|
order_id: this.receiptList[0].orderInfo.id,
|
||||||
|
print_id: this.receiptList[0].deviceId,
|
||||||
|
shop_id: this.receiptList[0].orderInfo.shopId,
|
||||||
|
}
|
||||||
|
socketStore.ws.send(JSON.stringify(data));
|
||||||
|
this.receiptList.splice(0, 1);
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 打印交班小票
|
||||||
|
printWork(data) {
|
||||||
|
if (
|
||||||
|
this.deviceNoteList.length &&
|
||||||
|
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||||
|
) {
|
||||||
|
data.deviceName = this.deviceNoteList[0].address;
|
||||||
|
lodopPrintWork(data);
|
||||||
|
} else {
|
||||||
|
console.log("交班小票:未在本机查询到打印机");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 打印订单发票
|
||||||
|
printInvoice(data) {
|
||||||
|
if (
|
||||||
|
this.deviceNoteList.length &&
|
||||||
|
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||||
|
) {
|
||||||
|
data.deviceName = this.deviceNoteList[0].address;
|
||||||
|
invoicePrint(data);
|
||||||
|
} else {
|
||||||
|
console.log("订单发票:未在本机查询到打印机");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 打印退单小票
|
||||||
|
printRefund(data) {
|
||||||
|
if (
|
||||||
|
this.deviceNoteList.length &&
|
||||||
|
this.checkLocalPrint(this.deviceNoteList[0].address)
|
||||||
|
) {
|
||||||
|
data.deviceName = this.deviceNoteList[0].address;
|
||||||
|
refundPrint(data);
|
||||||
|
} else {
|
||||||
|
console.log("退单小票:未在本机查询到打印机");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -112,11 +112,61 @@ export const useSocket = defineStore("socket", {
|
|||||||
switch (data.operate_type) {
|
switch (data.operate_type) {
|
||||||
case "add":
|
case "add":
|
||||||
// 添加购物车商品
|
// 添加购物车商品
|
||||||
goodsStore.successAddCart(data.data);
|
{
|
||||||
|
// console.log('socket终极操作数据.add===', data.data);
|
||||||
|
const cartItem = goodsStore.cartList.find(item => item.id == data.data.id) || { number: 0 }
|
||||||
|
// console.log('socket终极操作数据.cartItem===', cartItem);
|
||||||
|
let arr = []
|
||||||
|
goodsStore.orderList.forEach(item => {
|
||||||
|
arr.push(...item.goods)
|
||||||
|
})
|
||||||
|
const isExist = _.some(arr, item => Number(item.productId) === data.data.product_id)
|
||||||
|
|
||||||
|
if (data.data.number == 1 && data.data.number > cartItem.number) {
|
||||||
|
if (isExist) {
|
||||||
|
ElMessage({
|
||||||
|
type: 'warning',
|
||||||
|
message: '该商品已下单过,请确认是否重复',
|
||||||
|
duration: 4000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goodsStore.successAddCart(data.data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "edit":
|
case "edit":
|
||||||
// 编辑购物车商品
|
{
|
||||||
goodsStore.successEditCart(data.data);
|
// 编辑购物车商品
|
||||||
|
// console.log('socket终极操作数据.edit===', data.data);
|
||||||
|
|
||||||
|
const cartItem = goodsStore.cartList.find(item => item.id == data.data.id)
|
||||||
|
|
||||||
|
// console.log('socket终极操作数据.cartItem===', cartItem);
|
||||||
|
|
||||||
|
let arr = []
|
||||||
|
goodsStore.orderList.forEach(item => {
|
||||||
|
arr.push(...item.goods)
|
||||||
|
})
|
||||||
|
const isExist = _.some(arr, item => Number(item.productId) === data.data.product_id)
|
||||||
|
|
||||||
|
if (data.data.number == 2 && data.data.number > cartItem.number) {
|
||||||
|
if (isExist) {
|
||||||
|
ElMessage({
|
||||||
|
type: 'warning',
|
||||||
|
message: '该商品已下单过,请确认是否重复',
|
||||||
|
duration: 4000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ElMessage({
|
||||||
|
type: 'warning',
|
||||||
|
message: '购物车已有该商品,请确认是否重复',
|
||||||
|
duration: 4000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
goodsStore.successEditCart(data.data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "del":
|
case "del":
|
||||||
// 删除购物车商品
|
// 删除购物车商品
|
||||||
@@ -169,11 +219,17 @@ export const useSocket = defineStore("socket", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (data.data_type == "order") {
|
} else if (data.data_type == "order") {
|
||||||
|
goodsStore.successClearCart();
|
||||||
|
goodsStore.historyOrderAjax(data.data.table_code);
|
||||||
|
this.cartInit();
|
||||||
|
|
||||||
|
|
||||||
// 收到订单消息,打印订单小票
|
// 收到订单消息,打印订单小票
|
||||||
let orderInfo = data.data.split("_");
|
let orderInfo = data.data.split("_");
|
||||||
let orderId = orderInfo[0]; // 订单ID
|
let orderId = orderInfo[0]; // 订单ID
|
||||||
let orderModel = orderInfo[1]; // 订单类型
|
let orderModel = orderInfo[1]; // 订单类型
|
||||||
let orderStatus = orderInfo[2]; // 订单状态
|
let orderStatus = orderInfo[2]; // 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成_第几次下单
|
||||||
|
let placeNum = orderInfo[3]; // 下单次数
|
||||||
|
|
||||||
let printList = useStorage.get("printList") || [];
|
let printList = useStorage.get("printList") || [];
|
||||||
|
|
||||||
@@ -189,6 +245,35 @@ export const useSocket = defineStore("socket", {
|
|||||||
this.orderList.push(orderId);
|
this.orderList.push(orderId);
|
||||||
this.startPrintInterval();
|
this.startPrintInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 防止重复打印客看单
|
||||||
|
if (orderStatus == 0) {
|
||||||
|
getOrderByIdAjax(orderId).then(res => {
|
||||||
|
let originOrderInfo = res
|
||||||
|
originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum);
|
||||||
|
|
||||||
|
console.log('originOrderInfo', originOrderInfo);
|
||||||
|
|
||||||
|
let amout = 0
|
||||||
|
originOrderInfo.detailMap.flat().forEach(item => {
|
||||||
|
amout += item.num * item.unitPrice
|
||||||
|
});
|
||||||
|
|
||||||
|
originOrderInfo.originAmount = amout
|
||||||
|
|
||||||
|
if (originOrderInfo.placeNum == 1 && originOrderInfo.dineMode == 'dine-in') {
|
||||||
|
originOrderInfo.originAmount += originOrderInfo.seatAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originOrderInfo.packFee > 0) {
|
||||||
|
originOrderInfo.originAmount += originOrderInfo.packFee
|
||||||
|
}
|
||||||
|
|
||||||
|
printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: false }));
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (data.data_type == "product_update") {
|
} else if (data.data_type == "product_update") {
|
||||||
// 商品更新
|
// 商品更新
|
||||||
this.updateGoods();
|
this.updateGoods();
|
||||||
|
|||||||
@@ -159,7 +159,9 @@ 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: [],
|
||||||
@@ -179,39 +181,85 @@ export function commOrderPrintData(orderInfo) {
|
|||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
};
|
};
|
||||||
|
|
||||||
orderInfo.cartList.map((item) => {
|
if (orderInfo.isGuest) {
|
||||||
data.carts.push({
|
// 如果是客看单,只展示当前下单的菜品
|
||||||
categoryId: item.categoryId,
|
orderInfo.detailMap[0].map((item) => {
|
||||||
name: item.productName,
|
let price = 0
|
||||||
number: item.num,
|
if (item.discountSaleAmount > 0) {
|
||||||
skuName: item.skuName,
|
price = item.discountSaleAmount
|
||||||
salePrice: formatDecimal(+item.price),
|
} else {
|
||||||
totalAmount: formatDecimal(+item.payAmount),
|
price = item.price
|
||||||
proGroupInfo: item.proGroupInfo
|
}
|
||||||
? item.proGroupInfo.map((item) => item.goods).flat()
|
|
||||||
: "",
|
data.carts.push({
|
||||||
|
categoryId: item.categoryId,
|
||||||
|
name: item.isGift === 1 ? `[赠]${item.productName}` : item.productName,
|
||||||
|
number: item.num - item.returnNum,
|
||||||
|
skuName: item.skuName,
|
||||||
|
salePrice: formatDecimal(+price),
|
||||||
|
totalAmount: formatDecimal(+item.payAmount),
|
||||||
|
proGroupInfo: item.proGroupInfo
|
||||||
|
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||||
|
: "",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
orderInfo.cartList.map((item) => {
|
||||||
|
let price = 0
|
||||||
|
if (item.discountSaleAmount > 0) {
|
||||||
|
price = item.discountSaleAmount
|
||||||
|
} else {
|
||||||
|
price = item.price
|
||||||
|
}
|
||||||
|
data.carts.push({
|
||||||
|
categoryId: item.categoryId,
|
||||||
|
name: item.isGift === 1 ? `[赠]${item.productName}` : item.productName,
|
||||||
|
number: item.num - item.returnNum,
|
||||||
|
skuName: item.skuName,
|
||||||
|
salePrice: formatDecimal(+price),
|
||||||
|
totalAmount: formatDecimal((item.num - item.returnNum) * price),
|
||||||
|
proGroupInfo: item.proGroupInfo
|
||||||
|
? item.proGroupInfo.map((item) => item.goods).flat()
|
||||||
|
: "",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (orderInfo.seatAmount > 0) {
|
|
||||||
console.log('有餐位费', orderInfo.seatAmount);
|
|
||||||
|
|
||||||
data.carts.push({
|
|
||||||
categoryId: '',
|
|
||||||
name: '餐位费',
|
|
||||||
number: orderInfo.seatNum,
|
|
||||||
skuName: '',
|
|
||||||
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
|
||||||
totalAmount: orderInfo.seatAmount,
|
|
||||||
proGroupInfo: "",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orderInfo.packFee > 0) {
|
if (orderInfo.dineMode == 'dine-in') {
|
||||||
|
if (orderInfo.seatAmount > 0 && orderInfo.isGuest && orderInfo.placeNum == 1 && !orderInfo.isRefundDish) {
|
||||||
|
data.carts.push({
|
||||||
|
categoryId: '',
|
||||||
|
name: '餐位费',
|
||||||
|
number: orderInfo.seatNum,
|
||||||
|
skuName: '',
|
||||||
|
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||||
|
totalAmount: orderInfo.seatAmount,
|
||||||
|
proGroupInfo: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orderInfo.seatAmount > 0 && !orderInfo.isGuest && !orderInfo.isRefundDish) {
|
||||||
|
data.carts.push({
|
||||||
|
categoryId: '',
|
||||||
|
name: '餐位费',
|
||||||
|
number: orderInfo.seatNum,
|
||||||
|
skuName: '',
|
||||||
|
salePrice: formatDecimal(orderInfo.seatAmount / orderInfo.seatNum),
|
||||||
|
totalAmount: orderInfo.seatAmount,
|
||||||
|
proGroupInfo: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orderInfo.packFee > 0 && !orderInfo.isRefundDish) {
|
||||||
|
let packNum = 0;
|
||||||
|
orderInfo.cartList.forEach(item => {
|
||||||
|
packNum += item.packNumber
|
||||||
|
})
|
||||||
data.carts.push({
|
data.carts.push({
|
||||||
categoryId: '',
|
categoryId: '',
|
||||||
name: '打包费',
|
name: '打包费',
|
||||||
number: '',
|
number: packNum,
|
||||||
skuName: '',
|
skuName: '',
|
||||||
salePrice: '',
|
salePrice: '',
|
||||||
totalAmount: formatDecimal(orderInfo.packFee),
|
totalAmount: formatDecimal(orderInfo.packFee),
|
||||||
@@ -219,6 +267,7 @@ export function commOrderPrintData(orderInfo) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('最终组合打印数据===', data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@
|
|||||||
<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> -->
|
||||||
@@ -21,17 +27,30 @@
|
|||||||
<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="设备类型">
|
<el-form-item label="选择设备" v-if="form.connectionType === 'USB'">
|
||||||
<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>
|
||||||
@@ -125,6 +144,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<classify ref="classifyRef" @success="(e) => (form.categoryList = e)" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -136,6 +156,11 @@ 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();
|
||||||
@@ -150,7 +175,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出品
|
||||||
@@ -163,7 +188,8 @@ 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);
|
||||||
@@ -210,16 +236,29 @@ function getPrintList() {
|
|||||||
|
|
||||||
// 测试打印
|
// 测试打印
|
||||||
function printHandle() {
|
function printHandle() {
|
||||||
if (!form.value.address) {
|
if (form.value.connectionType === 'USB' && !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);
|
||||||
@@ -232,11 +271,16 @@ async function submitHandle() {
|
|||||||
ElMessage.error("请输入设备名称");
|
ElMessage.error("请输入设备名称");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!form.value.address) {
|
if (form.value.connectionType === 'USB' && !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();
|
||||||
@@ -253,6 +297,19 @@ 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,22 +248,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
<!-- 退款推库存的操作弹窗 -->
|
||||||
|
<refundConsModal ref="refundConsModalRef" :list="refundList" @success="refundConsModalSuccess" />
|
||||||
</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 } from '@/utils/index.js'
|
import { inputFilterFloat, formatDecimal, getOrderByIdAjax, commOrderPrintData } 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'
|
||||||
|
import { useUser } from '@/store/user.js'
|
||||||
|
import refundConsModal from '@/components/refundConsModal.vue'
|
||||||
|
|
||||||
|
const refundConsModalRef = ref(null)
|
||||||
|
|
||||||
const goodsStore = useGoods()
|
const goodsStore = useGoods()
|
||||||
const socket = useSocket()
|
const socket = useSocket()
|
||||||
|
const printStore = usePrint()
|
||||||
|
const store = useUser()
|
||||||
const tableMergingRef = ref(null)
|
const tableMergingRef = ref(null)
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -312,15 +321,21 @@ async function returnFormSubmit() {
|
|||||||
returnFormLoading.value = true
|
returnFormLoading.value = true
|
||||||
await returnOrderItemAjax(returnForm.value.num)
|
await returnOrderItemAjax(returnForm.value.num)
|
||||||
showReturnForm.value = false
|
showReturnForm.value = false
|
||||||
ElMessage.success('退菜成功')
|
// ElMessage.success('退菜成功')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('退菜失败了');
|
console.log('退菜失败了');
|
||||||
}
|
}
|
||||||
returnFormLoading.value = false
|
returnFormLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提交退菜
|
const refundStock = ref('')
|
||||||
async function returnOrderItemAjax(num = 1) {
|
// 退款推库存的操作
|
||||||
|
function refundConsModalSuccess(e) {
|
||||||
|
refundStock.value = e
|
||||||
|
refundNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refundNext() {
|
||||||
try {
|
try {
|
||||||
let data = {
|
let data = {
|
||||||
orderId: goodsStore.orderListInfo.id,
|
orderId: goodsStore.orderListInfo.id,
|
||||||
@@ -332,19 +347,81 @@ async function returnOrderItemAjax(num = 1) {
|
|||||||
{
|
{
|
||||||
id: goodsStore.cartOrderItem.id,
|
id: goodsStore.cartOrderItem.id,
|
||||||
returnAmount: goodsStore.cartOrderItem.lowPrice,
|
returnAmount: goodsStore.cartOrderItem.lowPrice,
|
||||||
num: num
|
num: refundNum.value
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
operator: store.userInfo.name || store.shopInfo.shopName,
|
||||||
|
print: printStore.deviceNoteList.length ? false : true,
|
||||||
|
refundStock: refundStock.value, // 是否推库存 1退菜图库存 2仅退菜不退库存
|
||||||
}
|
}
|
||||||
await refundOrder(data)
|
await refundOrder(data)
|
||||||
goodsStore.cartOrderItem.returnNum += num
|
ElMessage.success('退菜成功')
|
||||||
|
goodsStore.cartOrderItem.returnNum += refundNum.value
|
||||||
goodsStore.calcCartInfo()
|
goodsStore.calcCartInfo()
|
||||||
|
|
||||||
|
getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
|
||||||
|
let originOrderInfo = res
|
||||||
|
let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
|
||||||
|
originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
|
||||||
|
originOrderInfo.cartList[0].num = refundNum.value
|
||||||
|
originOrderInfo.cartList[0].returnNum = 0
|
||||||
|
originOrderInfo.cartList[0].payAmount = refundNum.value * originOrderInfo.cartList[0].price
|
||||||
|
|
||||||
|
printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
|
||||||
|
}).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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提交退菜
|
||||||
|
const refundNum = ref(1)
|
||||||
|
const refundList = ref([])
|
||||||
|
async function returnOrderItemAjax(num = 1) {
|
||||||
|
try {
|
||||||
|
refundNum.value = num
|
||||||
|
let item = goodsStore.cartOrderItem
|
||||||
|
|
||||||
|
console.log('returnOrderItemAjax===', item);
|
||||||
|
|
||||||
|
// 在这里给订单的商品补全库存信息 start
|
||||||
|
goodsStore.originGoodsList.forEach(val => {
|
||||||
|
if (item.productId == val.id) {
|
||||||
|
if (store.shopInfo.refundMode == 1) {
|
||||||
|
// 跟随分类退款模式
|
||||||
|
goodsStore.categoryList.forEach(v => {
|
||||||
|
if (val.categoryId == v.id) {
|
||||||
|
item.refundMode = v.refundMode
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 跟随商品退款模式及
|
||||||
|
item.refundMode = val.refundMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('item===', item);
|
||||||
|
if (item.refundMode == 3) {
|
||||||
|
refundList.value = [
|
||||||
|
{
|
||||||
|
name: item.product_name,
|
||||||
|
num: refundNum.value
|
||||||
|
}
|
||||||
|
]
|
||||||
|
refundConsModalRef.value.show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
refundNext()
|
||||||
|
// 在这里给订单的商品补全库存信息 end
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 显示打包
|
// 显示打包
|
||||||
function packHandle() {
|
function packHandle() {
|
||||||
let item = goodsStore.cartList[goodsStore.cartActiveIndex]
|
let item = goodsStore.cartList[goodsStore.cartActiveIndex]
|
||||||
|
|||||||
@@ -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">
|
||||||
@@ -89,7 +95,7 @@
|
|||||||
<img class="sell_out_icon" src="@/assets/icon_goods_wks.svg">
|
<img class="sell_out_icon" src="@/assets/icon_goods_wks.svg">
|
||||||
</div>
|
</div>
|
||||||
<!-- 售罄 -->
|
<!-- 售罄 -->
|
||||||
<div class="sell_out" v-else-if="item.isSoldStock">
|
<div class="sell_out" v-else-if="item.isSoldStock || item.isSoldOut">
|
||||||
<img class="sell_out_icon" src="@/assets/icon_goods_sq.svg">
|
<img class="sell_out_icon" src="@/assets/icon_goods_sq.svg">
|
||||||
</div>
|
</div>
|
||||||
<!-- 库存不足 -->
|
<!-- 库存不足 -->
|
||||||
@@ -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()
|
||||||
@@ -551,7 +559,7 @@ function showSkuHandle(item) {
|
|||||||
message: '不在可售时间内',
|
message: '不在可售时间内',
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
} else if (item.isSoldStock) {
|
} else if (item.isSoldStock || item.isSoldOut) {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: '该商品已售罄',
|
message: '该商品已售罄',
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ const props = defineProps({
|
|||||||
member: {
|
member: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: {}
|
default: {}
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'cart' // cart 代客下单 table 桌台结算 order 订单结算
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -200,14 +204,57 @@ const printHandle = _.throttle(async function () {
|
|||||||
await printOrderLable(true)
|
await printOrderLable(true)
|
||||||
}, 1500, { leading: true, trailing: false })
|
}, 1500, { leading: true, trailing: false })
|
||||||
|
|
||||||
|
|
||||||
|
// 在 usePrint 的 actions 中添加(比如放在 pushReceiptData 方法下方)
|
||||||
|
function calcAllCartsTotalSum(cartObj) {
|
||||||
|
// 初始化总和为0
|
||||||
|
let totalSum = 0;
|
||||||
|
// 遍历原始对象的所有键(0、1、2...)
|
||||||
|
Object.keys(cartObj).forEach(key => {
|
||||||
|
const carts = cartObj[key] || [];
|
||||||
|
// 累加当前分类下的菜品总价(num × unitPrice)
|
||||||
|
carts.forEach(item => {
|
||||||
|
const num = Number(item.num) - Number(item.returnNum) || 0; // 防错:非数字转0
|
||||||
|
const unitPrice = Number(item.unitPrice) || 0;
|
||||||
|
totalSum += num * unitPrice;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return totalSum; // 返回所有菜品的总价总和
|
||||||
|
}
|
||||||
|
|
||||||
// 打印订单标签
|
// 打印订单标签
|
||||||
async function printOrderLable(isBefore = false) {
|
async function printOrderLable(isBefore = false) {
|
||||||
try {
|
try {
|
||||||
let orderId = goodsStore.orderListInfo.id
|
let orderId = goodsStore.orderListInfo.id
|
||||||
const data = await getOrderByIdAjax(orderId);
|
let data = await getOrderByIdAjax(orderId);
|
||||||
|
|
||||||
|
console.log(`打印订单标签数据${isBefore}===`, data);
|
||||||
|
|
||||||
|
if (isBefore) {
|
||||||
|
data.originAmount = calcAllCartsTotalSum(data.detailMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.seatAmount > 0 && data.dineMode == 'dine-in' && isBefore) {
|
||||||
|
data.originAmount += data.seatAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
let packFee = 0
|
||||||
|
|
||||||
|
data.cartList.forEach(item => {
|
||||||
|
if (item.packNumber > 0 && (item.num - item.returnNum) >= item.packNumber) {
|
||||||
|
packFee += (item.num - item.returnNum) * item.packAmount
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (packFee > 0 && isBefore) {
|
||||||
|
data.originAmount += packFee
|
||||||
|
data.packFee = packFee
|
||||||
|
}
|
||||||
|
|
||||||
let printList = useStorage.get("printList") || [];
|
let printList = useStorage.get("printList") || [];
|
||||||
|
|
||||||
|
console.log('printStore.deviceNoteList.length:', printStore.deviceNoteList.length);
|
||||||
|
|
||||||
// 防止重复打印
|
// 防止重复打印
|
||||||
if (!printList.some((el) => el == orderId)) {
|
if (!printList.some((el) => el == orderId)) {
|
||||||
if (!isBefore) {
|
if (!isBefore) {
|
||||||
@@ -221,17 +268,17 @@ async function printOrderLable(isBefore = false) {
|
|||||||
printStore.labelPrint(commOrderPrintData(data))
|
printStore.labelPrint(commOrderPrintData(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('printStore.deviceNoteList', printStore.deviceNoteList);
|
||||||
if (printStore.deviceNoteList.length) {
|
if (printStore.deviceNoteList.length) {
|
||||||
// 使用本地打印机打印
|
// 使用本地打印机打印
|
||||||
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) {
|
||||||
@@ -258,9 +305,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')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
<div class="left">
|
<div class="left">
|
||||||
<span>台桌:{{ goodsStore.tableInfo.name }}</span>
|
<span>台桌:{{ goodsStore.tableInfo.name }}</span>
|
||||||
<div class="n" @click="takeFoodCodeRef.show()">
|
<div class="n" @click="takeFoodCodeRef.show()">
|
||||||
{{ goodsStore.tableInfo.num || 1 }}人
|
{{ goodsStore.tableInfo.num || 0 }}人
|
||||||
<el-icon>
|
<el-icon>
|
||||||
<EditPen />
|
<EditPen />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 备注 -->
|
<!-- 备注 -->
|
||||||
<remarkModal ref="remarkRef" @success="(e) => (remark = e)" />
|
<remarkModal ref="remarkRef" @success="(e) => (goodsStore.remark = e)" />
|
||||||
<!-- 修改取餐号 -->
|
<!-- 修改取餐号 -->
|
||||||
<takeFoodCode />
|
<takeFoodCode />
|
||||||
<el-drawer v-model="membershow" :with-header="true" size="90%" title="选择会员">
|
<el-drawer v-model="membershow" :with-header="true" size="90%" title="选择会员">
|
||||||
@@ -197,7 +197,7 @@
|
|||||||
</el-drawer>
|
</el-drawer>
|
||||||
<!-- <takeFoodCode ref="takeFoodCodeRef" title="修改取餐号" placeholder="请输入取餐号" @success="takeFoodCodeSuccess" /> -->
|
<!-- <takeFoodCode ref="takeFoodCodeRef" title="修改取餐号" placeholder="请输入取餐号" @success="takeFoodCodeSuccess" /> -->
|
||||||
<!-- 结算订单 -->
|
<!-- 结算订单 -->
|
||||||
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="cartInfo.totalAmount" :remark="remark"
|
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="cartInfo.totalAmount" :remark="goodsStore.remark"
|
||||||
:orderInfo="orderInfo" @success="" />
|
:orderInfo="orderInfo" @success="" />
|
||||||
<!-- 快捷收银 -->
|
<!-- 快捷收银 -->
|
||||||
<fastCashier ref="fastCashierRef" type="0" />
|
<fastCashier ref="fastCashierRef" type="0" />
|
||||||
@@ -212,6 +212,7 @@
|
|||||||
</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";
|
||||||
@@ -224,7 +225,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 } from '@/utils/index.js'
|
import { formatDecimal, formatPhoneNumber, getOrderByIdAjax, commOrderPrintData } 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'
|
||||||
@@ -252,7 +253,6 @@ const pendingCartModalRef = ref(null);
|
|||||||
const settleAccountRef = ref(null);
|
const settleAccountRef = ref(null);
|
||||||
const fastCashierRef = ref(null);
|
const fastCashierRef = ref(null);
|
||||||
const tableMergingRef = ref(null)
|
const tableMergingRef = ref(null)
|
||||||
const remark = ref("");
|
|
||||||
const cartListActive = ref(0);
|
const cartListActive = ref(0);
|
||||||
const cartListActiveItem = ref({})
|
const cartListActiveItem = ref({})
|
||||||
const cartList = ref([]);
|
const cartList = ref([]);
|
||||||
@@ -299,6 +299,7 @@ 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
|
||||||
@@ -308,8 +309,8 @@ async function createOrderHandle(t = 0) {
|
|||||||
originAmount: goodsStore.cartInfo.costSummary.goodsOriginalAmount,
|
originAmount: goodsStore.cartInfo.costSummary.goodsOriginalAmount,
|
||||||
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: goodsStore.remark, // 备注
|
||||||
placeNum: (goodsStore.orderListInfo.placeNum || 0) + 1, // 下单次数
|
placeNum: placeNum + 1, // 下单次数
|
||||||
waitCall: 0, // 是否叫号
|
waitCall: 0, // 是否叫号
|
||||||
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||||
limitRate: goodsStore.limitDiscountRes
|
limitRate: goodsStore.limitDiscountRes
|
||||||
@@ -328,6 +329,32 @@ 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);
|
||||||
|
|
||||||
|
// let amout = 0
|
||||||
|
// originOrderInfo.detailMap.flat().forEach(item => {
|
||||||
|
// amout += item.num * item.unitPrice
|
||||||
|
// });
|
||||||
|
|
||||||
|
// originOrderInfo.originAmount = amout
|
||||||
|
|
||||||
|
// if (originOrderInfo.placeNum == 1 && originOrderInfo.dineMode == 'dine-in') {
|
||||||
|
// originOrderInfo.originAmount += originOrderInfo.seatAmount
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (originOrderInfo.packFee > 0) {
|
||||||
|
// originOrderInfo.originAmount += originOrderInfo.packFee
|
||||||
|
// }
|
||||||
|
|
||||||
|
// printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: false }));
|
||||||
|
// }).catch(err => {
|
||||||
|
// console.log(err);
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
// 清除购物车,更新历史订单
|
// 清除购物车,更新历史订单
|
||||||
goodsStore.updateOrderList()
|
goodsStore.updateOrderList()
|
||||||
|
|||||||
@@ -26,8 +26,9 @@
|
|||||||
</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>
|
||||||
@@ -47,6 +48,26 @@ 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 {
|
||||||
|
|||||||
339
src/views/member/components/StoreWineManagement.vue
Normal file
339
src/views/member/components/StoreWineManagement.vue
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
<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="250">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button type="primary" @click="viewRecord(row)">查看记录</el-button>
|
||||||
|
<el-button type="danger" :disabled="isExpired(row.expTime) || row.num <= 0"
|
||||||
|
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">
|
||||||
|
<span v-if="isExpired(row.expTime) || row.status == 2">已过期</span>
|
||||||
|
<span v-else-if="row.num <= 0">已取完</span>
|
||||||
|
<span v-else>取酒</span>
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</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>
|
||||||
|
<!-- 存取酒记录弹窗 -->
|
||||||
|
<el-dialog title="记录" width="600px" v-model="showRecordDialogVisible">
|
||||||
|
<el-table :data="recordList" border stripe>
|
||||||
|
<el-table-column label="记录" prop="content"></el-table-column>
|
||||||
|
<el-table-column label="操作时间" prop="time"></el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, onMounted } from "vue";
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut, shopStorageRecord } 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 isExpired(expTime) {
|
||||||
|
if (!expTime) return false;
|
||||||
|
const now = new Date();
|
||||||
|
const expDate = new Date(expTime);
|
||||||
|
return expDate < now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看记录
|
||||||
|
const showRecordDialogVisible = ref(false);
|
||||||
|
const recordList = ref([]);
|
||||||
|
async function viewRecord(row) {
|
||||||
|
try {
|
||||||
|
showRecordDialogVisible.value = true;
|
||||||
|
const res = await shopStorageRecord({
|
||||||
|
id: row.id,
|
||||||
|
page: 1,
|
||||||
|
size: 999,
|
||||||
|
});
|
||||||
|
recordList.value = res || [];
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取存取酒记录失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
init();
|
||||||
|
drawerVisible.value = true;
|
||||||
|
// 刷新列表数据
|
||||||
|
storageGoodGetAjax();
|
||||||
|
shopStorageGetAjax();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
show,
|
||||||
|
init,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
storageGoodGetAjax();
|
||||||
|
shopStorageGetAjax();
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.drawer_wrap {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
padding: var(--el-font-size-base) 0;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--el-font-size-base);
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 var(--el-font-size-base);
|
||||||
|
background-color: #fff;
|
||||||
|
padding: var(--el-font-size-base);
|
||||||
|
border-radius: var(--el-font-size-base);
|
||||||
|
|
||||||
|
.left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--el-font-size-base);
|
||||||
|
|
||||||
|
.return {
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
padding: 10px 8px 4px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.user_info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--el-font-size-base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pay_wrap {
|
||||||
|
flex: 1;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: var(--el-font-size-base);
|
||||||
|
|
||||||
|
.tab {
|
||||||
|
height: 100%;
|
||||||
|
padding: var(--el-font-size-base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: var(--el-font-size-base);
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -99,6 +99,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
||||||
@@ -114,6 +117,8 @@
|
|||||||
<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>
|
||||||
@@ -123,10 +128,12 @@ 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: '',
|
||||||
|
|||||||
@@ -56,6 +56,14 @@
|
|||||||
¥{{ formatDecimal(+scope.row.payAmount) }}
|
¥{{ formatDecimal(+scope.row.payAmount) }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="已退数量">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<div class="column">
|
||||||
|
<div class="row">退单数量:{{ scope.row.refundNum }}</div>
|
||||||
|
<div class="row">退菜数量:{{ scope.row.returnNum }}</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="退款数量" width="170">
|
<el-table-column label="退款数量" width="170">
|
||||||
<template v-slot="scope">
|
<template v-slot="scope">
|
||||||
<el-input-number v-model="scope.row.refund_number" :disabled="refundType != 2" :min="0"
|
<el-input-number v-model="scope.row.refund_number" :disabled="refundType != 2" :min="0"
|
||||||
@@ -66,7 +74,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
<template v-if="item.returnGoods.length">
|
<template v-if="item.returnGoods.length">
|
||||||
<div class="tips" style="margin-top: 20px;padding-bottom: 10px;">以下为已退部分退单/退菜</div>
|
<div class="tips" style="margin-top: 20px;padding-bottom: 10px;">以下已完成退菜/退款</div>
|
||||||
<el-table :data="item.returnGoods" brder stripe>
|
<el-table :data="item.returnGoods" brder stripe>
|
||||||
<el-table-column label="商品信息">
|
<el-table-column label="商品信息">
|
||||||
<template v-slot="scope">
|
<template v-slot="scope">
|
||||||
@@ -118,17 +126,19 @@
|
|||||||
<div class="drawer_footer">
|
<div class="drawer_footer">
|
||||||
<div class="btn">
|
<div class="btn">
|
||||||
<el-button type="danger" style="width: 100%;" :loading="loading"
|
<el-button type="danger" style="width: 100%;" :loading="loading"
|
||||||
@click="handleRefund">手动退款</el-button>
|
:disabled="item.onGoods && !item.onGoods.length" @click="handleRefund">手动退款</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn">
|
<div class="btn">
|
||||||
<el-button type="primary" style="width: 100%;" :loading="loading"
|
<el-button type="primary" style="width: 100%;" :loading="loading"
|
||||||
@click="refundHandle()">原路退回</el-button>
|
:disabled="item.onGood && !item.onGoods.length" @click="refundHandle()">原路退回</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
<takeFoodCode ref="takeFoodCodeRef" title="退款密码" :type="2" input-type="password" placeholder="请输入退款密码"
|
<takeFoodCode ref="takeFoodCodeRef" title="退款密码" :type="2" input-type="password" placeholder="请输入退款密码"
|
||||||
@success="passwordSuccess" />
|
@success="passwordSuccess" />
|
||||||
|
<!-- 退款退菜推库存的操作弹窗 -->
|
||||||
|
<refundConsModal ref="refundConsModalRef" :list="returnList" @success="refundConsModalSuccess" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -142,9 +152,13 @@ import { usePrint } from "@/store/print.js";
|
|||||||
import { useUser } from '@/store/user.js'
|
import { useUser } from '@/store/user.js'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import takeFoodCode from "@/components/takeFoodCode.vue";
|
import takeFoodCode from "@/components/takeFoodCode.vue";
|
||||||
|
import { useGoods } from '@/store/goods.js'
|
||||||
|
import refundConsModal from '@/components/refundConsModal.vue';
|
||||||
|
|
||||||
|
const refundConsModalRef = ref(null)
|
||||||
|
|
||||||
const emits = defineEmits(['success'])
|
const emits = defineEmits(['success'])
|
||||||
|
const goodsStore = useGoods()
|
||||||
const store = useUser()
|
const store = useUser()
|
||||||
const printStore = usePrint();
|
const printStore = usePrint();
|
||||||
const globalStore = useGlobal()
|
const globalStore = useGlobal()
|
||||||
@@ -168,41 +182,83 @@ const takeFoodCodeRef = ref(null)
|
|||||||
const cash = ref(false)
|
const cash = ref(false)
|
||||||
const amountInputRef = ref(null)
|
const amountInputRef = ref(null)
|
||||||
|
|
||||||
|
// 退款推库存的操作
|
||||||
|
function refundConsModalSuccess(e) {
|
||||||
|
refundStock.value = e
|
||||||
|
refundNext()
|
||||||
|
}
|
||||||
|
|
||||||
// 退款密码
|
// 退款密码
|
||||||
|
const returnList = ref([])
|
||||||
|
const refundDetails = ref([])
|
||||||
|
const pwd = ref('')
|
||||||
|
const refundStock = ref('')
|
||||||
|
const rows = ref([])
|
||||||
async function passwordSuccess(e = '') {
|
async function passwordSuccess(e = '') {
|
||||||
try {
|
pwd.value = e
|
||||||
loading.value = true
|
loading.value = true
|
||||||
let rows = tableRef.value.getSelectionRows()
|
rows.value = tableRef.value.getSelectionRows()
|
||||||
let refundDetails = []
|
// if (refundType.value != 1) {
|
||||||
if (refundType.value != 1) {
|
refundDetails.value = tableRef.value.getSelectionRows().map(val => {
|
||||||
refundDetails = tableRef.value.getSelectionRows().map(val => {
|
return {
|
||||||
return {
|
refundMode: val.refundMode,
|
||||||
id: val.id,
|
name: val.productName,
|
||||||
returnAmount: val.payAmount,
|
id: val.id,
|
||||||
num: val.refund_number
|
returnAmount: val.payAmount,
|
||||||
}
|
num: val.refund_number
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 处理退菜退款的库存逻辑 判断有没有returnMode = 3,然后弹窗提示 start
|
||||||
|
console.log('refundDetails===', refundDetails.value);
|
||||||
|
refundDetails.value.forEach(item => {
|
||||||
|
if (item.refundMode == 3) {
|
||||||
|
returnList.value.push({
|
||||||
|
name: item.name,
|
||||||
|
num: item.num
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('returnList===', returnList.value);
|
||||||
|
|
||||||
|
// 显示退菜退款的弹窗
|
||||||
|
if (returnList.value.length > 0) {
|
||||||
|
refundConsModalRef.value.show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 处理退菜退款的库存逻辑 判断有没有returnMode = 3,然后弹窗提示 end
|
||||||
|
|
||||||
|
refundNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最后的退款操作
|
||||||
|
async function refundNext() {
|
||||||
|
try {
|
||||||
let data = {
|
let data = {
|
||||||
orderId: item.value.id,
|
orderId: item.value.id,
|
||||||
refundAmount: formatDecimal(+refundAmount.value),
|
refundAmount: formatDecimal(+refundAmount.value),
|
||||||
modify: modify.value,
|
modify: modify.value,
|
||||||
cash: cash.value,
|
cash: cash.value,
|
||||||
refundReason: remark.value,
|
refundReason: remark.value,
|
||||||
refundDetails: refundDetails,
|
refundDetails: refundDetails.value,
|
||||||
pwd: e,
|
pwd: pwd.value,
|
||||||
|
operator: store.userInfo.name || store.shopInfo.shopName,
|
||||||
|
print: printStore.deviceNoteList.length ? false : true,
|
||||||
|
refundStock: refundStock.value, // 是否推库存 1退菜图库存 2仅退菜不退库存
|
||||||
};
|
};
|
||||||
|
|
||||||
await refundOrder(data)
|
await refundOrder(data)
|
||||||
ElMessage.success('退款成功')
|
ElMessage.success('退款成功')
|
||||||
await printRefund(rows)
|
await printRefund(rows.value)
|
||||||
isShow.value = false
|
isShow.value = false
|
||||||
emits('success')
|
emits('success')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
}
|
}
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示手动退款
|
// 显示手动退款
|
||||||
@@ -260,6 +316,7 @@ 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: [],
|
||||||
@@ -268,6 +325,7 @@ 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"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,10 +333,10 @@ async function printRefund(rows) {
|
|||||||
data.carts.push(
|
data.carts.push(
|
||||||
{
|
{
|
||||||
name: item.productName,
|
name: item.productName,
|
||||||
number: item.num,
|
number: item.refund_number,
|
||||||
skuName: item.skuName,
|
skuName: item.skuName,
|
||||||
salePrice: formatDecimal(+item.unitPrice),
|
salePrice: formatDecimal(+item.unitPrice),
|
||||||
totalAmount: formatDecimal(+item.payAmount)
|
totalAmount: formatDecimal(+item.unitPrice * item.refund_number)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -286,8 +344,8 @@ async function printRefund(rows) {
|
|||||||
printStore.printRefund(data);
|
printStore.printRefund(data);
|
||||||
} else {
|
} else {
|
||||||
// 云打印
|
// 云打印
|
||||||
await orderPrint({ id: item.value.id, type: 2 })
|
// await orderPrint({ id: item.value.id, type: 2 })
|
||||||
ElMessage.success('云打印退款单成功')
|
// ElMessage.success('云打印退款单成功')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -337,6 +395,29 @@ function show(row) {
|
|||||||
|
|
||||||
isShow.value = true
|
isShow.value = true
|
||||||
let newRow = { ...row }
|
let newRow = { ...row }
|
||||||
|
|
||||||
|
// 在这里给订单的商品补全库存信息 start
|
||||||
|
console.log('originGoodsList===', goodsStore.originGoodsList);
|
||||||
|
newRow.goods.forEach(item => {
|
||||||
|
goodsStore.originGoodsList.forEach(val => {
|
||||||
|
if (item.productId == val.id) {
|
||||||
|
if (store.shopInfo.refundMode == 1) {
|
||||||
|
// 跟随分类退款模式
|
||||||
|
goodsStore.categoryList.forEach(v => {
|
||||||
|
if (val.categoryId == v.id) {
|
||||||
|
item.refundMode = v.refundMode
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 跟随商品退款模式及
|
||||||
|
item.refundMode = val.refundMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
console.log('newRow.goods===', newRow.goods);
|
||||||
|
// 在这里给订单的商品补全库存信息 end
|
||||||
|
|
||||||
remark.value = ''
|
remark.value = ''
|
||||||
|
|
||||||
let onGoods = []
|
let onGoods = []
|
||||||
@@ -345,14 +426,25 @@ function show(row) {
|
|||||||
// 可退的最大数量,下单数量 - 已退数量 - 退菜数量
|
// 可退的最大数量,下单数量 - 已退数量 - 退菜数量
|
||||||
let refundMaxNum = item.num - item.refundNum - item.returnNum
|
let refundMaxNum = item.num - item.refundNum - item.returnNum
|
||||||
|
|
||||||
if (refundMaxNum <= 0) {
|
// if (refundMaxNum <= 0) {
|
||||||
item.refund_number = item.num
|
// item.refund_number = item.num
|
||||||
// 已经退过,不在允许操作
|
// // 已经退过,不在允许操作
|
||||||
returnGoods.push(item)
|
// returnGoods.push(item)
|
||||||
} else {
|
// } else {
|
||||||
// 可以操作的退款数量
|
// // 可以操作的退款数量
|
||||||
item.refund_number = item.num
|
// item.refund_number = item.num
|
||||||
|
// onGoods.push(item)
|
||||||
|
// }
|
||||||
|
item.refund_number = refundMaxNum
|
||||||
|
// if (item.refundNum > 0 || item.returnNum > 0) {
|
||||||
|
// // 已经退过,不在允许操作
|
||||||
|
// returnGoods.push(item)
|
||||||
|
// }
|
||||||
|
// 可以操作的退款数量
|
||||||
|
if (refundMaxNum > 0) {
|
||||||
onGoods.push(item)
|
onGoods.push(item)
|
||||||
|
} else {
|
||||||
|
returnGoods.push(item)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -361,6 +453,8 @@ function show(row) {
|
|||||||
|
|
||||||
item.value = newRow
|
item.value = newRow
|
||||||
|
|
||||||
|
console.log('item.value===', item.value);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
tableRef.value.clearSelection()
|
tableRef.value.clearSelection()
|
||||||
refundTypeChange(1)
|
refundTypeChange(1)
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box_content_left_top_item_top">
|
<div class="box_content_left_top_item_top">
|
||||||
<div style="color:#ff5252; font-size: 30px;">
|
<div style="color:#ff5252; font-size: 30px;">
|
||||||
¥{{ formatDecimal(infoData.handAmount || 0) }}
|
¥{{ formatDecimal(infoData.orderTurnover || 0) }}
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-top: 6px; color: #666;">
|
<div style="margin-top: 6px; color: #666;">
|
||||||
营业额
|
营业额
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<div class="box_content_left_top_item">
|
<div class="box_content_left_top_item">
|
||||||
<div class="box_content_left_top_item_botton">
|
<div class="box_content_left_top_item_botton">
|
||||||
<div style=" font-size: 20px;">
|
<div style=" font-size: 20px;">
|
||||||
¥{{ formatDecimal(infoData.cashAmount || 0) }}
|
¥{{ formatDecimal(infoData.cash || 0) }}
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-top: 6px;">
|
<div style="margin-top: 6px;">
|
||||||
现金支付
|
现金支付
|
||||||
@@ -179,18 +179,19 @@ 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)
|
await handover(printStore.deviceNoteList.length ? 0 : 1)
|
||||||
const data = await handoverData(res)
|
|
||||||
if (printStore.deviceNoteList.length) {
|
if (printStore.deviceNoteList.length) {
|
||||||
|
printStore.printWork(infoData.value)
|
||||||
// 使用本地打印机 打印交班数据
|
// 使用本地打印机 打印交班数据
|
||||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
// data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||||
data.printShop = isPrint.value
|
// data.printShop = isPrint.value
|
||||||
printStore.printWork(data)
|
|
||||||
} else {
|
|
||||||
// 使用云打印机 打印交班数据
|
|
||||||
await handoverNetworkPrint(data.id)
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// // 使用云打印机 打印交班数据
|
||||||
|
// 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