更新没有usb打印机时调用云打印机

This commit is contained in:
gyq 2024-08-02 17:54:52 +08:00
parent f8c5c9bf59
commit ac469cbc32
7 changed files with 323 additions and 178 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "vite-electron", "name": "vite-electron",
"private": true, "private": true,
"version": "1.4.11", "version": "1.4.12",
"main": "dist-electron/main.js", "main": "dist-electron/main.js",
"scripts": { "scripts": {
"dev": "chcp 65001 && vite", "dev": "chcp 65001 && vite",

View File

@ -0,0 +1,96 @@
import getLodop from "./LodopFuncs.js";
/**
* 打印退单小票
*/
export default (data) => {
let LODOP = getLodop();
LODOP.PRINT_INIT("打印小票");
// 设置打印纸大小D
LODOP.SET_PRINT_PAGESIZE(3, "58mm", 20, "");
//设置默认打印机(这里用的是打印机名称)
LODOP.SET_PRINTER_INDEX(data.deviceName);
// 文字内容
let t1 = 40;
let t2 = (100 - t1) / 3;
let html = `
<div style="font-size: 30px;display:flex;justify-content:center;">
${data.shop_name}
</div>
<div style="font-size: 16px;display: flex; justify-content:center;margin-top:6px;">
退款单${data.orderInfo.masterId ? data.orderInfo.masterId : ""}
</div>
<div style="margin-top: 30px;font-size: 12px;">
订单号${data.orderInfo && data.orderInfo.orderNo}
</div>
<div style="margin-top: 4px;font-size: 12px;">
交易时间${data.createdAt}
</div>
<div style="margin-top: 4px;font-size: 12px;">
收银员${data.loginAccount}
</div>
<div style="margin-top: 6px;margin-bottom: 6px;width: 100%">
<hr/>
</div>
<table class="table" style="width: 100%;">
<tr>
<td style="font-size: 12px;width:${t1}%;">品名</td>
<td style="font-size: 12px;width:${t2}%;">单价</td>
<td style="font-size: 12px;width:${t2}%;">数量</td>
<td style="font-size: 12px;width:${t2}%;">小计</td>
</tr>
`;
let table = "";
for (let item of data.carts) {
table += `
<tr>
<td style="font-size: 12px;width:${t1}%;">
<div>${item.name}</div>
${
item.skuName
? `<div class="sku">规格:${item.skuName}</div>`
: ""
}
</td>
<td style="font-size: 12px;width:${t2}%;">${item.salePrice}</td>
<td style="font-size: 12px;width:${t2}%;">${item.number}</td>
<td style="font-size: 12px;width:${t2}%;">
${item.totalAmount}
</td>
</tr>
`;
}
let str = `
</table>
<div style="margin-top: 6px;margin-bottom: 6px;width: 100%">
<hr/>
</div>
<div style="margin-top: 6px; font-size: 22px;display:flex;justify-content: space-between;">
<span>应退</span>
<span>${data.amount}</span>
</div>
<div style="margin-top: 4px; font-size: 12px;">
<span>余额</span>
<span>0.00</span>
</div>
<div style="margin-top: 6px;margin-bottom: 6px;width: 100%">
<hr/>
</div>
<div style="margin-top: 4px; font-size: 12px;">
打印时间${data.printTime}
</div>
<div>.</div>
<div>.</div>
<div>.</div>
<div>.</div>
`;
let lastHtml = `${html}${table}${str}`;
setTimeout(() => {
LODOP.ADD_PRINT_HTM("9mm", "0mm", "RightMargin:0mm", 20, lastHtml);
LODOP.SET_LICENSES("", "DCFF409304DFCEB3E2C644BF96CD0720", "", "");
LODOP.PRINT();
}, 800);
};

View File

@ -6,6 +6,7 @@ import dayjs from "dayjs";
import receiptPrint from "@/components/lodop/receiptPrint.js"; import receiptPrint from "@/components/lodop/receiptPrint.js";
import lodopPrintWork from "@/components/lodop/lodopPrintWork.js"; import lodopPrintWork from "@/components/lodop/lodopPrintWork.js";
import invoicePrint from "@/components/lodop/invoicePrint.js"; import invoicePrint from "@/components/lodop/invoicePrint.js";
import refundPrint from "@/components/lodop/refundPrint.js";
export const usePrint = defineStore({ export const usePrint = defineStore({
id: "print", id: "print",
@ -203,5 +204,17 @@ export const usePrint = defineStore({
console.log("订单发票:没有小票打印机"); console.log("订单发票:没有小票打印机");
} }
}, },
// 打印退单小票
printRefund(data) {
if (
this.deviceNoteList.length &&
this.checkLocalPrint(this.deviceNoteList[0].config.deviceName)
) {
data.deviceName = this.deviceNoteList[0].config.deviceName;
refundPrint(data);
} else {
console.log("退单小票:没有小票打印机");
}
},
}, },
}); });

View File

@ -122,6 +122,7 @@ const isPrint = ref(true);
const printHandle = _.throttle(async function () { const printHandle = _.throttle(async function () {
try { try {
if (!isPrint.value) return; if (!isPrint.value) return;
printLoading.value = true;
const data = { const data = {
shop_name: store.userInfo.shopName, shop_name: store.userInfo.shopName,
loginAccount: store.userInfo.loginAccount, loginAccount: store.userInfo.loginAccount,
@ -134,20 +135,20 @@ const printHandle = _.throttle(async function () {
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
}; };
printStore.labelPrint(data) printStore.labelPrint(data)
setTimeout(() => {
printLoading.value = false;
}, 1500)
if (printStore.deviceNoteList.length) {
printStore.pushReceiptData(data) printStore.pushReceiptData(data)
// try { } else {
// printLoading.value = true; await print({
// await print({ type: "normal",
// type: "normal", ispre: true,
// ispre: true, orderId: props.orderInfo.id,
// orderId: props.orderInfo.id, });
// }); printLoading.value = false;
// printLoading.value = false; ElMessage.success("打印成功");
// // ElMessage.success(""); }
// } catch (error) {
// printLoading.value = false;
// console.log(error);
// }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
@ -194,8 +195,19 @@ async function printOrderLable() {
}) })
// //
printStore.labelPrint(data) printStore.labelPrint(data)
if (printStore.deviceNoteList.length) {
// //
printStore.pushReceiptData(data) printStore.pushReceiptData(data)
} else {
await print({
type: "normal",
ispre: true,
orderId: props.orderInfo.id,
});
printLoading.value = false;
ElMessage.success("打印成功");
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }

View File

@ -46,17 +46,25 @@ const orderInfo = ref({})
async function printEwmHandle() { async function printEwmHandle() {
try { try {
printEwmLoading.value = true printEwmLoading.value = true
if (printStore.deviceNoteList.length) {
printStore.printInvoice({ printStore.printInvoice({
url: ewmInfo.value.wechat_url url: ewmInfo.value.wechat_url
}) })
// const res = await syjprintqrcode({
// id: ewmInfo.value.id
// })
ElMessage.success('打印成功') ElMessage.success('打印成功')
showEwmDialog.value = false showEwmDialog.value = false
setTimeout(() => { setTimeout(() => {
printEwmLoading.value = false printEwmLoading.value = false
}, 1000) }, 1000)
} else {
const res = await syjprintqrcode({
id: ewmInfo.value.id
})
ElMessage.success('打印成功')
showEwmDialog.value = false
setTimeout(() => {
printEwmLoading.value = false
}, 1000)
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
printEwmLoading.value = false printEwmLoading.value = false

View File

@ -142,8 +142,19 @@
(orderDetaildata.status == 'refund' || (orderDetaildata.status == 'refund' ||
orderDetaildata.status == 'closed') orderDetaildata.status == 'closed')
">开发票</el-button> ">开发票</el-button>
<el-button :loading="normalPrintLoading" @click="print('normal')" style="flex: 1">重打小票</el-button> <el-button :loading="normalPrintLoading" @click="print('normal')" style="flex: 1" v-if="
<el-button :loading="labelPrintLoading" @click="print('label')" style="flex: 1">重打标签</el-button> orderDetaildata.orderType != 'return' &&
orderDetaildata.status == 'closed'
">重打小票</el-button>
<el-button :loading="labelPrintLoading" @click="print('label')" style="flex: 1" v-if="
orderDetaildata.orderType != 'return' &&
(orderDetaildata.status == 'refund' ||
orderDetaildata.status == 'closed')
">重打标签</el-button>
<el-button :loading="normalPrintLoading" @click="print('refund')" style="flex: 1"
v-if="orderDetaildata.status == 'refund'">
重打小票
</el-button>
</div> </div>
</div> </div>
</div> </div>
@ -445,7 +456,8 @@ const print = lodash.throttle(
setTimeout(() => { setTimeout(() => {
labelPrintLoading.value = false labelPrintLoading.value = false
}, 1000) }, 1000)
} else { } else if (e == 'normal') {
if (printStore.deviceNoteList.length) {
normalPrintLoading.value = true normalPrintLoading.value = true
const data = { const data = {
shop_name: store.userInfo.shopName, shop_name: store.userInfo.shopName,
@ -476,16 +488,62 @@ const print = lodash.throttle(
setTimeout(() => { setTimeout(() => {
normalPrintLoading.value = false normalPrintLoading.value = false
}, 1000) }, 1000)
// // } else {
// await cloudPrinterprint({ //
// type: e, await cloudPrinterprint({
// orderId: orderDetaildata.value.id, type: e,
// ispre: false, orderId: orderDetaildata.value.id,
// }); ispre: false,
// ElMessage({ });
// message: "", ElMessage({
// type: "success", message: "成功打票",
// }); type: "success",
});
}
} else if (e == 'refund') {
if (printStore.deviceNoteList.length) {
normalPrintLoading.value = true
const data = {
shop_name: store.userInfo.shopName,
loginAccount: store.userInfo.loginAccount,
carts: [],
amount: printLabelOrder.value.orderAmount,
remark: printLabelOrder.value.remark,
orderInfo: printLabelOrder.value,
outNumber: printLabelOrder.value.outNumber,
createdAt: dayjs(printLabelOrder.value.createdAt).format(
"YYYY-MM-DD HH:mm:ss"
),
printTime: dayjs().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,
salePrice: formatDecimal(item.priceAmount / item.num),
totalAmount: formatDecimal(item.priceAmount)
}
)
})
printStore.printRefund(data);
setTimeout(() => {
normalPrintLoading.value = false
}, 1000)
} else {
//
await cloudPrinterprint({
type: 'normal',
orderId: orderDetaildata.value.id,
ispre: false,
});
ElMessage({
message: "成功打票",
type: "success",
});
}
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);

View File

@ -159,53 +159,13 @@ const dialogVisible = ref(false) //交班
const infoData = ref({}) const infoData = ref({})
const loading = ref(false); const loading = ref(false);
const printList = ref([]);
const localPrintList = ref([])
const isPrint = ref(true) const isPrint = ref(true)
//
async function bySubTypeAjax() {
try {
const res = await bySubType({
shopId: store.userInfo.shopId,
contentType: "local",
subType: "cash",
});
printList.value = res;
} 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
}
}
// //
const exit = async () => { const exit = async () => {
try { try {
if (printStore.deviceNoteList.length) {
loading.value = true; loading.value = true;
let data = {} let data = {}
// //
@ -234,50 +194,48 @@ const exit = async () => {
}); });
}, 1000); }, 1000);
loading.value = false; loading.value = false;
return // console.log('');
if (printList.value.length) { // if (!checkLocalPrint(printList.value[0].config.deviceName)) {
console.log('本地打印'); // loading.value = true;
if (!checkLocalPrint(printList.value[0].config.deviceName)) { // let res = await loginlogout({
loading.value = true; // status: 1
let res = await loginlogout({ // })
status: 1 // // useStorage.clear()
}) // useStorage.del('userInfo')
// useStorage.clear() // useStorage.del('token')
useStorage.del('userInfo') // useStorage.del('douyin')
useStorage.del('token') // useStorage.del('categorysActive')
useStorage.del('douyin') // ElMessage.success("");
useStorage.del('categorysActive') // setTimeout(() => {
ElMessage.success("交班成功"); // router.replace({
setTimeout(() => { // name: "login",
router.replace({ // });
name: "login", // }, 1000);
}); // loading.value = false;
}, 1000); // } else {
loading.value = false; // //
// const data = await handoverData({
// id: infoData.value.id
// })
// data.deviceName = printList.value[0].config.deviceName
// data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
// ipcRenderer.send("printerWorkSync", JSON.stringify(data));
// // return
// // useStorage.clear()
// useStorage.del('userInfo')
// useStorage.del('token')
// useStorage.del('douyin')
// useStorage.del('categorysActive')
// ElMessage.success("");
// setTimeout(() => {
// router.replace({
// name: "login",
// });
// }, 1000);
// loading.value = false;
// }
} else { } else {
// console.log('云打印交班数据');
const data = await handoverData({
id: infoData.value.id
})
data.deviceName = printList.value[0].config.deviceName
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
ipcRenderer.send("printerWorkSync", JSON.stringify(data));
// return
// useStorage.clear()
useStorage.del('userInfo')
useStorage.del('token')
useStorage.del('douyin')
useStorage.del('categorysActive')
ElMessage.success("交班成功");
setTimeout(() => {
router.replace({
name: "login",
});
}, 1000);
loading.value = false;
}
} else {
console.log('云打印');
loading.value = true; loading.value = true;
await tglogout() await tglogout()