|
|
|
@ -291,7 +291,8 @@ |
|
|
|
<script> |
|
|
|
import util from '@/components/kk-printer/utils/util.js'; |
|
|
|
import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js'; |
|
|
|
import kkPrinter from '@/components/kk-printer/index.vue'; |
|
|
|
import kkPrinter from '@/components/kk-printer/index.vue'; |
|
|
|
import gbk from '@/components/kk-printer/utils/printUtil-GBK.js'; |
|
|
|
import { |
|
|
|
maskShopName, |
|
|
|
maskPhone |
|
|
|
@ -336,7 +337,8 @@ |
|
|
|
sAmout: 0, |
|
|
|
yNum: 150, |
|
|
|
printTotal: 1040, |
|
|
|
zReturnNum: "" |
|
|
|
zReturnNum: "", |
|
|
|
deviceType: 'ios' |
|
|
|
} |
|
|
|
}, |
|
|
|
components: { |
|
|
|
@ -395,7 +397,8 @@ |
|
|
|
this.lbgName = JSON.parse(JSON.stringify(this.lbgName)) |
|
|
|
this.type = uni.getStorageSync('type') |
|
|
|
}, |
|
|
|
onLoad(option) { |
|
|
|
onLoad(option) { |
|
|
|
var that = this; |
|
|
|
this.saleId = option.id |
|
|
|
if (option.id != null && option.id != undefined && option.id != "") { |
|
|
|
if (option.type == 'gys') { |
|
|
|
@ -442,7 +445,13 @@ |
|
|
|
} |
|
|
|
}).catch((res) => {}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
uni.getSystemInfo({ |
|
|
|
success(res) { |
|
|
|
that.deviceType = res.osName |
|
|
|
console.log('设备类型', res.osName) |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
deleteOrder() { |
|
|
|
@ -635,50 +644,132 @@ |
|
|
|
uni.hideLoading(); |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
goPrint(type){ |
|
|
|
let strCmd = '' |
|
|
|
strCmd = blesdk.CreatCPCLPage(600, 1040, 1, 1); |
|
|
|
strCmd += blesdk.addCPCLSETMAG(2, 2) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('40', '30', '24', '0', 0, '沧州明珠商贸城--快衣店') |
|
|
|
strCmd += blesdk.addCPCLSETMAG(3, 3) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('50', '120', '24', '0', 0, '收:' + maskShopName(this.sales.userName)) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(1, 1) |
|
|
|
strCmd += blesdk.addCPCLText('50', '250', '24', '0', 0, maskPhone(this.order.phone)) |
|
|
|
strCmd += blesdk.addCPCLText('250', '250', '24', '0', 0, '编号:' + this.sales.id) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(1, 1) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('50', '330', '24', '0', 0, this.sales.province + '/' + this.sales.city + '/' + |
|
|
|
this.sales.area) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(1, 1) |
|
|
|
if(type == 'confirm'){ |
|
|
|
strCmd += blesdk.addCPCLText('50', '410', '24', '0', 0, "*****") |
|
|
|
}else{ |
|
|
|
if (this.sales.receiveAddress.length > 20) { |
|
|
|
let position = 20; |
|
|
|
let part1 = this.sales.receiveAddress.substring(0, position); |
|
|
|
let part2 = this.sales.receiveAddress.substring(position); |
|
|
|
strCmd += blesdk.addCPCLText('50', '410', '24', '0', 0, part1) |
|
|
|
strCmd += blesdk.addCPCLText('50', '440', '24', '0', 0, part2) |
|
|
|
} else { |
|
|
|
strCmd += blesdk.addCPCLText('50', '410', '24', '0', 0, this.sales.receiveAddress) |
|
|
|
} |
|
|
|
} |
|
|
|
strCmd += blesdk.addCPCLSETMAG(2, 2) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('0', '490', '24', '0', 0, '——————————————————————————————') |
|
|
|
strCmd += blesdk.addCPCLText('50', '570', '24', '0', 0, '发货方式:' + (this.sales.companyName ? this.sales |
|
|
|
.companyName : '暂无')) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(2, 2) |
|
|
|
strCmd += blesdk.addCPCLText('0', '650', '24', '0', 0, '——————————————————————————————') |
|
|
|
strCmd += blesdk.addCPCLText('50', '730', '24', '0', 0, '店铺:' + maskShopName(this.sales.shopName)) |
|
|
|
strCmd += blesdk.addCPCLText('50', '810', '24', '0', 0, maskPhone(this.sales.createByPhone)) |
|
|
|
strCmd += blesdk.addCPCLText('50', '890', '24', '0', 0, '地址:' + this.shopData.shopAddress) |
|
|
|
strCmd += blesdk.addCPCLLocation(0); |
|
|
|
strCmd += blesdk.addCPCLPrint(); |
|
|
|
this.bufferData.push(strCmd); |
|
|
|
this.xierushuju(this.bufferData) |
|
|
|
this.$nextTick(() => { |
|
|
|
this.bufferData = [] |
|
|
|
uni.hideLoading(); |
|
|
|
}) |
|
|
|
}, |
|
|
|
xierushuju() { |
|
|
|
let that = this; |
|
|
|
//写入数据 |
|
|
|
if (this.defaultText == '打印小票') { |
|
|
|
that.$emit('onPrintSmall'); |
|
|
|
} else if (this.defaultText == '确认打印') { |
|
|
|
that.$emit('goPrint'); |
|
|
|
} else { |
|
|
|
that.$emit('onPrint'); |
|
|
|
} |
|
|
|
console.log('查看数据是否正确', that.bufferData) |
|
|
|
that.$nextTick(() => { |
|
|
|
var dataStr = '' |
|
|
|
for (let m = 0; m < that.bufferData.length; m++) { |
|
|
|
dataStr += that.bufferData[m] |
|
|
|
} |
|
|
|
const maxChunk = that.deviceType == 'android' ? 20 : 180; |
|
|
|
const delay = that.deviceType == 'android' ? 20 : 180; |
|
|
|
|
|
|
|
let buffer = gbk.strToGBKByte(dataStr) |
|
|
|
for (let i = 0, j = 0, length = buffer.byteLength; i < length; i += maxChunk, j++) { |
|
|
|
let subPackage = buffer.slice(i, i + maxChunk <= length ? (i + maxChunk) : length); |
|
|
|
setTimeout(that._writeBLECharacteristicValue, j * delay, subPackage); |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
return; |
|
|
|
}, |
|
|
|
_writeBLECharacteristicValue(buffer) { |
|
|
|
let that = this; |
|
|
|
wx.writeBLECharacteristicValue({ |
|
|
|
deviceId: uni.getStorageSync('deviceId'), |
|
|
|
serviceId: uni.getStorageSync('serviceId'), |
|
|
|
characteristicId: uni.getStorageSync('characteristicId'), |
|
|
|
value: buffer, |
|
|
|
success(res) { |
|
|
|
console.log('打印buffer', buffer) |
|
|
|
console.log('writeBLECharacteristicValue success', res) |
|
|
|
}, |
|
|
|
fail(res) { |
|
|
|
console.log('writeBLECharacteristicValue fail', res) |
|
|
|
wx.closeBLEConnection({ |
|
|
|
deviceId: uni.getStorageSync('deviceId'), |
|
|
|
success(res) { |
|
|
|
console.log(res) |
|
|
|
} |
|
|
|
}) |
|
|
|
if (uni.getStorageSync('deviceId')) { |
|
|
|
console.log("111") |
|
|
|
that.xierushuju() |
|
|
|
} else { |
|
|
|
that.jiantingshebei() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
uni.hideLoading(); |
|
|
|
}, |
|
|
|
//打印贴包单 |
|
|
|
onPrint(opt) { |
|
|
|
let strCmd = '' |
|
|
|
strCmd = blesdk.CreatCPCLPage(600, 1040, 1, 1); |
|
|
|
strCmd += blesdk.addCPCLSETMAG(2, 2) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('40', '30', '24', '0', 0, '沧州明珠商贸城--快衣店') |
|
|
|
strCmd += blesdk.addCPCLSETMAG(3, 3) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('50', '120', '24', '0', 0, '收:' + maskShopName(this.sales.userName)) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(1, 1) |
|
|
|
strCmd += blesdk.addCPCLText('50', '250', '24', '0', 0, maskPhone(this.order.phone)) |
|
|
|
strCmd += blesdk.addCPCLText('250', '250', '24', '0', 0, '编号:' + this.sales.id) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(1, 1) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('50', '330', '24', '0', 0, this.sales.province + '/' + this.sales.city + '/' + |
|
|
|
this.sales.area) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(1, 1) |
|
|
|
if (this.sales.receiveAddress.length > 20) { |
|
|
|
let position = 20; |
|
|
|
let part1 = this.sales.receiveAddress.substring(0, position); |
|
|
|
let part2 = this.sales.receiveAddress.substring(position); |
|
|
|
strCmd += blesdk.addCPCLText('50', '410', '24', '0', 0, part1) |
|
|
|
strCmd += blesdk.addCPCLText('50', '440', '24', '0', 0, part2) |
|
|
|
} else { |
|
|
|
strCmd += blesdk.addCPCLText('50', '410', '24', '0', 0, this.sales.receiveAddress) |
|
|
|
} |
|
|
|
strCmd += blesdk.addCPCLSETMAG(2, 2) |
|
|
|
blesdk.addCPCLSETBOLD('bold') |
|
|
|
strCmd += blesdk.addCPCLText('0', '490', '24', '0', 0, '——————————————————————————————') |
|
|
|
strCmd += blesdk.addCPCLText('50', '570', '24', '0', 0, '发货方式:' + (this.sales.companyName ? this.sales |
|
|
|
.companyName : '暂无')) |
|
|
|
strCmd += blesdk.addCPCLSETMAG(2, 2) |
|
|
|
strCmd += blesdk.addCPCLText('0', '650', '24', '0', 0, '——————————————————————————————') |
|
|
|
strCmd += blesdk.addCPCLText('50', '730', '24', '0', 0, '店铺:' + maskShopName(this.sales.shopName)) |
|
|
|
strCmd += blesdk.addCPCLText('50', '810', '24', '0', 0, maskPhone(this.sales.createByPhone)) |
|
|
|
strCmd += blesdk.addCPCLText('50', '890', '24', '0', 0, '地址:' + this.shopData.shopAddress) |
|
|
|
strCmd += blesdk.addCPCLLocation(0); |
|
|
|
strCmd += blesdk.addCPCLPrint(); |
|
|
|
this.bufferData.push(strCmd); |
|
|
|
this.$nextTick(() => { |
|
|
|
this.bufferData = [] |
|
|
|
uni.hideLoading(); |
|
|
|
onPrint(opt) { |
|
|
|
let that = this; |
|
|
|
uni.showModal({ |
|
|
|
title: "提示", |
|
|
|
content: "要隐藏客户信息吗?", |
|
|
|
cancelText:'不隐藏', |
|
|
|
confirmText:'隐藏', |
|
|
|
|
|
|
|
success: function(res) { |
|
|
|
if (res.confirm) { |
|
|
|
console.log('用户点击确定'); |
|
|
|
that.goPrint('confirm'); |
|
|
|
} |
|
|
|
if(res.cancel){ |
|
|
|
console.log('用户点击取消'); |
|
|
|
that.goPrint('cancel'); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
//计算打印机当前行高度 |
|
|
|
|