新增本地USB打印

This commit is contained in:
gyq
2024-07-29 18:10:01 +08:00
parent 4fb34a4235
commit b2e450fd52
8 changed files with 222 additions and 46 deletions

View File

@@ -1,5 +1,4 @@
<!-- 结算订单 -->
<template>
<el-drawer size="100%" :with-header="false" direction="btt" v-model="dialogVisible">
<div class="drawer_wrap">
@@ -77,6 +76,8 @@ import { ElMessage } from "element-plus";
import dayjs from "dayjs";
import useStorage from '@/utils/useStorage'
import { ipcRenderer } from "electron";
import { formatDecimal } from '@/utils/index.js'
import receiptPrint from "@/components/lodop/receiptPrint.js";
import { usePrint } from '@/store/print.js'
const printStore = usePrint()
@@ -122,31 +123,30 @@ const printHandle = _.throttle(async function () {
try {
if (!isPrint.value) return;
const data = {
shop_name: store.userInfo.merchantName,
shop_name: store.userInfo.shopName,
loginAccount: store.userInfo.loginAccount,
carts: props.cart,
amount: props.amount,
remark: props.remark,
orderInfo: props.orderInfo,
createdAt: dayjs(props.orderInfo.createdAt).format(
"YYYY-MM-DD HH:mm:ss"
),
createdAt: dayjs(props.orderInfo.createdAt).format("YYYY-MM-DD HH:mm:ss"),
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
printStore.labelPrint(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);
}
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);
// }
} catch (error) {
console.log(error);
}
@@ -166,13 +166,17 @@ async function printOrderLable() {
const printLabelOrder = res.list[0]
const data = {
shop_name: store.userInfo.merchantName,
shop_name: store.userInfo.shopName,
loginAccount: store.userInfo.loginAccount,
carts: [],
amount: printLabelOrder.orderAmount,
remark: printLabelOrder.remark,
orderInfo: printLabelOrder,
outNumber: printLabelOrder.outNumber,
createdAt: dayjs(printLabelOrder.createdAt).format(
"YYYY-MM-DD HH:mm:ss"
)
),
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
}
printLabelOrder.skuInfos.map(item => {
data.carts.push(
@@ -180,13 +184,16 @@ async function printOrderLable() {
categoryId: item.categoryId,
name: item.productName,
number: item.num,
skuName: item.productSkuName
skuName: item.productSkuName,
salePrice: formatDecimal(item.priceAmount / item.num),
totalAmount: formatDecimal(item.priceAmount)
}
)
})
// console.log('重打标签小票', data);
// 打印标签
printStore.labelPrint(data)
// 打印小票
printStore.pushReceiptData(data)
} catch (error) {
console.log(error);
}

View File

@@ -142,8 +142,8 @@
(orderDetaildata.status == 'refund' ||
orderDetaildata.status == 'closed')
">开发票</el-button>
<el-button @click="print('normal')" style="flex: 1">重打小票</el-button>
<el-button @click="print('label')" style="flex: 1">重打标签</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>
</div>
</div>
</div>
@@ -300,7 +300,7 @@ import {
} from "@/api/order/index.js";
import add from "@/views/order/components/add.vue";
import cashTable from "@/views/order/components/cashTable.vue";
import { clearNoNum } from "@/utils";
import { clearNoNum, formatDecimal } from "@/utils";
import md5 from "js-md5";
import dateRange from './components/dateRange.vue'
import { useGlobal } from "@/store/global.js";
@@ -311,6 +311,9 @@ const invoiceLoading = ref(false)
const invoiceRef = ref(null)
const takeFoodCodeRef = ref(null);
const labelPrintLoading = ref(false)
const normalPrintLoading = ref(false)
const global = useGlobal();
const store = useUser();
@@ -417,8 +420,10 @@ const print = lodash.throttle(
try {
if (e == "label") {
// checkLabelPrint(printLabelOrder.value)
labelPrintLoading.value = true
const data = {
shop_name: store.userInfo.merchantName,
shop_name: store.userInfo.shopName,
loginAccount: store.userInfo.loginAccount,
carts: [],
orderInfo: printLabelOrder.value,
outNumber: printLabelOrder.value.outNumber,
@@ -437,16 +442,50 @@ const print = lodash.throttle(
// console.log('重打标签小票', data);
printStore.labelPrint(data);
setTimeout(() => {
labelPrintLoading.value = false
}, 1000)
} else {
await cloudPrinterprint({
type: e,
orderId: orderDetaildata.value.id,
ispre: false,
});
ElMessage({
message: "成功打票",
type: "success",
});
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)
// // 云打票
// await cloudPrinterprint({
// type: e,
// orderId: orderDetaildata.value.id,
// ispre: false,
// });
// ElMessage({
// message: "成功打票",
// type: "success",
// });
}
} catch (error) {
console.log(error);