| | |
| | | <template> |
| | | <view class="page"> |
| | | <view class="finishProductIn-locno-bg" /> |
| | | <u-navbar title="核磅记录" :background="background" :border-bottom="false" :title-bold="true" title-color="#000" |
| | | back-icon-color="#000"> |
| | | <u-navbar |
| | | title="核磅记录" |
| | | :background="background" |
| | | :border-bottom="false" |
| | | :title-bold="true" |
| | | title-color="#000" |
| | | back-icon-color="#000" |
| | | > |
| | | <view class="navbar-right" slot="right" @click="goPrintAll"> |
| | | 全部打印 |
| | | </view> |
| | | </u-navbar> |
| | | <view class="wrap"> |
| | | <!-- 连接和打印状态指示器 --> |
| | | <view class="status-indicator" :class="{ |
| | | <view |
| | | class="status-indicator" |
| | | :class="{ |
| | | connected: connectionStatus === 'connected', |
| | | connecting: connectionStatus === 'connecting', |
| | | disconnected: connectionStatus === 'disconnected', |
| | | }"> |
| | | }" |
| | | > |
| | | <text class="status-text">{{ getConnectionStatusText() }}</text> |
| | | <text class="print-status" v-if="printStatus !== 'idle'">- {{ getPrintStatusText() }}</text> |
| | | <text class="print-status" v-if="printStatus !== 'idle'" |
| | | >- {{ getPrintStatusText() }}</text |
| | | > |
| | | </view> |
| | | <scroll-view class="finishProductIn-locno-scroll-list" scroll-y="true" @scrolltolower="getmoreList()"> |
| | | <u-cell-group class="finishProductIn-locno-scroll-list-group" :border="false"> |
| | | <view class="content" v-for="(item, index) in list" :key="item.locNo" :index="index" |
| | | @click="selectNo(item)"> |
| | | <scroll-view |
| | | class="finishProductIn-locno-scroll-list" |
| | | scroll-y="true" |
| | | @scrolltolower="getmoreList()" |
| | | > |
| | | <u-cell-group |
| | | class="finishProductIn-locno-scroll-list-group" |
| | | :border="false" |
| | | > |
| | | <view |
| | | class="content" |
| | | v-for="(item, index) in list" |
| | | :key="item.locNo" |
| | | :index="index" |
| | | @click="selectNo(item)" |
| | | > |
| | | <view class="content-header"> |
| | | <view class="content-header-title">{{ index + 1 }}</view> |
| | | </view> |
| | |
| | | </view> |
| | | </u-cell-group> |
| | | <view class="loadmore" @click="getmoreList()"> |
| | | <u-loadmore :status="status" :load-text="loadText" @loadmore="getmoreList()" /> |
| | | <u-loadmore |
| | | :status="status" |
| | | :load-text="loadText" |
| | | @loadmore="getmoreList()" |
| | | /> |
| | | </view> |
| | | </scroll-view> |
| | | </view> |
| | | <u-toast ref="uToast" /> |
| | | <u-modal v-model="maskShow" title="" :show-confirm-button="false"> |
| | | <view @touchmove.stop.prevent="moveHandle" @click="maskclose"> |
| | | <scroll-view class="uni-scroll_box" scroll-y @touchmove.stop.prevent="moveHandle" |
| | | @click.stop="moveHandle"> |
| | | <scroll-view |
| | | class="uni-scroll_box" |
| | | scroll-y |
| | | @touchmove.stop.prevent="moveHandle" |
| | | @click.stop="moveHandle" |
| | | > |
| | | <view class="modal-title">选择蓝牙设备</view> |
| | | <view v-if="listDevice.length === 0" class="empty-tip">暂无设备</view> |
| | | <view v-for="(item, index) in listDevice" :key="index" @click="tapQuery(item)" class="device-item"> |
| | | <view |
| | | v-for="(item, index) in listDevice" |
| | | :key="index" |
| | | @click="tapQuery(item)" |
| | | class="device-item" |
| | | > |
| | | <view class="device-name"> |
| | | <text>名称:</text> |
| | | <text>{{ item.name || "未知设备" }}</text> |
| | |
| | | connectionStatus: "disconnected", // 连接状态: disconnected, connecting, connected |
| | | printStatus: "idle", // 打印状态: idle, printing, error |
| | | errorMessage: "", // 错误信息 |
| | | verificationNo:'' |
| | | verificationNo: "", |
| | | failedPrintJobs: [], |
| | | }; |
| | | }, |
| | | onLoad(options) { |
| | | this.verificationNo = JSON.parse(decodeURIComponent(options.verificationNo)) |
| | | 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) => { |
| | | }).then((res) => { |
| | | this.list = res.data; |
| | | this.total = res.data.length; |
| | | if (this.pageSize >= this.total) { |
| | |
| | | if (value) { |
| | | this.list = []; |
| | | this.pageSize = 10; |
| | | this.$u.api.NuclearScaleEntry |
| | | .queryPacking({ |
| | | this.$u.api.NuclearScaleEntry.queryPacking({ |
| | | current: this.pageNum, |
| | | size: this.pageSize, |
| | | moNo: value, |
| | | }) |
| | | .then((res) => { |
| | | }).then((res) => { |
| | | this.list = res.data.records; |
| | | this.total = res.data.total; |
| | | if (this.pageSize >= this.total) { |
| | |
| | | maskclose() {}, |
| | | //打印二维码 |
| | | printQrCode(item) { |
| | | // return new Promise(async (resolve, reject) => { |
| | | return new Promise(async (resolve, reject) => { |
| | | // const params = { |
| | | // rwMatlBindId: item.id |
| | | // }; |
| | |
| | | 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.outboundDate; |
| | | const scph = item.batchNo; |
| | | const shdw = item.customerName; |
| | | const fhdw = "江东合金技术有限公司"; |
| | | |
| | | // 初始化画板 |
| | | jcapi.initDrawingBoard({ |
| | |
| | | total_qty : item.newNetWeight, |
| | | qty_arrived : item.newNetWeight, |
| | | release_no : item.relNo, |
| | | } |
| | | }; |
| | | |
| | | jcapi.drawLabelQrCode({ |
| | | x: 43.5, |
| | |
| | | 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, |
| | | 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(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, |
| | | 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 |
| | | ); |
| | | // 生成打印数据 |
| | | let imageJsonObj = jcapi.generateLabelJson(); |
| | | |
| | | // 设置打印任务 |
| | | jcapi.startJob({ |
| | | jcapi.startJob( |
| | | { |
| | | totalCount: 1, |
| | | density: this.printDensity, |
| | | labelType: this.labelType, |
| | |
| | | |
| | | // 添加打印超时处理 |
| | | const printTimeout = setTimeout(() => { |
| | | jcapi.didReadPrintCountInfo( |
| | | originalPrintCountCallback); |
| | | jcapi.didReadPrintCountInfo(originalPrintCountCallback); |
| | | reject(new Error("打印超时未响应")); |
| | | }, 20000); |
| | | |
| | | jcapi.printData( |
| | | imageJsonObj, { |
| | | imageJsonObj, |
| | | { |
| | | printQuantity: 1, |
| | | }, |
| | | function(r) { |
| | | if (r.code != 0) { |
| | | // 恢复原始回调 |
| | | jcapi.didReadPrintCountInfo( |
| | | originalPrintCountCallback); |
| | | jcapi.didReadPrintCountInfo(originalPrintCountCallback); |
| | | // 结束当前打印任务 |
| | | reject(new Error(r.msg || "打印失败")); |
| | | } |
| | |
| | | } catch (error) { |
| | | reject(error); |
| | | } |
| | | // }); |
| | | }); |
| | | }, |
| | | tapQuery(item) { |
| | | this.maskShow = false; |
| | |
| | | // 设置为连接中状态 |
| | | this.connectionStatus = "connecting"; |
| | | |
| | | jcapi.openPrinterByDevice({ |
| | | jcapi.openPrinterByDevice( |
| | | { |
| | | address: item.address, |
| | | name: item.name, |
| | | 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, |