// 多张连续打印 import BluePrint from '@/pages/print/bluePrint.js' import {addPrintRecord} from '@/api/print.js' export default { methods:{ printComp(reprintPram){ let reprint = '' let ptintContext =[]; // 是否重复打印 if(reprintPram){ reprint = 'REPRINT' } uni.showLoading({ mask: true, title: "正在连接..." }) // 针对接口返回不同的字段名称进行判断 if(this.materlist.wareMaterialCode == undefined){ this.materlist.wareMaterialCode = this.materlist.code || this.materlist.warematerialCode ||'' } if(this.materlist.wareMaterialName == undefined){ this.materlist.wareMaterialName = this.materlist.warematerialName || this.materlist.name || '' } if(this.materlist.barNo==undefined){ this.materlist.barNo = this.materlist.batchNo || this.materlist.itemBatchNo || '' } //物料名称是否换行 let name = this.materlist.wareMaterialName || '' let name_1 = name.length > 38 ? name.substr(0, 38) : name let name_2 = name.length > 38 ? name.substr(38) : '' //供应商是否换行 let desc = this.materlist.supplier || '' let desc_1 = desc.length > 38 ? desc.substr(0, 38) : desc let desc_2 = desc.length > 38 ? desc.substr(38) : '' // this.warehouse.PurchaseNo ptintContext = [ {type:'text',x:0,y:0,text:'',size:2,rotate:0,bold:0,underline:false,reverse:false}, {type:'text',x:0,y:0,text:'',size:2,rotate:0,bold:0,underline:false,reverse:false}, {type:'text',x:0,y:0,text:'',size:2,rotate:0,bold:0,underline:false,reverse:false}, /* 以上空数据,为防止丢包时打印不正常 */ {type:'line',x1:3,y1:3,x2:560,y2: 3,width:2}, //上边线 {type:'line',x1:3,y1:3,x2:3,y2: 420,width:2},//左边线 {type:'line',x1:3,y1:420,x2:560,y2: 420,width:2}, //最下边线 {type:'line',x1:560,y1:3,x2:560,y2:420,width:2}, //右边线 {type:'text',x:10,y:34,text:`Part:`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'text',x:80,y:24,text:`${this.materlist.wareMaterialCode}`,size:4,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:3,y1:80,x2:560,y2:80,width:2}, {type:'text',x:10,y:90,text:`Descript:${name_1}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'text',x:10,y:115,text:`${name_2}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:3,y1:150,x2:560,y2:150,width:2}, {type:'text',x:10,y:170,text:`Vendor:${desc_1}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'text',x:10,y:175,text:`${desc_2}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:3,y1:210,x2:560,y2:210,width:2}, {type:'text',x:10,y:225,text:`PO:${this.materlist.purchaseNo || ''}/${this.materlist.ebelp || ''}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:3,y1:260,x2:350,y2:260,width:2}, {type:'text',x:10,y:275,text:`Qty:${this.ermNum} ${this.materlist.unit == null ? '' : this.materlist.unit}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:3,y1:310,x2:350,y2:310,width:2}, {type:'text',x:10,y:325,text:`Batch:${this.materlist.barNo}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, // {type:'text',x:155,y:323,text:``,size:3,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:3,y1:360,x2:350,y2:360,width:2}, {type:'text',x:10,y:380,text:`Time:${this.getCurrentDate().date} ${this.getCurrentDate().time}`,size:2,rotate:0,bold:1,underline:false,reverse:false}, // {type:'text',x:155,y:378,text:`${this.getCurrentDate().time}`,size:3,rotate:0,bold:1,underline:false,reverse:false}, {type:'line',x1:350,y1:210,x2:350,y2:420,width:2}, {type:'qr',x:380,y:220,text:`PARTS NUMBER: ${this.materlist.wareMaterialCode},SAP: ${this.materlist.sap_Location || ''},LOT NO: ${this.materlist.barNo},QUANTITY: ${this.ermNum}`,width:4,level:1}, {type:'text',x:405,y:390,text:`${reprint}`,size:2,rotate:0,bold:1,underline:false,reverse:false} ] console.log(ptintContext) // addPrintRecord(this.addForm).then(res => { BluePrint.print(this.$store,ptintContext).then(()=>{ let routes = getCurrentPages(); // 获取当前打开过的页面路由数组 let curRoute = routes[routes.length - 1].route //获取当前页面路由 if (curRoute == 'pages/print/bluetoothConnection') {// 连接蓝牙失败 跳页面 return } this.contLabel-- if (this.contLabel <= 0) { uni.hideLoading(); uni.showToast({ title: `打印完成`, duration: 2000 }) this.contLabel = 1 return } uni.showLoading({ mask: true, title: `打印中,剩余:${this.contLabel}` }) this.timer = setTimeout(() => { //间隔5秒 减少打印丢失 clearTimeout(this.timer) this.timer = null this.printComp(reprintPram) // 添加打印记录 this.addForm.code = this.materlist.wareMaterialCode; this.addForm.name = this.materlist.name; this.addForm.batchNo = this.materlist.barNo ; this.addForm.specificationModel = this.materlist.specificationModel; //这里不再记录打印记录,因为有了斑马打印 【Editby shaocx,2023-05-22】 /* addPrintRecord(this.addForm).then(res => { console.log(res); }) //*/ }, 10000) }).catch((err)=>{ uni.showToast({ title:'打印失败', duration: 2000 }) }) } } }