更新没有usb打印机时调用云打印机
This commit is contained in:
parent
f8c5c9bf59
commit
ac469cbc32
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "vite-electron",
|
||||
"private": true,
|
||||
"version": "1.4.11",
|
||||
"version": "1.4.12",
|
||||
"main": "dist-electron/main.js",
|
||||
"scripts": {
|
||||
"dev": "chcp 65001 && vite",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
@ -6,6 +6,7 @@ import dayjs from "dayjs";
|
|||
import receiptPrint from "@/components/lodop/receiptPrint.js";
|
||||
import lodopPrintWork from "@/components/lodop/lodopPrintWork.js";
|
||||
import invoicePrint from "@/components/lodop/invoicePrint.js";
|
||||
import refundPrint from "@/components/lodop/refundPrint.js";
|
||||
|
||||
export const usePrint = defineStore({
|
||||
id: "print",
|
||||
|
|
@ -203,5 +204,17 @@ export const usePrint = defineStore({
|
|||
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("退单小票:没有小票打印机");
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ const isPrint = ref(true);
|
|||
const printHandle = _.throttle(async function () {
|
||||
try {
|
||||
if (!isPrint.value) return;
|
||||
printLoading.value = true;
|
||||
const data = {
|
||||
shop_name: store.userInfo.shopName,
|
||||
loginAccount: store.userInfo.loginAccount,
|
||||
|
|
@ -134,20 +135,20 @@ const printHandle = _.throttle(async function () {
|
|||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
};
|
||||
printStore.labelPrint(data)
|
||||
printStore.pushReceiptData(data)
|
||||
// try {
|
||||
// printLoading.value = true;
|
||||
// await print({
|
||||
// type: "normal",
|
||||
// ispre: true,
|
||||
// orderId: props.orderInfo.id,
|
||||
// });
|
||||
// printLoading.value = false;
|
||||
// // ElMessage.success("打印成功");
|
||||
// } catch (error) {
|
||||
// printLoading.value = false;
|
||||
// console.log(error);
|
||||
// }
|
||||
setTimeout(() => {
|
||||
printLoading.value = false;
|
||||
}, 1500)
|
||||
if (printStore.deviceNoteList.length) {
|
||||
printStore.pushReceiptData(data)
|
||||
} else {
|
||||
await print({
|
||||
type: "normal",
|
||||
ispre: true,
|
||||
orderId: props.orderInfo.id,
|
||||
});
|
||||
printLoading.value = false;
|
||||
ElMessage.success("打印成功");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
|
@ -194,8 +195,19 @@ async function printOrderLable() {
|
|||
})
|
||||
// 打印标签
|
||||
printStore.labelPrint(data)
|
||||
// 打印小票
|
||||
printStore.pushReceiptData(data)
|
||||
|
||||
if (printStore.deviceNoteList.length) {
|
||||
// 打印小票
|
||||
printStore.pushReceiptData(data)
|
||||
} else {
|
||||
await print({
|
||||
type: "normal",
|
||||
ispre: true,
|
||||
orderId: props.orderInfo.id,
|
||||
});
|
||||
printLoading.value = false;
|
||||
ElMessage.success("打印成功");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,17 +46,25 @@ const orderInfo = ref({})
|
|||
async function printEwmHandle() {
|
||||
try {
|
||||
printEwmLoading.value = true
|
||||
printStore.printInvoice({
|
||||
url: ewmInfo.value.wechat_url
|
||||
})
|
||||
// const res = await syjprintqrcode({
|
||||
// id: ewmInfo.value.id
|
||||
// })
|
||||
ElMessage.success('打印成功')
|
||||
showEwmDialog.value = false
|
||||
setTimeout(() => {
|
||||
printEwmLoading.value = false
|
||||
}, 1000)
|
||||
if (printStore.deviceNoteList.length) {
|
||||
printStore.printInvoice({
|
||||
url: ewmInfo.value.wechat_url
|
||||
})
|
||||
ElMessage.success('打印成功')
|
||||
showEwmDialog.value = false
|
||||
setTimeout(() => {
|
||||
printEwmLoading.value = false
|
||||
}, 1000)
|
||||
} else {
|
||||
const res = await syjprintqrcode({
|
||||
id: ewmInfo.value.id
|
||||
})
|
||||
ElMessage.success('打印成功')
|
||||
showEwmDialog.value = false
|
||||
setTimeout(() => {
|
||||
printEwmLoading.value = false
|
||||
}, 1000)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
printEwmLoading.value = false
|
||||
|
|
|
|||
|
|
@ -142,8 +142,19 @@
|
|||
(orderDetaildata.status == 'refund' ||
|
||||
orderDetaildata.status == 'closed')
|
||||
">开发票</el-button>
|
||||
<el-button :loading="normalPrintLoading" @click="print('normal')" style="flex: 1">重打小票</el-button>
|
||||
<el-button :loading="labelPrintLoading" @click="print('label')" style="flex: 1">重打标签</el-button>
|
||||
<el-button :loading="normalPrintLoading" @click="print('normal')" style="flex: 1" v-if="
|
||||
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>
|
||||
|
|
@ -445,47 +456,94 @@ const print = lodash.throttle(
|
|||
setTimeout(() => {
|
||||
labelPrintLoading.value = false
|
||||
}, 1000)
|
||||
} else {
|
||||
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"),
|
||||
} else if (e == 'normal') {
|
||||
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.pushReceiptData(data);
|
||||
setTimeout(() => {
|
||||
normalPrintLoading.value = false
|
||||
}, 1000)
|
||||
} else {
|
||||
// 云打票
|
||||
await cloudPrinterprint({
|
||||
type: e,
|
||||
orderId: orderDetaildata.value.id,
|
||||
ispre: false,
|
||||
});
|
||||
ElMessage({
|
||||
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",
|
||||
});
|
||||
}
|
||||
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.pushReceiptData(data);
|
||||
setTimeout(() => {
|
||||
normalPrintLoading.value = false
|
||||
}, 1000)
|
||||
// // 云打票
|
||||
// await cloudPrinterprint({
|
||||
// type: e,
|
||||
// orderId: orderDetaildata.value.id,
|
||||
// ispre: false,
|
||||
// });
|
||||
// ElMessage({
|
||||
// message: "成功打票",
|
||||
// type: "success",
|
||||
// });
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
|
|
|||
|
|
@ -159,125 +159,83 @@ const dialogVisible = ref(false) //交班
|
|||
const infoData = ref({})
|
||||
const loading = ref(false);
|
||||
|
||||
const printList = ref([]);
|
||||
const localPrintList = ref([])
|
||||
|
||||
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 () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
let data = {}
|
||||
// 获取交班打印小票数据
|
||||
data = await handoverData({
|
||||
id: infoData.value.id
|
||||
})
|
||||
if (printStore.deviceNoteList.length) {
|
||||
loading.value = true;
|
||||
let data = {}
|
||||
// 获取交班打印小票数据
|
||||
data = await handoverData({
|
||||
id: infoData.value.id
|
||||
})
|
||||
|
||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
data.printShop = isPrint.value
|
||||
printStore.printWork(data)
|
||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
data.printShop = isPrint.value
|
||||
printStore.printWork(data)
|
||||
|
||||
// return
|
||||
await loginlogout({
|
||||
status: 1
|
||||
})
|
||||
// return
|
||||
await loginlogout({
|
||||
status: 1
|
||||
})
|
||||
|
||||
useStorage.del('userInfo')
|
||||
useStorage.del('token')
|
||||
useStorage.del('douyin')
|
||||
useStorage.del('categorysActive')
|
||||
useStorage.del('userInfo')
|
||||
useStorage.del('token')
|
||||
useStorage.del('douyin')
|
||||
useStorage.del('categorysActive')
|
||||
|
||||
ElMessage.success("交班成功");
|
||||
setTimeout(() => {
|
||||
router.replace({
|
||||
name: "login",
|
||||
});
|
||||
}, 1000);
|
||||
loading.value = false;
|
||||
return
|
||||
if (printList.value.length) {
|
||||
console.log('本地打印');
|
||||
if (!checkLocalPrint(printList.value[0].config.deviceName)) {
|
||||
loading.value = true;
|
||||
let res = await loginlogout({
|
||||
status: 1
|
||||
})
|
||||
// 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 {
|
||||
// 获取交班打印小票数据
|
||||
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;
|
||||
}
|
||||
ElMessage.success("交班成功");
|
||||
setTimeout(() => {
|
||||
router.replace({
|
||||
name: "login",
|
||||
});
|
||||
}, 1000);
|
||||
loading.value = false;
|
||||
// console.log('本地打印');
|
||||
// if (!checkLocalPrint(printList.value[0].config.deviceName)) {
|
||||
// loading.value = true;
|
||||
// let res = await loginlogout({
|
||||
// status: 1
|
||||
// })
|
||||
// // 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 {
|
||||
// // 获取交班打印小票数据
|
||||
// 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('云打印');
|
||||
console.log('云打印交班数据');
|
||||
loading.value = true;
|
||||
|
||||
await tglogout()
|
||||
|
|
|
|||
Loading…
Reference in New Issue