优化最新版打印机逻辑

This commit is contained in:
gyq
2026-04-22 14:23:46 +08:00
parent fa67997c86
commit d5568c48d0
16 changed files with 2872 additions and 345 deletions

View File

@@ -36,20 +36,32 @@
<el-input v-model="form.address" placeholder="请输入设备IP地址"></el-input>
</el-form-item>
<el-form-item label="商品分类">
<div style="cursor: pointer" @click="classifyRef.show()">
<span style="color: #409eff" v-if="form.categoryList.length">
{{form.categoryList.map(item => item.name).join(',')}}
</span>
<span style="color: #e65d6e" v-else>
请选择分类
</span>
<div class="column">
<el-radio-group v-model="form.classifyPrint" @change="form.categoryList = [];form.categoryIds = ''">
<el-radio-button label="全部" value="0"></el-radio-button>
<el-radio-button label="部分" value="1"
v-show="printTypeList[1].values.length > 0"></el-radio-button>
</el-radio-group>
<div style="cursor: pointer" @click="classifyRef.show()" v-if="form.classifyPrint == '1'">
<span style="color: #409eff" v-if="form.categoryList.length">
{{form.categoryList.map(item => item.name).join(',')}}
</span>
<span style="color: #e65d6e" v-else>
请选择分类
</span>
</div>
</div>
</el-form-item>
<el-form-item label="是否打印交班小票">
<el-radio-group v-model="form.handoverSwitch">
<el-radio-button label="否" :value="0"></el-radio-button>
<el-radio-button label="是" :value="1"></el-radio-button>
</el-radio-group>
<el-form-item label="打印类型">
<div class="row" v-for="(item, index) in printTypeList" :key="index">
<div class="title">{{ item.label }}</div>
<div class="cont">
<el-checkbox-group v-model="item.values" @change="printTypeChange($event, index)">
<el-checkbox :label="item.label" :value="item.value" v-for="item in item.list"
:key="item.value"></el-checkbox>
</el-checkbox-group>
</div>
</div>
</el-form-item>
<!-- <el-form-item label="打印份数">
<el-select v-model="form.printQty">
@@ -95,21 +107,25 @@
<div class="row">收银员{{ printData.loginAccount }}</div>
<div class="line"></div>
<table class="table">
<tr>
<td>品名</td>
<td>单价</td>
<td>数量</td>
<td>小计</td>
</tr>
<tr v-for="(item, index) in printData.carts" :key="index">
<td>
<div>{{ item.name }}</div>
<div class="sku">{{ item.skuName }}</div>
</td>
<td>{{ item.salePrice }}</td>
<td>{{ item.number }}</td>
<td>{{ item.totalAmount }}</td>
</tr>
<thead>
<tr>
<td>品名</td>
<td>单价</td>
<td>数量</td>
<td>小计</td>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in printData.carts" :key="index">
<td>
<div>{{ item.name }}</div>
<div class="sku">{{ item.skuName }}</div>
</td>
<td>{{ item.salePrice }}</td>
<td>{{ item.number }}</td>
<td>{{ item.totalAmount }}</td>
</tr>
</tbody>
</table>
<div class="line"></div>
<div class="row between">
@@ -148,6 +164,7 @@
</template>
<script setup>
import _ from 'lodash'
import dayjs from "dayjs";
import { ipcRenderer } from "electron";
import { onMounted, reactive, ref } from "vue";
@@ -172,22 +189,61 @@ const printList = ref([]);
const feets = ref([0, 1, 2, 3, 4, 5, 8]);
const loading = ref(false);
const requestLoading = ref(false);
const printTypeList = ref([
{
label: '前台',
values: [],
list: [
{ label: '客看单', value: 'GUEST_ORDER' },
{ label: '预结算单', value: 'PRE_ORDER' },
{ label: '结算单', value: 'ORDER' },
{ label: '退菜单', value: 'RETURN_ORDER' },
{ label: '退款单', value: 'REFUND_ORDER' },
]
},
{
label: '后厨',
values: [],
list: [
{ label: '后厨-整单', value: 'ALL_KITCHEN' },
{ label: '后厨-分单', value: 'ONLY_KITCHEN' },
{ label: '后厨-退菜单', value: 'REFUND_KITCHEN' },
]
},
{
label: '其它',
values: [],
list: [
{ label: '交班单', value: 'HANDOVER' },
{ label: '排队取号', value: 'CALL' },
{ label: '储值单', value: 'RECHARGE' },
{ label: '出入库单', value: 'STOCK' },
{ label: '盘点单', value: 'STOCK_CHECK' },
{ label: '商品报表', value: 'PRODUCT_REPORT' },
{ label: '经营日报', value: 'DAY_REPORT' },
{ label: '日结单', value: 'DAY_ORDER' },
]
}
])
const categoryIdsType = ref('all') // all=全部 custom=部分
const form = ref({
id: "",
name: '', // 设备名称
connectionType: 'USB', // 现在打印机支持USB 和 网络、蓝牙、局域网
address: '', // 打印机名称
port: '', // 端口
subType: 'cash', // 打印类型分类label标签cash小票kitchen出品
printType: 'cash', // 打印类型分类label标签cash小票kitchen出品
contentType: '', // 打印机品牌
categoryIds: [], // 打印分类Id
categoryIds: '', // 打印分类Id
categoryList: [], // 分类
sort: '',
receiptSize: '58mm', // 小票尺寸 58mm 80mm
classifyPrint: 1, // 分类打印 0-所有 1-部分分类 2-部分商品
printQty: '', // 打印数量 c1m1^2 = 顾客+商家[2张] m1^1 = 商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
printMethod: 'all', // 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」queue-仅打印排队取号
printType: [], // 打印类型JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
classifyPrint: '1', // 分类打印 0-所有 1-部分分类 2-部分商品
printNum: '', // 打印数量 c1m1^2 = 顾客+商家[2张] m1^1 = 商家[1张] c1^1顾客[1张] c2m1^3顾客2+商家1[3张]
kitchenPrintMode: 'all', // 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」queue-仅打印排队取号
printContentType: [],
status: 1,
handoverSwitch: 0, // 交班单开关 0-关闭 1-开启
});
@@ -248,13 +304,13 @@ function printHandle() {
printDataLoading.value = true;
printData.shop_name = store.shopInfo.shopName
printData.loginAccount = store.userInfo.name
printData.deviceName = form.value.address;
printData.deviceName = form.value.name;
printData.printTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
if (form.value.connectionType === 'USB') {
printStore.pushReceiptData(printData, false);
} else if (form.value.connectionType === '局域网') {
ipcRenderer.send('networkPrint', JSON.stringify({
ipcRenderer.send('ORDER', JSON.stringify({
printerIp: form.value.address,
orderData: printData
}))
@@ -264,6 +320,16 @@ function printHandle() {
}, 2500);
}
// 打印类型切换
function printTypeChange(e, index) {
if (index == 1 && printTypeList.value[index].values.length == 0) {
form.value.categoryList = []
form.value.classifyPrint = '0'
} else {
form.value.classifyPrint = '1'
}
}
// 提交打印机
async function submitHandle() {
try {
@@ -279,8 +345,21 @@ async function submitHandle() {
ElMessage.error("请输入设备IP地址");
return;
}
if (form.value.classifyPrint == '1' && !form.value.categoryList.length) {
ElMessage.error("请选择商品分类");
return;
}
loading.value = true;
form.value.categoryIds = form.value.categoryList.map(item => item.id)
form.value.categoryIds = form.value.categoryList.map(item => item.id).join(',')
let arr = []
printTypeList.value.forEach(item => {
arr.push(...item.values)
})
form.value.printContentType = arr.join(',')
await printerAdd(form.value, form.value.id ? "put" : "post");
ElMessage.success(form.value.id ? "编辑成功" : "添加成功");
printStore.init();
@@ -298,9 +377,11 @@ async function tbPrintMachineDetailAjax(id) {
const res = await printerDetail({ id: id });
form.value = res;
// 做分类信息补全
let arr = []
let categoryIds = res.categoryIds.split(',')
goodsStore.originCategoryList.map(item => {
res.categoryList.map(val => {
categoryIds.map(val => {
if (item.id == val) {
arr.push({
id: item.id,
@@ -310,6 +391,22 @@ async function tbPrintMachineDetailAjax(id) {
})
})
form.value.categoryList = arr
// 补全已选中的打印类型
const printContentTypes = res.printContentType.split(',')
printTypeList.value.forEach(val => {
val.values = _.map(
_.filter(val.list, item => printContentTypes.includes(item.value)),
'value'
);
})
console.log(form.value);
// if (printTypeList.value[1].values.length > 0 && form.value.classifyPrint == 1) {
// form.value.classifyPrint = 1
// }
} catch (error) {
console.log(error);
}
@@ -354,6 +451,7 @@ onMounted(() => {
border-radius: 10px;
background-color: #fff;
padding: 15px;
overflow-y: auto;
}
.menu_wrap {

View File

@@ -13,7 +13,7 @@
<div class="item" v-for="item in list" :key="item.id">
<div class="left">
<div class="icon">
<el-image :src="icons[item.subType]" style="width: 40px; height: 40px"></el-image>
<el-image :src="icons[item.printType]" style="width: 40px; height: 40px"></el-image>
</div>
<div class="info">
<div class="name">{{ item.name }}</div>
@@ -28,7 +28,7 @@
<div class="editor">
<el-text type="primary" @click="
router.push({
name: deviceRoute[item.subType],
name: deviceRoute[item.printType],
query: { id: item.id },
})
">

View File

@@ -359,18 +359,19 @@ async function refundNext() {
goodsStore.cartOrderItem.returnNum += refundNum.value
goodsStore.calcCartInfo()
getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
let originOrderInfo = res
let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
originOrderInfo.cartList[0].num = refundNum.value
originOrderInfo.cartList[0].returnNum = 0
originOrderInfo.cartList[0].payAmount = refundNum.value * originOrderInfo.cartList[0].price
// 打印退菜小票
// getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
// let originOrderInfo = res
// let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
// originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
// originOrderInfo.cartList[0].num = refundNum.value
// originOrderInfo.cartList[0].returnNum = 0
// originOrderInfo.cartList[0].payAmount = refundNum.value * originOrderInfo.cartList[0].price
printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
}).catch(err => {
console.log(err);
})
// printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
// }).catch(err => {
// console.log(err);
// })
// await goodsStore.historyOrderAjax('', data.orderId)
} catch (error) {
console.log(error);

View File

@@ -226,6 +226,13 @@ function calcAllCartsTotalSum(cartObj) {
async function printOrderLable(isBefore = false) {
try {
let orderId = goodsStore.orderListInfo.id
await orderPrint({
type: isBefore ? 1 : 0,
id: orderId,
});
printLoading.value = false
return
let data = await getOrderByIdAjax(orderId);
console.log(`打印订单标签数据${isBefore}===`, data);

View File

@@ -28,15 +28,20 @@
</el-dialog> -->
<!-- <el-input v-model="authCode" placeholder="请扫描支付码"></el-input>
<el-button type="primary" @click="microPayAjax">反扫支付</el-button> -->
<el-button type="primary" @click="printReceipt">调用本地网络打印机</el-button>
<el-button type="primary" @click="printReceipt">打印盘点单</el-button>
</template>
<script setup>
import dayjs from 'dayjs';
import { onMounted, ref } from 'vue'
import { findVersion } from '@/api/user.js'
import packageData from "../../../package.json";
import { ipcRenderer } from 'electron'
import { microPay } from '@/api/order.js'
import { usePrint } from '@/store/print';
import { printData } from '@/api/print.js'
import { useUser } from '@/store/user.js'
import { ALL_KITCHEN, ONLY_KITCHEN, REFUND_KITCHEN } from '../../../electron/printService'
const showDialog = ref(false)
const updataInfo = ref({})
@@ -45,27 +50,88 @@ const uploadPro = ref(0)
const uploadSucess = ref(false)
const uploadResponse = ref({})
const tempFilePath = ref('')
const printStore = usePrint()
const authCode = ref('')
const user = useUser()
function printReceipt() {
let data = {
printerIp: '192.168.1.53',
orderData: {
orderNo: '20260327008',
shopName: '川味小馆',
createTime: new Date().toLocaleString(),
products: [
{ name: '回锅肉', price: '32.00', num: 1 },
{ name: '米饭', price: '2.00', num: 2 },
{ name: '紫菜蛋花汤', price: '8.00', num: 1 }
],
total: '42.00',
payType: '支付宝',
remark: '微辣'
}
// RECHARGE=22 STOCK=30 STOCK_CHECK=32 CALL=38
async function printReceipt() {
const order = {
shop_name: '张三的店',
loginAccount: '',
isBefore: true,
carts: [
{
id: 1,
name: "菜品名称1",
skuName: "多放香菜",
salePrice: "1.0",
number: "10",
totalAmount: "10",
remark: '多放点盐',
proGroupInfo: [
{
proName: '西红柿',
number: '2'
}
]
},
// {
// id: 2,
// name: "菜品名称2",
// skuName: "500ml",
// salePrice: "1.0",
// number: "10",
// totalAmount: "10",
// remark: ''
// },
// {
// id: 3,
// name: "菜品名称3",
// skuName: "",
// salePrice: "1.0",
// number: "10",
// totalAmount: "10",
// remark: ''
// },
],
amount: "10.00",
originAmount: '10.00',
discountAmount: "0.00",
discountAllAmount: 0,
orderAmount: 10,
discount: 0,
remark: "给我多放点辣椒,谢谢老板",
orderInfo: {
masterId: "",
orderNo: "202404021023542223445",
orderNum: '12',
discountAllAmount: 0,
orderAmount: 10,
tableName: '室内-A1',
dineMode: 'dine-in'
},
loginAccount: '李四',
printerName: '堂食打印机',
deviceName: "",
createdAt: "2024-04-02 10:15",
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
}
ipcRenderer.send('portPrint', JSON.stringify(data))
// ALL_KITCHEN('192.168.1.53', order)
// ONLY_KITCHEN('192.168.1.53', order)
REFUND_KITCHEN('192.168.1.53', order)
// const res = await printData({
// shopId: user.shopInfo.id,
// dataId: 38,
// type: 'CALL'
// })
// console.log(JSON.parse(res.data));
// printStore.CALL(JSON.parse(res.data))
}
// 检查版本更新

View File

@@ -251,7 +251,7 @@ async function refundNext() {
await refundOrder(data)
ElMessage.success('退款成功')
await printRefund(rows.value)
// await printRefund(rows.value)
isShow.value = false
emits('success')
} catch (error) {