|
@@ -1,6 +1,10 @@
|
|
|
import { mapState, mapActions } from "vuex";
|
|
|
import { FakeConnectedDevice } from "@psdk/frame-father";
|
|
|
import bluetoothTool from "@/plugins/BluetoothTool.js";
|
|
|
+import { printMaterial } from "@/common/request/apis/print";
|
|
|
+import printPop from "@/components/print-pop/print-pop.vue";
|
|
|
+import blePop from "@/components/ble-pop/ble-pop.vue";
|
|
|
+import bleTipPop from "@/components/ble-tip-pop/ble-tip-pop.vue";
|
|
|
|
|
|
import {
|
|
|
TBar,
|
|
@@ -41,6 +45,11 @@ async function sendMessage(cmd) {
|
|
|
|
|
|
export default {
|
|
|
name: "blePrintMixin",
|
|
|
+ components: {
|
|
|
+ printPop,
|
|
|
+ blePop,
|
|
|
+ bleTipPop,
|
|
|
+ },
|
|
|
computed: {
|
|
|
...mapState({
|
|
|
discoveredDevices: (state) => state.ble.discoveredDevices, // 已发现的蓝牙设备
|
|
@@ -67,7 +76,6 @@ export default {
|
|
|
},
|
|
|
};
|
|
|
},
|
|
|
- mounted() {},
|
|
|
methods: {
|
|
|
...mapActions("ble", [
|
|
|
"checkBleStatus", // 检查蓝牙设备连接状态
|
|
@@ -136,71 +144,76 @@ export default {
|
|
|
/**
|
|
|
* 打印
|
|
|
*@data {Object} 需要打印的数据
|
|
|
+ *@num {number} 需要打印的数量
|
|
|
* */
|
|
|
- async writeTsplModel(data) {
|
|
|
+ async writeTsplModel(data, num = 1) {
|
|
|
const vm = this;
|
|
|
const obj = {
|
|
|
- qrCode: data.qrCode, // 二维码
|
|
|
+ qrCode: data.number, // 二维码
|
|
|
barCode: data.barCode, // 商品条码
|
|
|
customerName: data.customerName, //客户名
|
|
|
number: data.number, // 单据编号
|
|
|
- batchNumber: data.batchNumber, // 批次条码
|
|
|
};
|
|
|
try {
|
|
|
+ let cellWidth = 6;
|
|
|
+ if (obj.qrCode.length > 30) cellWidth = 4;
|
|
|
+ if (obj.qrCode.length > 60) cellWidth = 2;
|
|
|
+
|
|
|
+ const startX = 80;
|
|
|
+ const startY = 30;
|
|
|
+ const qrcodeX = startX;
|
|
|
+ const qrcodeY = startY;
|
|
|
+ const qrcodeSize = cellWidth * 21; // 经验值
|
|
|
+ const textStartX = qrcodeX + qrcodeSize + 10;
|
|
|
+ const textStartY = qrcodeY;
|
|
|
+ const textLineHeight = 28;
|
|
|
+
|
|
|
+ const barcodeX = startX;
|
|
|
+ const barcodeY =
|
|
|
+ Math.max(qrcodeY + qrcodeSize, textStartY + textLineHeight * 3) + 15;
|
|
|
+ const barcodeHeight = 50;
|
|
|
+
|
|
|
const tspl = await vm.$printer
|
|
|
.tspl()
|
|
|
.clear()
|
|
|
- .page(
|
|
|
- new TPage({
|
|
|
- width: 76,
|
|
|
- height: 130,
|
|
|
- })
|
|
|
- )
|
|
|
+ .page(new TPage({ width: 76, height: 130 }))
|
|
|
.qrcode(
|
|
|
new TQRCode({
|
|
|
- x: 50,
|
|
|
- y: 20,
|
|
|
- content: "283423982494284284828484",
|
|
|
- cellWidth: 10,
|
|
|
+ x: qrcodeX,
|
|
|
+ y: qrcodeY,
|
|
|
+ content: obj.qrCode,
|
|
|
+ cellWidth,
|
|
|
})
|
|
|
)
|
|
|
.text(
|
|
|
new TText({
|
|
|
- x: 50 + 30,
|
|
|
- y: 20,
|
|
|
+ x: textStartX,
|
|
|
+ y: textStartY,
|
|
|
content: obj.customerName,
|
|
|
font: TFont.TSS24,
|
|
|
})
|
|
|
)
|
|
|
.text(
|
|
|
new TText({
|
|
|
- x: 50 + 30,
|
|
|
- y: 20 + 35,
|
|
|
+ x: textStartX,
|
|
|
+ y: textStartY + textLineHeight * 2,
|
|
|
content: obj.number,
|
|
|
font: TFont.TSS24,
|
|
|
})
|
|
|
)
|
|
|
.barcode(
|
|
|
new TBarCode({
|
|
|
- x: 50,
|
|
|
- y: 20 + 35 + 20,
|
|
|
+ x: barcodeX,
|
|
|
+ y: barcodeY,
|
|
|
cellWidth: 2,
|
|
|
- height: 60,
|
|
|
+ height: barcodeHeight,
|
|
|
content: obj.barCode,
|
|
|
rotation: TRotation.ROTATION_0,
|
|
|
codeType: TCodeType.CODE128,
|
|
|
showType: 2,
|
|
|
})
|
|
|
)
|
|
|
- .text(
|
|
|
- new TText({
|
|
|
- x: 50 + 20,
|
|
|
- y: 50 + 100,
|
|
|
- content: obj.barCode,
|
|
|
- font: TFont.TSS24,
|
|
|
- })
|
|
|
- )
|
|
|
- .print();
|
|
|
+ .print(num);
|
|
|
var binary = tspl.command().binary();
|
|
|
await sendMessage(Array.from(uint8ArrayToSignedArray(binary)));
|
|
|
} catch (e) {
|
|
@@ -212,9 +225,40 @@ export default {
|
|
|
},
|
|
|
|
|
|
async writeData({ num = 1, data }) {
|
|
|
- for (let i = 0; i < num; i++) {
|
|
|
- await this.writeTsplModel(data);
|
|
|
+ await this.writeTsplModel(data, num);
|
|
|
+ },
|
|
|
+ //条码逻辑
|
|
|
+ async handlePrint(id) {
|
|
|
+ try {
|
|
|
+ uni.showLoading({
|
|
|
+ mask: true,
|
|
|
+ });
|
|
|
+ const res = await printMaterial({ id });
|
|
|
+ console.log("item===id==", id);
|
|
|
+ console.log("res=====", res);
|
|
|
+ if (res.code == 200) {
|
|
|
+ const data = {
|
|
|
+ customerName: res.data.customerName,
|
|
|
+ number: res.data.number,
|
|
|
+ barCode: res.data.barCode,
|
|
|
+ };
|
|
|
+ this.openBlePrintPop(data);
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ icon: "none",
|
|
|
+ title: res.msg || res.data || "服务器错误",
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ //TODO handle the exception
|
|
|
+ } finally {
|
|
|
+ uni.hideLoading();
|
|
|
}
|
|
|
},
|
|
|
+ //开始打印
|
|
|
+ startPrint(data) {
|
|
|
+ this.writeData(data);
|
|
|
+ },
|
|
|
},
|
|
|
};
|