lilei 2 anni fa
parent
commit
24eef3c34d

+ 7 - 5
components/kk-printer/utils/bluetoolth.js

@@ -303,7 +303,7 @@ export function senBlData(deviceId, serviceId, characteristicId,uint8Array,laste
 export function sendDataToDevice(options) {
 	let byteLength = options.value.byteLength;
 	//这里默认一次20个字节发送
-	const speed = plus.os.name != 'Android' ? 180 : 20; //20; 
+	const speed = plus.os.name != 'Android' ? 180 : 15; //20; 
 	console.log("send data 20");
 	console.log(options,byteLength,options.value);
 	if (byteLength > 0) {
@@ -313,10 +313,12 @@ export function sendDataToDevice(options) {
 			})
 			.then((res) => {
 				if (byteLength > speed) {
-					sendDataToDevice({
-						...options,
-						value: options.value.slice(speed, byteLength),
-					});
+					setTimeout(()=>{
+						sendDataToDevice({
+							...options,
+							value: options.value.slice(speed, byteLength),
+						});
+					},50)
 				} else {
 					options.lasterSuccess && options.lasterSuccess();
 				}

+ 7 - 7
libs/printTools.js

@@ -134,30 +134,30 @@ export const textCpclFormat = function(cpcl,text,maxFontNums,left,top,lightHeigh
 // 60 * 40 尺寸模板 cpcl 指令
 export const printCpclTempl = function(cpcl,data){
 	console.log(cpcl)
-	let top = 24 // 距离顶部
+	let top = 0 // 距离顶部
 	const left = 8 // 距离左边
 	const lightHeight = 24 // 行高3mm,1mm = 8点
 	const pageW = 60 // 页签宽度mm
 	const pageH = 40 // 页签高度mm
 	const maxFontNums = Math.floor((pageW*8-left*4)/lightHeight) // 每行最多字体数
 	const leftMaxFnums = Math.floor(maxFontNums*0.4)
-	const rightMaxFnums = leftMaxFnums + 1
+	const rightMaxFnums = leftMaxFnums + 2
 	let rightLeft = (leftMaxFnums+2)*lightHeight
 	// 初始化打印机
 	let strCmd =cpcl.CreatCPCLPage(pageW*8,pageH*8,data.currentInven,0);
 	// 经销商文字高度,是否换行
-	const a = textCpclFormat(cpcl,data.dealerName,maxFontNums,left,top,lightHeight,"center",'24',0);
+	const a = textCpclFormat(cpcl,data.dealerName,maxFontNums,0,top,lightHeight,"center",'24',0);
 	top = a.top;
 	strCmd += a.result;
 	// 数字货架名称文字
 	top = top+10;
-	const b = textCpclFormat(cpcl,data.shelfName,maxFontNums,left,top,lightHeight,"center",'24',0);
+	const b = textCpclFormat(cpcl,data.shelfName,maxFontNums,0,top,lightHeight,"center",'24',0);
 	top = b.top;
 	strCmd += b.result;
 	// 二维码
 	top = top+15;
 	strCmd += cpcl.addCPCLLocation(0);
-	strCmd += cpcl.addCPCLQRCode(left*6,top,'M', 3, 5, data.barCode);
+	strCmd += cpcl.addCPCLQRCode(left*5,top,'M', 3, 5, data.barCode);
 	// 货位号
 	strCmd += cpcl.addCPCLSETMAG(4,4);
 	const c = textCpclFormat(cpcl,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',0);
@@ -175,10 +175,10 @@ export const printCpclTempl = function(cpcl,data){
 	const e = textCpclFormat(cpcl,data.printDate,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',0);
 	top = e.top;
 	strCmd += e.result;
-	strCmd += 'FORM \n\r'
+	strCmd += 'FORM \n'
 	strCmd += cpcl.addCPCLPrint();
 	console.log(strCmd)
-	return plus.os.name != 'Android' ? gbk.strToGBKByte(strCmd) : plus.android.invoke(strCmd , 'getBytes', 'gbk');
+	return gbk.strToGBKByte(strCmd);
 }
 
 // 40 * 30 尺寸模板

+ 35 - 16
pages/batchShelves/batchPrint/batchPrint.vue

@@ -38,7 +38,7 @@
 	import { clzConfirm, numberToFixed } from '@/libs/tools';
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import productList from './productList.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	export default {
 		components: { productList, kkPrinter },
 		data() {
@@ -144,11 +144,10 @@
 			allCheckedCallback(val){
 				this.allChecked = val
 			},
-			printOnce(opt,tsc,blesdk,data){
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
-				// 60*40 打印模板
-				const command = printTempl(tsc,{
+				const paramsData = {
 					dealerName: dealer.orgName,
 					shelfName: this.basicInfoData.shelfName || '',
 					productCode: data.productCode || '',
@@ -158,18 +157,13 @@
 					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
 					printUser: dealer.userNameCN,
 					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				}
+				// 打印成功后函数
+				const onPrintSuccess = function(){
 					const result =_this.$refs.productList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						_this.printIndex = 0
 						_this.$refs.kkprinter.onPrintSuccess()
@@ -185,14 +179,39 @@
 						  }
 						})
 					}
-				});
+				}
+				// 开始批量打印
+				// tsc 指令 // 60*40 打印模板
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,paramsData)
+					blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
 			},
 			closeConnect(){
 				this.isParinting = false
 				uni.hideLoading()
 			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.productList.getAllChecked()
 				console.log(result,result.length)
 				if(result.length){
@@ -204,7 +223,7 @@
 					 	mask: true,
 					 	title: '正在打印中,请勿息屏或退出应用!'
 					 })
-					 this.printOnce(opt,tsc,blesdk,result[this.printIndex])
+					 this.printOnce(opt,cmd,blesdk,result[this.printIndex])
 				}else{
 					this.toashMsg("请选择产品!")
 					this.$refs.kkprinter.onPrintFail()

+ 29 - 17
pages/replenishmentManage/manualPrint.vue

@@ -117,7 +117,6 @@
 				const _this = this
 				// 60*40 打印模板
 				const dealer = this.$store.state.vuex_userData
-				let resultData = ''
 				const paramsData = {
 						dealerName: dealer.orgName,
 						shelfName: this.basicInfoData.shelfInfo.shelfName || '',
@@ -130,22 +129,9 @@
 						barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
 						// barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
 					}
-				// tsc 指令
-				console.log(cmd,cmd.type)
-				if(cmd.type&&cmd.type=='tsc'){
-					const command = printTempl(cmd,paramsData)
-					resultData = command.getData()
-				}else{
-					resultData = cmd.getData(printCpclTempl(cmd,paramsData))
-				}
 				
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				resultData, 
-				function(){
+				// 打印成功后函数
+				const onPrintSuccess = function(){
 					const result =_this.$refs.partList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
@@ -165,12 +151,38 @@
 						  }
 						})
 					}
-				});
+				}
+				// tsc 指令
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,paramsData)
+					// 开始批量打印
+					blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
+				
 			},
 			closeConnect(){
 				this.isParinting = false
 				uni.hideLoading()
 			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
 			// 批量打印 
 			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.partList.getAllChecked()

+ 42 - 16
pages/shelfSetting/batchPrint.vue

@@ -24,7 +24,7 @@
 	import { clzConfirm, numberToFixed } from '@/libs/tools';
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import productList from './productList.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	export default {
 		components: { productList, kkPrinter },
 		data() {
@@ -92,11 +92,10 @@
 			allCheckedCallback(val){
 				this.allChecked = val
 			},
-			printOnce(opt,tsc,blesdk,data){
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
-				// 60*40 打印模板
-				const command = printTempl(tsc,{
+				const paramsData = {
 					dealerName: dealer.orgName,
 					shelfName: data.shelfName || '',
 					productCode: data.productCode || '',
@@ -106,18 +105,12 @@
 					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
 					printUser: dealer.userNameCN,
 					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				}
+				const onPrintSuccess = function(){
 					const result =_this.$refs.productList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						_this.printIndex = 0
 						_this.$refs.kkprinter.onPrintSuccess()
@@ -133,14 +126,47 @@
 						  }
 						})
 					}
-				});
+				}
+				// 开始批量打印
+				// tsc 指令 // 60*40 打印模板
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,paramsData)
+					// 开始批量打印 
+					blesdk.senBlData(
+					opt.deviceId, 
+					opt.serviceId, 
+					opt.writeId, 
+					command.getData(), 
+					onPrintSuccess
+					);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
+				
 			},
 			closeConnect(){
 				this.isParinting = false
 				uni.hideLoading()
 			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.productList.getAllChecked()
 				console.log(result,result.length)
 				if(result.length){
@@ -152,7 +178,7 @@
 					 	mask: true,
 						title: '正在打印中,请勿息屏或退出应用!'
 					 })
-					 this.printOnce(opt,tsc,blesdk,result[this.printIndex])
+					 this.printOnce(opt,cmd,blesdk,result[this.printIndex])
 				}else{
 					this.toashMsg("请选择产品!")
 					this.$refs.kkprinter.onPrintFail()

+ 41 - 16
pages/shelfSetting/quickReplenish.vue

@@ -41,7 +41,7 @@
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import chooseTypeModal from './chooseTypeModal.vue'
 	import stockModal from '@/pages/replenishmentManage/stockModal.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	import {saveReplenishBill} from '@/api/shelfReplenish.js'
 	import {clzConfirm} from '@/libs/tools.js'
 	export default {
@@ -173,11 +173,18 @@
 				this.isParinting = false
 				uni.hideLoading()
 			},
-			printOnce(opt,tsc,blesdk,data){
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
+			},
+			printOnce(opt,cmd,blesdk,data){
 				const _this = this
 				const dealer = this.$store.state.vuex_userData
-				// 60*40 打印模板
-				const command = printTempl(tsc,{
+				const paramsData = {
 					dealerName: dealer.orgName,
 					shelfName: this.basicInfoData.shelfName || '',
 					productCode: data.productCode || '',
@@ -187,18 +194,12 @@
 					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
 					printUser: dealer.userNameCN,
 					barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
-				})
-				// 开始批量打印 
-				blesdk.senBlData(
-				opt.deviceId, 
-				opt.serviceId, 
-				opt.writeId, 
-				command.getData(), 
-				function(){
+				}
+				const onPrintSuccess = function(){
 					const result =_this.$refs.productList.getAllChecked()
 					_this.printIndex = _this.printIndex + 1
 					if(_this.printIndex < result.length){
-						_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+						_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					}else{
 						// 打印结束
 						_this.printIndex = 0
@@ -214,10 +215,34 @@
 						  }
 						})
 					}
-				});
+				}
+				// 开始批量打印
+				// tsc 指令 // 60*40 打印模板
+				console.log(cmd,cmd.type)
+				if(cmd.type&&cmd.type=='tsc'){
+					// 60*40 打印模板
+					const command = printTempl(cmd,paramsData)
+					// 开始批量打印 
+					blesdk.senBlData(
+					opt.deviceId, 
+					opt.serviceId, 
+					opt.writeId, 
+					command.getData(), 
+					onPrintSuccess);
+				}else{
+					const resultData = printCpclTempl(cmd,paramsData)
+					blesdk.sendDataToDevice({
+						deviceId: opt.deviceId, 
+						serviceId: opt.serviceId, 
+						characteristicId: opt.writeId,
+						value: resultData,
+						lasterSuccess: onPrintSuccess,
+						lasterError: this.onPrintError
+					});
+				}
 			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const _this = this
 				const result =_this.$refs.productList.getAllChecked()
 				console.log(result,result.length)
@@ -231,7 +256,7 @@
 					   success (ret) {
 					 	if (ret.confirm || ret.index == 0) {
 					 		_this.isParinting = true
-					 		_this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
+					 		_this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
 					 	}else{
 							_this.$refs.kkprinter.onPrintFail()
 							_this.isParinting = false