| | |
| | | connectionStatus: "disconnected", // 连接状态: disconnected, connecting, connected |
| | | printStatus: "idle", // 打印状态: idle, printing, error |
| | | errorMessage: "", // 错误信息 |
| | | verificationNo:'' |
| | | verificationNo: "", |
| | | failedPrintJobs: [], |
| | | }; |
| | | }, |
| | | onLoad(options) { |
| | | this.verificationNo = JSON.parse(decodeURIComponent(options.verificationNo)) |
| | | }, |
| | | onLoad(options) { |
| | | this.verificationNo = JSON.parse( |
| | | decodeURIComponent(options.verificationNo) |
| | | ); |
| | | this.getlist(); |
| | | // 初始化SDK |
| | | jcapi.initSDK(); |
| | | |
| | | // 尝试恢复之前的蓝牙连接状态 |
| | | this.restoreBluetoothConnection(); |
| | | |
| | | // 监听页码回调 |
| | | jcapi.didReadPrintCountInfo(function(r) { |
| | | console.log('页码',r); |
| | | console.log("页码", r); |
| | | }); |
| | | |
| | | // 监听错误回调 |
| | | jcapi.didReadPrintErrorInfo((r) => { |
| | | console.log('错误',r); |
| | | console.log("错误", r); |
| | | if (r.code == 23) { |
| | | // 打印机断开连接 |
| | | this.connectedDevice = null; |
| | | // 清除本地存储的连接信息 |
| | | uni.removeStorageSync("bluetoothConnection"); |
| | | uni.showToast({ |
| | | icon: "none", |
| | | title: "打印机连接已断开,请重新连接", |
| | |
| | | }); |
| | | }, |
| | | methods: { |
| | | restoreBluetoothConnection() { |
| | | try { |
| | | // 从本地存储获取之前保存的连接信息 |
| | | const savedConnection = uni.getStorageSync("bluetoothConnection"); |
| | | if (savedConnection && savedConnection.address) { |
| | | console.log("尝试恢复蓝牙连接:", savedConnection); |
| | | // 设置为连接中状态 |
| | | this.connectionStatus = "connecting"; |
| | | |
| | | // 尝试重新连接 |
| | | jcapi.openPrinterByDevice({ |
| | | address: savedConnection.address, |
| | | name: savedConnection.name, |
| | | deviceType: 0, // 设备类型:0-蓝牙,1-网络 |
| | | }, |
| | | (r) => { |
| | | if (r.code == 0) { |
| | | this.connectedDevice = savedConnection; |
| | | this.connectionStatus = "connected"; |
| | | console.log("蓝牙连接已恢复"); |
| | | } else { |
| | | this.connectionStatus = "disconnected"; |
| | | // 如果重连失败,清除保存的连接信息 |
| | | uni.removeStorageSync("bluetoothConnection"); |
| | | console.log("蓝牙重连失败:", r); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | } catch (e) { |
| | | console.error("恢复蓝牙连接失败:", e); |
| | | } |
| | | }, |
| | | getmoreList() { |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | |
| | | }, 1000); |
| | | }, |
| | | getlist() { |
| | | this.$u.api.NuclearScaleEntry |
| | | .queryPacking({ |
| | | this.$u.api.NuclearScaleEntry.queryPacking({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | verificationNo: this.verificationNo, |
| | | }).then((res) => { |
| | | this.list = res.data; |
| | | this.total = res.data.length; |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | | } else { |
| | | this.status = "loadmore"; |
| | | } |
| | | }); |
| | | }, |
| | | search(value) { |
| | | if (value) { |
| | | this.list = []; |
| | | this.pageSize = 10; |
| | | this.$u.api.NuclearScaleEntry.queryPacking({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | verificationNo: this.verificationNo, |
| | | }) |
| | | .then((res) => { |
| | | this.list = res.data; |
| | | this.total = res.data.length; |
| | | moNo: value, |
| | | }).then((res) => { |
| | | this.list = res.data.records; |
| | | this.total = res.data.total; |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | | } else { |
| | | this.status = "loadmore"; |
| | | } |
| | | }); |
| | | }, |
| | | search(value) { |
| | | if (value) { |
| | | this.list = []; |
| | | this.pageSize = 10; |
| | | this.$u.api.NuclearScaleEntry |
| | | .queryPacking({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | moNo: value, |
| | | }) |
| | | .then((res) => { |
| | | this.list = res.data.records; |
| | | this.total = res.data.total; |
| | | if (this.pageSize >= this.total) { |
| | | this.status = "nomore"; |
| | | } else { |
| | | this.status = "loadmore"; |
| | | } |
| | | }); |
| | | } else { |
| | | this.getlist(); |
| | | } |
| | |
| | | moveHandle() {}, |
| | | maskclose() {}, |
| | | //打印二维码 |
| | | printQrCode(item) { |
| | | // return new Promise(async (resolve, reject) => { |
| | | printQrCode(item) { |
| | | return new Promise(async (resolve, reject) => { |
| | | // const params = { |
| | | // rwMatlBindId: item.id |
| | | // }; |
| | | try { |
| | | try { |
| | | // let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params) |
| | | if (!item) { |
| | | this.$refs.uToast.show({ |
| | |
| | | return; |
| | | } |
| | | |
| | | const ht = item.contractNo |
| | | const lj = item.partNo |
| | | const ljms = item.ccontrProModel |
| | | const fh = item.newNetWeight |
| | | const scdt = item.outboundDate |
| | | const scph = item.batchNo |
| | | const shdw = item.customerName |
| | | const fhdw = '江东合金技术有限公司' |
| | | const ht = item.contractNo; |
| | | const lj = item.partNo; |
| | | const ljms = item.ccontrProModel; |
| | | const fh = item.newNetWeight; |
| | | const scdt = item.productionDate; |
| | | const scph = item.batchNo; |
| | | const shdw = item.customerName; |
| | | const fhdw = "江东合金技术有限公司"; |
| | | |
| | | // 初始化画板 |
| | | jcapi.initDrawingBoard({ |
| | |
| | | }); |
| | | |
| | | // 绘制二维码 |
| | | const qrContent = { |
| | | company : item.customerNo, |
| | | line_no : item.lineNo, |
| | | lot_batch_no : item.batchNo, |
| | | order_no : item.contractNo, |
| | | part_no : item.partNo, |
| | | total_qty : item.newNetWeight, |
| | | qty_arrived : item.newNetWeight, |
| | | release_no : item.relNo, |
| | | } |
| | | |
| | | const qrContent = { |
| | | company: item.customerNo, |
| | | line_no: item.lineNo, |
| | | lot_batch_no: item.batchNo, |
| | | order_no: item.contractNo, |
| | | part_no: item.partNo, |
| | | total_qty: item.newNetWeight, |
| | | qty_arrived: item.newNetWeight, |
| | | release_no: item.relNo, |
| | | }; |
| | | |
| | | jcapi.drawLabelQrCode({ |
| | | x: 43.5, |
| | | y: 2, |
| | |
| | | this.getDrawLabelLine(1, 6, 42, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 11, 42, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 16, 42, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 21, 42, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 27, 67, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 23, 42, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 27.5, 67, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 32, 67, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 37, 67, 0.3, 0, LineType.Solid); |
| | | this.getDrawLabelLine(1, 42, 67, 0.3, 0, LineType.Solid); |
| | |
| | | this.getDrawLabelLine(68, 1, 0.5, 46, 0, LineType.Solid); // 竖线3 |
| | | |
| | | // 绘制文本 |
| | | this.getDrawLabelText(3, 2.5, 40, 8, "中天科技装箱清单", 2.5, 0, LineModeType.AutoHeight, |
| | | 0, 0, 1, 1, 1); |
| | | this.getDrawLabelText(2, 7, 25, 8, "合同号:", 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 1, 1); |
| | | this.getDrawLabelText(2, 12, 25, 8, "零件号:", 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 1, 1); |
| | | this.getDrawLabelText(2, 17, 25, 8, "零件描述:", 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 1, 1); |
| | | this.getDrawLabelText(2, 22.5, 25, 8, "发货/装箱数:", 2.5, 0, LineModeType.AutoHeight, |
| | | 0, 0, 0, 1, 1); |
| | | this.getDrawLabelText(2, 27.5, 25, 8, "生产日期:", 2.5, 0, LineModeType.AutoHeight, 0, |
| | | 0, 0, 1, 1); |
| | | this.getDrawLabelText(2, 32.5, 25, 8, "生产批号:", 2.5, 0, LineModeType.AutoHeight, 0, |
| | | 0, 0, 1, 1); |
| | | this.getDrawLabelText(2, 37.5, 25, 8, "发货单位:", 2.5, 0, LineModeType.AutoHeight, 0, |
| | | 0, 0, 1, 1); |
| | | this.getDrawLabelText(2, 42.5, 25, 8, "收货单位:", 2.5, 0, LineModeType.AutoHeight, 0, |
| | | 0, 0, 1, 1); |
| | | this.getDrawLabelText( |
| | | 3, |
| | | 2.5, |
| | | 40, |
| | | 8, |
| | | "中天科技装箱清单", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 7, |
| | | 25, |
| | | 8, |
| | | "合同号:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 12, |
| | | 25, |
| | | 8, |
| | | "零件号:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 17, |
| | | 25, |
| | | 8, |
| | | "零件描述:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 23.5, |
| | | 25, |
| | | 8, |
| | | "发货/装箱数:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 28.5, |
| | | 25, |
| | | 8, |
| | | "生产日期:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 32.5, |
| | | 25, |
| | | 8, |
| | | "生产批号:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 37.5, |
| | | 25, |
| | | 8, |
| | | "发货单位:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 2, |
| | | 42.5, |
| | | 25, |
| | | 8, |
| | | "收货单位:", |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1, |
| | | 1 |
| | | ); |
| | | |
| | | // 填充参数值 |
| | | this.getDrawLabelText(11, 7, 30, 8, ht, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, |
| | | 0, 1); |
| | | this.getDrawLabelText(11, 12, 32, 8, lj, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, |
| | | 0, 1); |
| | | this.getDrawLabelText(14, 17, 30, 8, ljms, 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 0, 1); |
| | | this.getDrawLabelText(17, 22.5, 27, 8, fh, 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 0, 1); |
| | | this.getDrawLabelText(14, 27.5, 55, 8, scdt, 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 0, 1); |
| | | this.getDrawLabelText(14, 32.7, 55, 8, scph, 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 0, 1); |
| | | this.getDrawLabelText(14, 37.5, 55, 8, fhdw, 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 0, 1); |
| | | this.getDrawLabelText(14, 42.5, 55, 8, shdw, 2.5, 0, LineModeType.AutoHeight, 0, 0, |
| | | 0, 0, 1); |
| | | this.getDrawLabelText( |
| | | 11, |
| | | 7, |
| | | 30, |
| | | 8, |
| | | ht, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 11, |
| | | 12, |
| | | 32, |
| | | 8, |
| | | lj, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 14, |
| | | 17, |
| | | 30, |
| | | 8, |
| | | ljms, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 17, |
| | | 23.5, |
| | | 27, |
| | | 8, |
| | | fh, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 14, |
| | | 28.5, |
| | | 55, |
| | | 8, |
| | | scdt, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 14, |
| | | 32.7, |
| | | 55, |
| | | 8, |
| | | scph, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 14, |
| | | 37.5, |
| | | 55, |
| | | 8, |
| | | fhdw, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | this.getDrawLabelText( |
| | | 14, |
| | | 42.5, |
| | | 55, |
| | | 8, |
| | | shdw, |
| | | 2.5, |
| | | 0, |
| | | LineModeType.AutoHeight, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 1 |
| | | ); |
| | | // 生成打印数据 |
| | | let imageJsonObj = jcapi.generateLabelJson(); |
| | | |
| | |
| | | labelType: this.labelType, |
| | | printMode: this.printMode, |
| | | }, |
| | | function (r) { |
| | | function(r) { |
| | | if (r.code == 0) { |
| | | // 打印数据 |
| | | // 存储原始打印计数回调 |
| | |
| | | |
| | | // 添加打印超时处理 |
| | | const printTimeout = setTimeout(() => { |
| | | jcapi.didReadPrintCountInfo( |
| | | originalPrintCountCallback); |
| | | jcapi.didReadPrintCountInfo(originalPrintCountCallback); |
| | | reject(new Error("打印超时未响应")); |
| | | }, 20000); |
| | | |
| | |
| | | } catch (error) { |
| | | reject(error); |
| | | } |
| | | // }); |
| | | }); |
| | | }, |
| | | tapQuery(item) { |
| | | this.maskShow = false; |
| | |
| | | deviceType: 0, // 设备类型:0-蓝牙,1-网络 |
| | | }, |
| | | function(r) { |
| | | // 在tapQuery方法中,连接成功时添加保存连接信息的代码 |
| | | if (r.code == 0) { |
| | | _this.connectedDevice = item; |
| | | _this.connectionStatus = "connected"; |
| | | // 保存连接信息到本地存储 |
| | | uni.setStorageSync("bluetoothConnection", item); |
| | | uni.showToast({ |
| | | title: "连接成功", |
| | | duration: 1500, |