新增本地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

@@ -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);