|
@@ -46,73 +46,128 @@
|
|
_this.infoData = options.data ? JSON.parse(options.data) : {},
|
|
_this.infoData = options.data ? JSON.parse(options.data) : {},
|
|
_this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
|
|
_this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
|
|
console.log(_this.infoData)
|
|
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() {
|
|
onUnload() {
|
|
- this.$refs.kkprinter.closeConnect()
|
|
|
|
|
|
+ // this.$refs.kkprinter.closeConnect()
|
|
|
|
+ this.printNum = 0
|
|
|
|
+ this.infoData = null
|
|
|
|
+ this.printInfo = null
|
|
|
|
+ this.fromPage = ''
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
cansel(){
|
|
cansel(){
|
|
uni.$emit('refreshBL')
|
|
uni.$emit('refreshBL')
|
|
uni.navigateBack()
|
|
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){
|
|
startPrint(opt,tsc,blesdk){
|
|
console.log(opt,'opt')
|
|
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点像素
|
|
let top = 10 // 距离顶部10点像素
|
|
- const left = 10 // 距离左边10点
|
|
|
|
|
|
+ const left = 24 // 距离左边
|
|
const lightHeight = 24 // 行高3mm,1mm = 8点
|
|
const lightHeight = 24 // 行高3mm,1mm = 8点
|
|
const pageW = 40 // 页签宽度mm
|
|
const pageW = 40 // 页签宽度mm
|
|
const pageH = 30 // 页签高度mm
|
|
const pageH = 30 // 页签高度mm
|
|
const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
|
|
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()
|
|
const command = tsc.jpPrinter.createNew()
|
|
command.init()
|
|
command.init()
|
|
@@ -120,20 +175,25 @@
|
|
command.setGap(2) // 标签上下间距,单位mm
|
|
command.setGap(2) // 标签上下间距,单位mm
|
|
command.setCls() // 清除缓冲区数据
|
|
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())
|
|
console.log("开始打印了",command.getData())
|
|
blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
|
|
blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
|
|
},
|
|
},
|
|
@@ -190,9 +250,9 @@
|
|
.pno{
|
|
.pno{
|
|
background: rgba(3, 54, 146, 0.15);
|
|
background: rgba(3, 54, 146, 0.15);
|
|
border-radius: 100rpx;
|
|
border-radius: 100rpx;
|
|
- padding: 6rpx 20rpx;
|
|
|
|
|
|
+ padding: 4rpx 20rpx;
|
|
color: #033692;
|
|
color: #033692;
|
|
- font-size: 24rpx;
|
|
|
|
|
|
+ font-size: 26rpx;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|