Browse Source

打印调试

lilei 2 years ago
parent
commit
50b8285a4d

+ 13 - 7
components/kk-printer/index.vue

@@ -70,8 +70,9 @@
 </template>
 
 <script>
-	// import tsc from '@/components/kk-printer/printer/tsc.js'
-	import esc from '@/components/kk-printer/printer/esc.js'
+	import tsc from '@/components/kk-printer/printer/tsc.js'
+	// import esc from '@/components/kk-printer/printer/esc.js'
+	import * as cpcl from '@/components/kk-printer/printer/cpcl.js'
 	import * as blesdk from './utils/bluetoolth';
 	import util from './utils/util.js';
 	export default {
@@ -86,13 +87,14 @@
 				//是否显示蓝牙列表
 				isShowSearch:false,
 				//按蓝牙名过滤
-				filterName:'',
+				filterName: ['DL-','BTP-'],
 				//按信号过滤
 				filterRSSI:-95,
 				//设备列表
 				devicesList:[],
 				//连接的设备ID
 				deviceId:'',
+				deviceName: '',
 				//根据设备ID获取的服务
 				services:'',
 				//获取特征值时返回的三要素
@@ -150,7 +152,7 @@
 				let filterDevices2
 				if(name!=''){
 					filterDevices2 = filterDevices1.filter((item)=>{
-						return (item.name.indexOf(name) >= 0 || item.deviceId.indexOf(name) >= 0)
+						return name.find(a => item.name.indexOf(a) >= 0 || item.deviceId.indexOf(a) >= 0)
 					})
 				}else{
 					filterDevices2 = filterDevices1
@@ -190,9 +192,11 @@
 							// 有正在连接的设备,且和上次连接设备一样
 							if(res.devices.length && res.devices[0].deviceId == lastDevice.deviceId){
 								this.deviceId = lastDevice.deviceId
+								this.deviceName = lastDevice.name
 								this.serviceId = lastDevice.serviceId
 								this.writeId = lastDevice.writeId
 								this.readId = lastDevice.readId
+								console.log(this.deviceName.indexOf('DL-')>=0?tsc:cpcl)
 								if(flag){
 									this.isPrinting = true;
 									this.$nextTick(()=>{
@@ -200,7 +204,9 @@
 											deviceId: this.deviceId,
 											serviceId: this.serviceId,
 											writeId: this.writeId
-										},esc,blesdk)
+										},
+										this.deviceName.indexOf('DL-')>=0?tsc:cpcl,
+										blesdk)
 									})
 								}
 							}else{
@@ -252,7 +258,7 @@
 				let deviceId = device.deviceId;
 				let name = device.name;
 				this.deviceId = deviceId;
-				console.log('deviceId',this.deviceId)
+				this.deviceName = name;
 				this.isConnecting = true
 				this.stopSearchBtnTap()
 				uni.onBLEConnectionStateChange(function(res){
@@ -305,7 +311,7 @@
 				this.readId = res.readId;
 				this.isShowSearch = false;
 				try {
-					uni.setStorageSync('vuex_lastBuleDevice', {deviceId:this.deviceId,serviceId:this.serviceId,writeId:this.writeId,readId:this.readId});
+					uni.setStorageSync('vuex_lastBuleDevice', {deviceId:this.deviceId,serviceId:this.serviceId,writeId:this.writeId,readId:this.readId,name:this.deviceName});
 				} catch (e) {
 					// error
 				}

+ 284 - 118
components/kk-printer/printer/cpcl.js

@@ -1,122 +1,288 @@
+/* 16hex insert 0 */
+function Hex2Str(num) {
+	if (num.toString(16).length < 2) return "0" + num.toString(16);
+	else
+		return num.toString(16);
+}
+/*****CPCL指令接口****/
+
 /**
- * cpcl 命令打印工具类
- * 2021.04.26 uni-app版本
- * @auth boolTrue
- */
-var gbk = require("./printUtil-GBK.js");
-var jpPrinter = {
-	createNew: function() {
-		var jpPrinter = {};
-		var data = "";
-		var command = []
-		var rawCommand = ''
-
-		jpPrinter.name = "标签模式";
-		
-		jpPrinter.addCommand = function(content) { //将指令转成数组装起
-			rawCommand += content
-		}
-		
-		jpPrinter.init = function(width, height, printNum, rotation = 0, offset = 0) {
-			var strCmd = '! ' + offset + ' 200 200 ' + height + ' ' + printNum + '\n';
-			strCmd += "PAGE-WIDTH " + width + '\n';
-			if (rotation == 1)
-				strCmd += "ZPROTATE90\n";
-			else if (rotation == 2)
-				strCmd += "ZPROTATE180\n";
-			else if (rotation == 3)
-				strCmd += "ZPROTATE270\n";
-			else
-				strCmd += "ZPROTATE0\n";
-			jpPrinter.addCommand(strCmd)
-		};
-		
-		jpPrinter.setText = function(x, y, font, xsize, ysize, str) { //横向打印文字
-			data = "T " + "4" + " " + xsize + " " + x + " " + y + " " + str + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setGap = function(pageWidth) { //设置标签模式
-			data = "GAP-SENSE" + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setSpeed = function(printSpeed) { //设置打印机速度0 - 5
-			data = "SPEED " + printSpeed + "\n";
-			jpPrinter.addCommand(data)
-		};
-
-		jpPrinter.setDensity = function(printDensity) { //设置打印机浓度最亮的打印输出为对比度级别 0。最暗的对比度级别为 3。
-			data = "CONTRAST " + printDensity + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setMag = function(w,h) { //字体放大指定的放大倍数。
-			data = "SETMAG " + w + " " + h + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setLine = function(x0, y0, x1, y1, width) { //绘制线条
-			data = "LINE " + x0 + " " + y0 + " " + x1 + " " + y1 + " " + width + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setBox = function(x_start, y_start, x_end, y_end, thickness) { //绘制方框
-			data = "BOX " + x_start + " " + y_start + " " + x_end + " " + y_end + " " + thickness + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setFeed = function(feed) { //将纸向前推出n
-			data = "PREFEED " + feed + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setQR = function(x, y, level, ver, scale, content) { //打印二维码
-			var strCmd = 'B QR ' + x + ' ' + y + ' M ' + ver + ' U ' + scale + '\n' + level + 'A,' + content + '\n';
-			strCmd += 'ENDQR\n';
-			jpPrinter.addCommand(strCmd)
-		};
-		
-		jpPrinter.setBar = function(type, width, ratio, height, x, y, content) { //打印条形码
-			data = "BARCODE " + type + " " + width + " " + ratio + " " + height + " " + x + " " + y + " " + content + "\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setSound = function(interval) { //控制蜂鸣器,蜂鸣持续时间
-			data = "BEEP " + interval + "\n";
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setPageForm = function() { //换页
-			data = "FORM "+"\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		jpPrinter.setPagePrint = function() { //打印页面
-			data = "PRINT "+"\n"
-			jpPrinter.addCommand(data)
-		};
-		
-		// 添加命令
-		jpPrinter.RawCommand = function(data) {
-			jpPrinter.addCommand(data)
-		}
-		
-		//获取打印数据
-		jpPrinter.getData = function() {
-			let buffer = gbk.strToGBKByte(rawCommand)
-			return buffer;
-		};
-
-		jpPrinter.getRawData = function() {
-			return rawCommand;
-		};
-		jpPrinter.clearCommand = function() {
-			rawCommand = ''
-		};
-
-		return jpPrinter;
+ * 配置项如下
+ *
+ * width: 标签纸的宽度,单位像素點
+ * height: 标签纸的高度,单位像素點
+ * 8像素=1mm
+ * printNum: 打印张数,默认为1
+ * rotation:页面整体旋转 1-90度 2-180度 3-270度 其他-不旋转
+ */
+export function CreatCPCLPage(width, height, printNum, rotation = 0, offset = 0) {
+	var strCmd = '! ' + offset + ' 200 200 ' + height + ' ' + printNum + '\n';
+	strCmd += "PAGE-WIDTH " + width + '\n';
+	if (rotation == 1)
+		strCmd += "ZPROTATE90\n";
+	else if (rotation == 2)
+		strCmd += "ZPROTATE180\n";
+	else if (rotation == 3)
+		strCmd += "ZPROTATE270\n";
+	else
+		strCmd += "ZPROTATE0\n";
+	return strCmd;
+}
+
+/**
+ * 打印文字
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * fontName,fontSize: 字体,取值: 參考文檔
+ * rotation: 旋转 1-90度 2-180度 3-270度 其他-不旋转 
+ * content: 文字内容
+ */
+export function addCPCLText(x, y, fontName, fontSize, rotation, content) {
+	//console.log(fontName,fontSize,rotation, content);   
+	var strCmd = '';
+	if (rotation == 1) {
+		strCmd += 'T90 ';
+	}
+	if (rotation == 2) {
+		strCmd += 'T180 ';
+	}
+	if (rotation == 3) {
+		strCmd += 'T270 ';
+	} else {
+		strCmd += 'T ';
+	}
+	strCmd += fontName + ' ' + fontSize + ' ' + x + ' ' + y + ' ' + content + '\n';
+	return strCmd;
+};
+
+/**
+ * 打印一维码
+ *
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * codeType: 条码类型,取值为128、UPCA、UPCA2、UPCA5、UPCE、UPCE2、UPC5、EAN13、EAN13+2、EAN13+5、
+ *      EAN8、EAN8+2、EAN8+5、39、39C、F39、F39C、93、CODABAR、CODABAR16、ITF、I2OF5
+ * h: 条码高度,单位dot 
+ * rotation: 顺时针旋转角度,取值如下:
+ *     - 0 不旋转
+ *     - 1 顺时针旋转90度
+ *     
+ * narrow: 窄条码比例因子(dot) 取值: 參考文檔
+ * wide: 宽条码比例因子(dot) 取值: 參考文檔
+ * content: 文字内容
+ *
+ */
+export function addCPCLBarCode(x, y, codeType, h, rotation, narrow, wide, content) {
+	var strCmd = '';
+	if (rotation == 0)
+		strCmd += 'B ';
+	else
+		strCmd += 'VB ';
+	strCmd += codeType + ' ' + narrow + ' ' + wide + ' ' + h + ' ' + x + ' ' + y + ' ' + content + '\n'
+	return strCmd;
+};
+
+/**
+ * 打印二维码
+ *
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * level: 错误纠正能力等级,取值为L(7%)、M(15%)、Q(25%)、H(30%)
+ * ver: 1-10 版本,根据内容调整以获取合适容量
+ * scale: 1-10 放大倍数
+ * content: 文字内容
+ *
+ */
+export function addCPCLQRCode(x, y, level, ver, scale, content) {
+	var strCmd = 'B QR ' + x + ' ' + y + ' M ' + ver + ' U ' + scale + '\n' + level + 'A,' + content + '\n';
+	strCmd += 'ENDQR\n';
+	return strCmd;
+};
+
+/**
+ * 放大指令
+ * scaleX: 横向放大倍数 1,2,3等整数
+ * scaleY: 纵向放大倍数 1,2,3等整数
+ */
+export function addCPCLSETMAG(scaleX, scaleY) {
+	var strCmd = 'SETMAG ' + scaleX + ' ' + scaleY + '\n';
+	return strCmd;
+};
+
+/**
+ * 对齐指令 0-左对齐 1-右对齐 2-居中
+ */
+export function addCPCLLocation(set) {
+	var strCmd = '';
+	if (set == 1) {
+		strCmd += 'RIGHT\n';
+	} else if (set == 2) {
+		strCmd += 'CENTER\n';
+	} else {
+		strCmd += 'LEFT\n';
+	}
+	return strCmd;
+};
+
+/**
+ * 反白线 x0,y0,x1,y1,width
+ */
+export function addCPCLInverseLine(x0, y0, x1, y1, width) {
+	var strCmd = 'IL ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
+	return strCmd;
+};
+
+/**
+ * 画线 x0,y0,x1,y1,width
+ */
+export function addCPCLLine(x0, y0, x1, y1, width) {
+	var strCmd = 'L ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
+	return strCmd;
+};
+
+/**
+ * 画框 x0,y0,x1,y1,width
+ */
+export function addCPCLBox(x0, y0, x1, y1, width) {
+	var strCmd = 'BOX ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
+	return strCmd;
+};
+
+/**
+ * 字体加粗
+ */
+export function addCPCLSETBOLD(bold) {
+	var strCmd = 'SETBOLD ' + bold + '\n';
+	return strCmd;
+};
+
+/**
+ * 字体下划线
+ */
+export function addCPCLUNDERLINE(c) {
+	var strCmd = 'UNDERLINE ';
+	if (c) strCmd += 'ON\n';
+	else if (c) strCmd += 'OFF\n';
+	return strCmd;
+};
+
+/**
+ * 水印打印灰度等级 0-255
+ */
+export function addCPCLBACKGROUND(level) {
+	var strCmd = 'BACKGROUND ';
+	if (level > 255 || level < 0) level = 255;
+	strCmd += level + '\n';
+	return strCmd;
+};
+
+/**
+ * 打印水印文字
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * fontName,fontSize: 字体,取值: 參考文檔
+ * rotation: 旋转 1-90度 2-180度 3-270度 其他-不旋转 
+ * content: 文字内容
+ */
+export function addCPCLBKVText(x, y, fontName, fontSize, rotation, content) {
+	//console.log(fontName,fontSize,rotation, content);   
+	var strCmd = '';
+	if (rotation == 1) {
+		strCmd += 'BKT90 ';
+	}
+	if (rotation == 2) {
+		strCmd += 'BKT180 ';
+	}
+	if (rotation == 3) {
+		strCmd += 'BKT270 ';
+	} else {
+		strCmd += 'BKT ';
 	}
+	strCmd += fontName + ' ' + fontSize + ' ' + x + ' ' + y + ' ' + content + '\n';
+	return strCmd;
+};
+
+
+/**
+ * 标签缝隙定位指令
+ */
+export function addCPCLGAP() {
+	var strCmd = 'GAP-SENSE\nFORM\n';
+	return strCmd;
 };
 
-module.exports.jpPrinter = jpPrinter;
+/**
+ * 标签右黑标检测指令
+ */
+export function addCPCLSENSE() {
+	var strCmd = 'BAR-SENSE\nFORM\n';
+	return strCmd;
+};
+
+/**
+ * 标签左黑标检测指令
+ */
+export function addCPCLSENSELEFT() {
+	var strCmd = 'BAR-SENSE LEFT\nFORM\n';
+	return strCmd;
+};
+
+/**
+ * 打印指令
+ */
+export function addCPCLPrint() {
+	var strCmd = 'PRINT\n';
+	return strCmd;
+};
+
+/**
+ * 图片打印指令
+ * x: 文字方块左上角X座标,单位dot
+ * y: 文字方块左上角Y座标,单位dot
+ * data{
+            threshold,//0/1提取的灰度级
+            width,//图像宽度
+            height,//图像高度
+            imageData , //图像数据
+    }
+ */
+export function addCPCLImageCmd(x, y, data) {
+	var strImgCmd = '';
+	const threshold = data.threshold || 180;
+	let myBitmapWidth = data.width,
+		myBitmapHeight = data.height;
+	let len = parseInt((myBitmapWidth + 7) / 8); //一行的数据长度
+	//console.log('len=',len);
+	//console.log('myBitmapWidth=',myBitmapWidth);
+	//console.log('myBitmapHeight=',myBitmapHeight);
+	let ndata = 0;
+	let i = 0;
+	let j = 0;
+	let sendImageData = new ArrayBuffer(len * myBitmapHeight);
+	sendImageData = new Uint8Array(sendImageData);
+	let pix = data.imageData;
+	console.log('pix=', pix);
+
+	for (i = 0; i < myBitmapHeight; i++) {
+		for (j = 0; j < len; j++) {
+			sendImageData[ndata + j] = 0;
+		}
+		for (j = 0; j < myBitmapWidth; j++) {
+			const grayPixle1 = grayPixle(pix.slice((i * myBitmapWidth + j) * 4, (i * myBitmapWidth + j) * 4 + 3));
+			if (grayPixle1 < threshold)
+				sendImageData[ndata + parseInt(j / 8)] |= (0x80 >> (j % 8));
+
+		}
+		ndata += len;
+	}
+	//console.log('sendImageData=',sendImageData);
+	//CPCL指令图片数据 
+	strImgCmd += 'EG ' + len + ' ' + myBitmapHeight + ' ' + x + ' ' + y + ' ';
+	for (i = 0; i < sendImageData.length; i++) {
+		strImgCmd += Hex2Str(sendImageData[i]);
+	}
+	strImgCmd += '\n';
+	//console.log(strImgCmd);
+	return strImgCmd;
+}
+module.exports.type = 'cpcl';

+ 1 - 0
components/kk-printer/printer/esc.js

@@ -311,3 +311,4 @@ var jpPrinter = {
 };
 
 module.exports.jpPrinter = jpPrinter;
+module.exports.type = 'esc';

+ 1 - 0
components/kk-printer/printer/tsc.js

@@ -384,3 +384,4 @@ var jpPrinter = {
 };
 
 module.exports.jpPrinter = jpPrinter;
+module.exports.type = 'tsc';

+ 30 - 2
components/kk-printer/utils/bluetoolth.js

@@ -250,7 +250,7 @@ export function onGetBLECharacteristicValueChange(options, onChange = function()
 			lasterSuccess,
     }
  */
-export function senBlData(deviceId, serviceId, characteristicId,uint8Array,lasterSuccess) {
+export function senBlData(deviceId, serviceId, characteristicId,uint8Array,lasterSuccess,lasterError) {
 	console.log('************deviceId = [' + deviceId + ']  serviceId = [' + serviceId + '] characteristics=[' +characteristicId+ "]")
 	var uint8Buf = Array.from(uint8Array);
 	function split_array(datas,size){
@@ -292,13 +292,41 @@ export function senBlData(deviceId, serviceId, characteristicId,uint8Array,laste
 			},
 			fail(e) {
 				console.log('发送数据失败',e)
+				lasterError()
 			}
 		})
 	}
    var i = 0;
 	realWriteData(sendloop, i);
 }
- 
+// cpcl 发送数据
+export function sendDataToDevice(options) {
+	let byteLength = options.value.byteLength;
+	//这里默认一次20个字节发送
+	const speed = plus.os.name != 'Android' ? 180 : 20; //20; 
+	console.log("send data 20");
+	console.log(options,byteLength,options.value);
+	if (byteLength > 0) {
+		uniAsyncPromise('writeBLECharacteristicValue', {
+				...options,
+				value: options.value.slice(0, byteLength > speed ? speed : byteLength),
+			})
+			.then((res) => {
+				if (byteLength > speed) {
+					sendDataToDevice({
+						...options,
+						value: options.value.slice(speed, byteLength),
+					});
+				} else {
+					options.lasterSuccess && options.lasterSuccess();
+				}
+			})
+			.catch((res) => {
+				console.log(res);
+				options.lasterError && options.lasterError();
+			});
+	}
+} 
 /**
  * toast显示捕获的蓝牙异常
  */

File diff suppressed because it is too large
+ 13 - 0
components/kk-printer/utils/printUtil-GBK.js


+ 67 - 0
libs/printTools.js

@@ -1,3 +1,4 @@
+import gbk from '@/components/kk-printer/utils/printUtil-GBK.js';
 // 获取文本字节总数
 export const getBytesCount = function(str){
 	var bytesCount = 0;
@@ -110,6 +111,72 @@ export const printTempl = function(tsc,data){
 	return command
 }
 
+// 格式化cpcl打印文本
+export const textCpclFormat = function(cpcl,text,maxFontNums,left,top,lightHeight,align,fontName,fontSize){
+	let rowTop = top
+	const maxNums = maxFontNums
+	const rowHeight = lightHeight
+	const textArr = getTextRows(text.replace(/\s+/g, ' '),maxNums*2)
+	const rows = textArr.length
+	let result = ''
+	for(let i=0;i<rows;i++){
+		if(align=="center"){
+			const ltxt = textArr[i]
+			const ltlen = getBytesCount(ltxt)/2
+			result += cpcl.addCPCLText(left+((maxNums-ltlen)/2)*rowHeight-2,rowTop,fontName,fontSize,0,ltxt);
+		}
+		else{
+			result += cpcl.addCPCLText(left,rowTop,fontName,fontSize,0,textArr[i]);
+		}
+		rowTop = rowTop+rowHeight+5
+	}
+	return {result:result,top:rowTop}
+}
+// 60 * 40 尺寸模板 cpcl 指令
+export const printCpclTempl = function(cpcl,data){
+	console.log(cpcl)
+	let top = 32 // 距离顶部
+	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
+	let rightLeft = (leftMaxFnums+2.5)*lightHeight
+	// 初始化打印机
+	let strCmd =cpcl.CreatCPCLPage(pageW*8,pageH*8,data.currentInven,0);
+	// 经销商文字高度,是否换行
+	const a = textCpclFormat(cpcl,data.dealerName,maxFontNums,left,top,lightHeight,"center",'55',0);
+	top = a.top;
+	strCmd += a.result;
+	// 数字货架名称文字
+	top = top+10;
+	const b = textCpclFormat(cpcl,data.shelfName,maxFontNums,left,top,lightHeight,"center",'55',0);
+	top = b.top;
+	strCmd += b.result;
+	// 二维码
+	top = top+15;
+	strCmd += cpcl.addCPCLQRCode(left*6,top,'M', 2, 6, data.barCode);
+	// 货位号
+	const c = textCpclFormat(cpcl,data.shelfPlaceCode,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',6);
+	const rightTop = c.top;
+	strCmd += c.result;
+	// 产品编码
+	top = rightTop + 1;
+	const d = textCpclFormat(cpcl,data.productCode,rightMaxFnums,rightLeft,top,lightHeight,"left",'3',0);
+	top = d.top;
+	strCmd += d.result;
+	// 打印人打印时间
+	top = top+6;
+	const e = textCpclFormat(cpcl,data.printDate,rightMaxFnums,rightLeft,top,lightHeight,"left",'7',0);
+	top = e.top;
+	strCmd += e.result;
+	strCmd += cpcl.addCPCLPrint();
+	console.log(strCmd)
+	return gbk.strToGBKByte(strCmd);
+}
+
 // 40 * 30 尺寸模板
 export const printMiniTempl = function(tsc,data){
 	let top = 24 // 距离顶部

+ 26 - 5
pages/common/printTag/printTag.vue

@@ -39,7 +39,7 @@
 	import { clzConfirm, numberToFixed } from '@/libs/tools';
 	import { shelfDetail } from '@/api/shelf'
 	import kkPrinter from '@/components/kk-printer/index.vue';
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	import moment from 'moment'
 	export default {
 		components:{
@@ -143,8 +143,8 @@
 				uni.hideLoading()
 			},
 			// 打印
-			startPrint(opt,tsc,blesdk){
-				console.log(opt,'opt')
+			startPrint(opt,cmd,blesdk){
+				console.log(opt,cmd,'opt')
 				this.getPrintContent()
 				if(this.printInfo.currentInven<=0){
 					uni.showToast({
@@ -159,8 +159,21 @@
 				}
 				this.isParinting = true
 				this.show = true
-				const command = printTempl(tsc,this.printInfo)
-				blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
+				// tsc 指令
+				if(cmd.type&&cmd.type=='tsc'){
+					const command = printTempl(cmd,this.printInfo)
+					blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
+				}else{
+					const resultData = printCpclTempl(cmd,this.printInfo)
+					blesdk.sendDataToDevice({
+										deviceId: opt.deviceId, 
+										serviceId: opt.serviceId, 
+										characteristicId: opt.writeId,
+										value: resultData,
+										lasterSuccess: this.onPrintSuccess,
+										lasterError: this.onPrintError
+									});
+				}
 			},
 			// 打印成功
 			onPrintSuccess(){
@@ -176,6 +189,14 @@
 					} 
 				  }
 				})
+			},
+			onPrintError(){
+				this.$refs.kkprinter.onPrintFail()
+				this.isParinting = false
+				this.show = false
+				uni.showToast({
+					title: '打印失败,请重试!'
+				})
 			}
 		}
 	}

+ 29 - 19
pages/replenishmentManage/manualPrint.vue

@@ -22,7 +22,7 @@
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import { shelfReplenishDetail, shelfReplenishDetailList, shelfReplenishPrintSign } from '@/api/shelfReplenish'
 	import partList from '@/pages/common/partList.vue'
-	import {printTempl} from '@/libs/printTools.js'
+	import {printTempl,printCpclTempl} from '@/libs/printTools.js'
 	export default {
 		components: { partList, kkPrinter },
 		data() {
@@ -113,33 +113,43 @@
 			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,{
-					dealerName: dealer.orgName,
-					shelfName: this.basicInfoData.shelfInfo.shelfName || '',
-					productCode: data.productCode || '',
-					productName: data.product.name || '',
-					shelfPlaceCode: data.shelfPlaceCode || '',
-					currentInven: data.printQty,
-					printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
-					printUser: dealer.userNameCN,
-					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}`
-				})
+				const dealer = this.$store.state.vuex_userData
+				let resultData = ''
+				const paramsData = {
+						dealerName: dealer.orgName,
+						shelfName: this.basicInfoData.shelfInfo.shelfName || '',
+						productCode: data.productCode || '',
+						productName: data.product.name || '',
+						shelfPlaceCode: data.shelfPlaceCode || '',
+						currentInven: data.printQty,
+						printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
+						printUser: dealer.userNameCN,
+						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, 
-				command.getData(), 
+				resultData, 
 				function(){
 					const result =_this.$refs.partList.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()
@@ -162,7 +172,7 @@
 				uni.hideLoading()
 			},
 			// 批量打印 
-			startPrint(opt,tsc,blesdk){
+			startPrint(opt,cmd,blesdk){
 				const result =this.$refs.partList.getAllChecked()
 				if(result.length){
 					 if(this.isParinting){
@@ -173,7 +183,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()

Some files were not shown because too many files changed in this diff