优化最新版打印机逻辑

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 {