1.新增全部本地打印标签

2.优化订单重但标签小票
This commit is contained in:
gyq
2024-06-21 13:56:16 +08:00
parent c86fff9691
commit 0b2b4b44d0
17 changed files with 2356 additions and 342 deletions

View File

@@ -247,6 +247,120 @@ import { clearNoNum } from '@/utils'
const store = useUser()
const itemboxshow = ref(false)
import { ipcRenderer } from 'electron'
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 = []
props.skuInfos.map(item => {
if (pids.some(el => el == item.categoryId)) {
for (let i = 0; i < item.num; i++) {
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')
}
)
}
}
})
if (labelList.length) printLabel(labelList)
}
}
// 打印标签
let labelCount = ref(0)
let labelPrintTimer = ref(null)
const printLabel = lodash.throttle(function (list) {
// console.log('printLabel===', list);
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
} else {
clearInterval(labelPrintTimer.value)
labelPrintTimer.value = null
labelCount.value = 0
labelPrintTimer.value = setInterval(() => {
// console.log('labelCount', labelCount.value);
list[labelCount.value].count = `${list.length - labelCount.value}/${list.length}`
ipcRenderer.send('printerTagSync', JSON.stringify(list[labelCount.value]))
labelCount.value++
console.log(labelCount.value);
if (labelCount.value > list.length - 1) {
clearInterval(labelPrintTimer.value)
labelPrintTimer.value = null
labelCount.value = 0
}
}, 1000)
}
}, 1500, { leading: true, trailing: false })
const handleClick = (Name) => {//切换teb
ordereData.status = Name.props.name
asyncorderfindOrder()
@@ -303,23 +417,32 @@ const payreturnOrderclick = lodash.debounce(async () => { //搜索手机号
const print = async (e) => {
try {
await cloudPrinterprint({
type: e,
orderId: orderDetaildata.value.id,
ispre: false
})
ElMessage({
message: '成功打票',
type: 'success',
})
if (e == 'label' && printLabelList.value.length) {
checkLabelPrint(printLabelOrder.value)
} else {
await cloudPrinterprint({
type: e,
orderId: orderDetaildata.value.id,
ispre: false
})
ElMessage({
message: '成功打票',
type: 'success',
})
}
} catch (error) {
console.log(error);
}
}
const loadingboxshow = ref(false);
// 要打印标签的订单数据
const printLabelOrder = ref('')
const emititemboxshow = async (e) => { //接收子组件值 并赋值给父组件
// console.log('emititemboxshow', e);
printLabelOrder.value = e
loadingboxshow.value = true
try {
let res = await orderorderDetail({
@@ -453,6 +576,9 @@ const callNumberHandle = async () => {
onMounted(() => {
// resetMembrform.value = { ...membrform.value }
asyncorderfindOrder()
getPrintList();
bySubTypeAjax();
})
</script>