优化标签小票打印

This commit is contained in:
gyq
2024-06-26 14:01:12 +08:00
parent 87627e7b35
commit f3dfd4a121
9 changed files with 203 additions and 423 deletions

View File

@@ -4,7 +4,9 @@
<el-tabs v-model="ordereData.status" class="demo-tabs" @tab-click="handleClick">
<el-tab-pane label="全部" name="">
<div class="demo_tabs_div">
<el-input v-model="ordereData.orderNo" placeholder="请输入订单号查询" @input="inputChange" clearable />
<el-input v-model="ordereData.orderNo" placeholder="请输入订单号查询" @input="inputChange" clearable
@focus="
global.updateData(false)" @blur="global.updateData(true)" />
<!-- <el-button style="margin-left: 10px;" type="primary" @click="onSubmit">搜索</el-button> -->
</div>
<add :loading="loadingboxshow" :ordereData="ordereData" @emititemboxshow="emititemboxshow"
@@ -157,7 +159,9 @@
<el-dialog v-model="recharge" title="退单" width="800" :before-close="handlerecharge">
<div class="recharge_footer">
<div class="recharge_footer_item">
<el-input v-model="remark" style="width: 100%" :rows="2" type="textarea" placeholder="请输入退单原因" />
<el-input v-model="remark" style="width: 100%" :rows="2" type="textarea" placeholder="请输入退单原因"
@focus="
global.updateData(false)" @blur="global.updateData(true)" />
<div class="recharge_footer_items" @click="remark = '顾客取消'">
<div>顾客取消</div>
</div>
@@ -209,7 +213,9 @@
<!-- {{ item.num }} -->
<el-input-number v-model="item.num" :min="1" size="small"
:disabled="item.status == 'refund' ? true : false" :max="item.maxnum"
@change="(currentValue, oldValue) => changezong(item, index, 1, 'num', currentValue, oldValue)" />
@change="(currentValue, oldValue) => changezong(item, index, 1, 'num', currentValue, oldValue)"
@focus="
global.updateData(false)" @blur="global.updateData(true)" />
<!-- @change="changezong(item, index, 1, 'num')" -->
</div>
<div class="recharge_footer_itemright_botton_itemthere">
@@ -246,126 +252,20 @@ import { orderfindOrder, orderorderDetail, payreturnOrder, cloudPrinterprint, se
import add from '@/views/order/components/add.vue'
import cashTable from '@/views/order/components/cashTable.vue'
import { clearNoNum } from '@/utils'
import { useGlobal } from '@/store/global.js'
const global = useGlobal()
const store = useUser()
const itemboxshow = ref(false)
import { usePrint } from '@/store/print.js'
const printStore = usePrint()
import { ipcRenderer } from 'electron'
const reforderboxrightbutton = ref(null);//定义ref
const reforderboxrightbuttonheight = ref(null)//获取元素高度
import { bySubType } from "@/api/device";
// 小票打印机列表
const printList = ref([]);
// 标签打印机列表
const printLabelList = ref([]);
const localPrintList = ref([])
// 获取打印机状态
async function bySubTypeAjax() {
try {
const res1 = await bySubType({
shopId: store.userInfo.shopId,
contentType: "local",
subType: "cash",
});
const res2 = await bySubType({
shopId: store.userInfo.shopId,
contentType: "local",
subType: "label",
});
printList.value = res1;
printLabelList.value = res2;
} catch (error) {
console.log(error);
}
}
// 获取本地打印机列表
function getPrintList() {
ipcRenderer.send("getPrintList");
ipcRenderer.on("printList", (event, arg) => {
localPrintList.value = arg;
// console.log(localPrintList.value);
});
}
// 检查本地打印机是否能正常使用
function checkLocalPrint(deviceName) {
let print = ''
for (let item of localPrintList.value) {
if (item.name == deviceName) {
print = item
}
}
if (!print.name) {
return false
} else {
return true
}
}
// 检测是否打印标签小票
function checkLabelPrint(props) {
// console.log(props);
// console.log(printLabelList.value);
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
} else {
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
let labelList = []
// let count = 0
// let sum = 0
// props.skuInfos.map(item => {
// if (pids.some(el => el == item.categoryId)) {
// for (let i = 0; i < item.num; i++) {
// sum++
// }
// }
// })
props.skuInfos.map(item => {
if (pids.some(el => el == item.categoryId)) {
for (let i = 0; i < item.num; i++) {
// count++
labelList.push(
{
outNumber: props.outNumber,
name: item.productName,
skuName: item.productSkuName,
masterId: props.tableName,
deviceName: printLabelList.value[0].config.deviceName,
createdAt: dayjs(props.createAt).format('YYYY-MM-DD HH:mm:ss'),
// count: `${count}/${sum}`
}
)
}
}
})
if (labelList.length) printLabel(labelList)
}
}
// 打印标签
const printLabel = lodash.throttle(function (list) {
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
} else {
console.log(list.length);
for (let i = 0; i <= list.length - 1; i++) {
// console.log(list[i]);
// ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
setTimeout(() => {
ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
}, i * 800)
}
}
}, 1500, { leading: true, trailing: false })
const handleClick = (Name) => {//切换teb
ordereData.status = Name.props.name
@@ -416,15 +316,37 @@ const payreturnOrderclick = lodash.debounce(async () => { //搜索手机号
} catch (error) {
buttonloading.value = false
}
}, 500)
const print = async (e) => {
// 重新打印标签/小票
const print = lodash.throttle(async function (e) {
try {
if (e == 'label' && printLabelList.value.length) {
checkLabelPrint(printLabelOrder.value)
if (e == 'label') {
// checkLabelPrint(printLabelOrder.value)
const data = {
shop_name: store.userInfo.merchantName,
carts: [],
orderInfo: printLabelOrder.value,
outNumber: printLabelOrder.value.outNumber,
createdAt: dayjs(printLabelOrder.value.createdAt).format(
"YYYY-MM-DD HH:mm:ss"
)
}
printLabelOrder.value.skuInfos.map(item => {
data.carts.push(
{
categoryId: item.categoryId,
name: item.productName,
number: item.num,
skuName: item.productSkuName
}
)
})
// console.log('重打标签小票', data);
printStore.labelPrint(data)
} else {
await cloudPrinterprint({
type: e,
@@ -439,7 +361,7 @@ const print = async (e) => {
} catch (error) {
console.log(error);
}
}
}, 1500, { leading: true, trailing: false })
const loadingboxshow = ref(false);
// 要打印标签的订单数据
@@ -585,9 +507,6 @@ const callNumberHandle = async () => {
onMounted(() => {
// resetMembrform.value = { ...membrform.value }
asyncorderfindOrder()
getPrintList();
bySubTypeAjax();
})
</script>