Browse Source

打印优化

lilei 3 years ago
parent
commit
0cad1f6910
4 changed files with 134 additions and 64 deletions
  1. 2 2
      manifest.json
  2. 120 60
      pages/common/printTag/printTag.vue
  3. 11 1
      pages/latePlay/chooseProduct.vue
  4. 1 1
      pages/login/login.vue

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
     "name" : "iSCM智慧供应链",
     "appid" : "__UNI__5B57B68",
     "description" : "iSCM智慧供应链系统",
-    "versionName" : "1.0.0",
-    "versionCode" : 100,
+    "versionName" : "1.0.1",
+    "versionCode" : 101,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {

+ 120 - 60
pages/common/printTag/printTag.vue

@@ -46,73 +46,128 @@
 			_this.infoData = options.data ? JSON.parse(options.data) : {},
 			_this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
 			console.log(_this.infoData)
-			var myDate = new Date()
-			if(_this.fromPage == 'bdtq'){
-				_this.printInfo = {
-					dealerName: _this.$store.state.vuex_userData.orgName,
-					shelfName: _this.infoData.shelfName || '',
-					productCode: _this.infoData.productEntity&&_this.infoData.productEntity.code || '',
-					productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
-					shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
-					currentInven: _this.printNum,
-					printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
-					printUser: _this.$store.state.vuex_userData.username,
-					barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productEntity&&_this.infoData.productEntity.productSn}&productCode=${_this.infoData.productEntity&&_this.infoData.productEntity.code}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
-				}
-			}else if(_this.fromPage == 'smdy'){
-				_this.printInfo = {
-					dealerName: _this.$store.state.vuex_userData.orgName,
-					shelfName: _this.infoData.shelfName || '',
-					productCode: _this.infoData.productCode || '',
-					productName: _this.infoData.productName || '',
-					shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
-					currentInven: _this.printNum,
-					printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
-					printUser: _this.$store.state.vuex_userData.username,
-					barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productSn}&productCode=${_this.infoData.productCode}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
-				}
-			}
-			console.log('printInfo-----------',_this.printInfo)
 		},
 		onUnload() {
-			this.$refs.kkprinter.closeConnect()
+			// this.$refs.kkprinter.closeConnect()
+			this.printNum = 0
+			this.infoData = null
+			this.printInfo = null
+			this.fromPage = ''
 		},
 		methods: {
 			cansel(){
 				uni.$emit('refreshBL')
 				uni.navigateBack()
 			},
-			textFormat(command,text,maxFontNums,left,top,lightHeight){
-				const textLen = text.length
-				console.log(textLen,maxFontNums)
-				if(textLen > maxFontNums){
-					const rows = Math.ceil(textLen/maxFontNums)
-					for(let i=0;i<rows;i++){
-						top = top+i*lightHeight
-						console.log(top)
-						// 最后一行
-						if(i==rows-1){
-							const ltxt = text.substring(i*maxFontNums)
-							const ltlen = ltxt.length
-							command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, top, "TSS24.BF2", 1, 1, ltxt)
-						}else{
-							command.setText(left, top, "TSS24.BF2", 1, 1, text.substring(i*maxFontNums,maxFontNums))
+			// 获取打印内容
+			getPrintContent(){
+				const _this = this
+				const myDate = new Date()
+				if(_this.fromPage == 'bdtq'){
+					_this.printInfo = {
+						dealerName: _this.$store.state.vuex_userData.orgName,
+						shelfName: _this.infoData.shelfName || '',
+						productCode: _this.infoData.productEntity&&_this.infoData.productEntity.code || '',
+						productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
+						shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
+						currentInven: _this.printNum,
+						printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
+						printUser: _this.$store.state.vuex_userData.username,
+						barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productEntity&&_this.infoData.productEntity.productSn}&productCode=${_this.infoData.productEntity&&_this.infoData.productEntity.code}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
+					}
+				}else if(_this.fromPage == 'smdy'){
+					_this.printInfo = {
+						dealerName: _this.$store.state.vuex_userData.orgName,
+						shelfName: _this.infoData.shelfName || '',
+						productCode: _this.infoData.productCode || '',
+						productName: _this.infoData.productName || '',
+						shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
+						currentInven: _this.printNum,
+						printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
+						printUser: _this.$store.state.vuex_userData.username,
+						barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productSn}&productCode=${_this.infoData.productCode}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
+					}
+				}
+				console.log('printInfo-----------',_this.printInfo)
+			},
+			getBytesCount(str){
+				var bytesCount = 0;
+				if (str != null) {
+					for (var i = 0; i < str.length; i++) {
+						var c = str.charAt(i);
+						if (c.match(/[^\x00-\xff]/ig) != null) //全角
+						{
+							bytesCount += 2;
+						} else {
+							bytesCount += 1;
 						}
 					}
-				}else{
-					command.setText(left+((maxFontNums-textLen)/2)*lightHeight, top, "TSS24.BF2", 1, 1, text)
 				}
-				return top
+				return bytesCount;
+			},
+			// JS 包含中文的字符串按固定长度拆分换行算法
+			getTextRows(str,iPageSize){
+				var strArray = [];
+				var tempStr = "";
+				var iTotalLength = this.getBytesCount(str);
+				for (var i = 0; i < str.length; i++) {
+					var iCount = this.getBytesCount(str[i]);
+					var iCountTemp = this.getBytesCount(tempStr);
+					//iCountTemp + iCount >= iPageSize 这里可能出现两种情况:
+					//长度等于 iPageSize 或 等于 iPageSize + 1(最后一个为中文字符就等于 9 + 2 情况)
+					if (iCountTemp + iCount >= iPageSize) {
+						tempStr += str[i];
+						strArray.push(tempStr);
+						// console.log("iCountTemp + iCount >= iPageSize " + tempStr)
+						tempStr = "";
+					} else {
+						tempStr += str[i];
+					}
+				}
+				
+				// //最后一次尾巴
+				if (tempStr.length > 0){
+					strArray.push(tempStr)
+				}
+				return strArray
+			},
+			textFormat(command,text,maxFontNums,left,top,lightHeight,align,fontSize){
+				let rowTop = top
+				const textArr = this.getTextRows(text.replace(/\s+/g, ' '),maxFontNums*2)
+				const rows = textArr.length
+				for(let i=0;i<rows;i++){
+					if(align=="center"){
+						const ltxt = textArr[i]
+						const ltlen = ltxt.replace(/[^x00-xFF]/g,'**').length/2
+						command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
+					}
+					else{
+						command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
+					}
+					rowTop = rowTop+lightHeight
+				}
+				return rowTop
 			},
 			// 打印
 			startPrint(opt,tsc,blesdk){
 				console.log(opt,'opt')
+				this.getPrintContent()
+				if(this.printInfo.currentInven<=0){
+					uni.showToast({
+						icon:"none",
+						title: "请选择打印数量"
+					})
+					this.$refs.kkprinter.onPrintFail()
+					return
+				}
 				let top = 10 // 距离顶部10点像素
-				const left = 10 // 距离左边10点
+				const left = 24 // 距离左边
 				const lightHeight = 24 // 行高3mm,1mm = 8点
 				const pageW = 40 // 页签宽度mm
 				const pageH = 30 // 页签高度mm
 				const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
+				let rightTop = 0
+				let rightLeft = Math.floor(maxFontNums*0.7)*lightHeight
 				// 初始化打印机
 				const command = tsc.jpPrinter.createNew()
 				command.init()
@@ -120,20 +175,25 @@
 				command.setGap(2) // 标签上下间距,单位mm
 				command.setCls() // 清除缓冲区数据
 				// 经销商文字高度,是否换行
-				top = this.textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight)
+				top = this.textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight,"center",1)
 				// 数字货架名称文字
-				top = top+lightHeight
-				top = this.textFormat(command,this.printInfo.shelfName,Math.floor(maxFontNums*0.6),left,top,lightHeight)
+				top = top+10
+				rightTop = top
+				const lwidth = Math.floor(maxFontNums*0.6)
+				rightLeft = (lwidth + 1.5) * lightHeight
+				top = this.textFormat(command,this.printInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
 				// 产品编码
-				top = top+lightHeight+15
-				command.setText(left, top, "TSS24.BF2", 1, 1, this.printInfo.productCode)
+				top = top+10
+				top = this.textFormat(command,this.printInfo.productCode,lwidth,left,top,lightHeight,"left",1)
 				// 产品名称
-				top = top+lightHeight
-				this.textFormat(command,this.printInfo.productName,Math.floor(maxFontNums*0.6),left,top,lightHeight)
-				
-				// command.setQR(50, 50, "L", 5, "A", "https://www.baidu.com")
-				// command.setBox(5, 5, 795, 595, 1)
-				command.setPagePrint(1,1) // 打印分数1,每个标签重发打印2次
+				top = top+5
+				top = this.textFormat(command,this.printInfo.productName,lwidth,left,top,lightHeight,"left",1)
+				// 货位号
+				this.textFormat(command,this.printInfo.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
+				// 二维码
+				const qrtop = rightTop +lightHeight+10
+				command.setQR(rightLeft, qrtop, "L", 3, "A", this.printInfo.barCode)
+				command.setPagePrint(1,this.printInfo.currentInven) // 打印分数1,每个标签重发打印2次
 				console.log("开始打印了",command.getData())
 				blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
 			},
@@ -190,9 +250,9 @@
 			.pno{
 				background: rgba(3, 54, 146, 0.15);
 				border-radius: 100rpx;
-				padding: 6rpx 20rpx;
+				padding: 4rpx 20rpx;
 				color: #033692;
-				font-size: 24rpx;
+				font-size: 26rpx;
 			}
 		}
 	}

+ 11 - 1
pages/latePlay/chooseProduct.vue

@@ -27,7 +27,7 @@
 							</view>
 							<view class="pinfo">
 								<view class="pname">
-									{{item.productEntity&&item.productEntity.productName}}
+									<text>{{item.shelfPlaceCode}}</text>{{item.productEntity&&item.productEntity.productName}}
 								</view>
 								<view class="ptxt flex align_center justify_between">
 									<view>
@@ -114,6 +114,7 @@
 					uni.hideLoading()
 					if(res.status == 200){
 						let list = res.data.list
+						console.log(list)
 						if (list && list.length){
 							// 分页 拼接数据
 							if (_this.pageNo != 1) {
@@ -212,6 +213,15 @@
 							color: #191919;
 							font-weight: bold;
 							margin-bottom: 10rpx;
+							text{
+								font-weight: normal;
+								margin-right: 6rpx;
+								padding: 0 10rpx;
+								background: rgba(3, 54, 146, 0.15);
+								border-radius: 100rpx;
+								color: #033692;
+								font-size: 28rpx;
+							}
 						}
 						.pno{
 							background-color: rgba(3, 54, 146, 0.15);

+ 1 - 1
pages/login/login.vue

@@ -72,7 +72,7 @@ export default {
 		this.theme = getApp().globalData.theme;
 		
 		//#ifdef APP-PLUS
-		  this.isAuthuserYs = plus.runtime.isAgreePrivacy()
+		  // this.isAuthuserYs = plus.runtime.isAgreePrivacy()
 		  uni.getSystemInfo({
 			  success:(res) => {
 				  console.log(res)