|
|
@@ -4,6 +4,10 @@ var util = require("@/pagesOrder/js/util.js");
|
|
|
import drawQrcode from "@/pagesOrder/js/weapp.qrcode.esm";
|
|
|
var toArrayBuffer = require('to-array-buffer');
|
|
|
|
|
|
+var PrinterJobs = require("@/pagesOrder/js/printerjobs.js");
|
|
|
+var printerUtil = require("@/pagesOrder/js/printerutil.js");
|
|
|
+
|
|
|
+
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -253,82 +257,141 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ _writeBLECharacteristicValue(data) {
|
|
|
+ uni.writeBLECharacteristicValue({
|
|
|
+ deviceId: data.deviceId,
|
|
|
+ serviceId: data.serviceId,
|
|
|
+ characteristicId: data.characteristicId,
|
|
|
+ value: data.buffer,
|
|
|
+ success(res) {
|
|
|
+ console.log('writeBLECharacteristicValue success', res)
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log('writeBLECharacteristicValue fail', res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
senBleLabel() {
|
|
|
let BleVal = this.BleVal;
|
|
|
let self = this;
|
|
|
console.log(BleVal,'BleValBleVal')
|
|
|
let currDev = uni.getStorageSync('BLE');
|
|
|
- //标签模式
|
|
|
let deviceId = currDev.deviceId;
|
|
|
let serviceId = currDev.services[0].serviceId;
|
|
|
let characteristicId = currDev.services[0].characteristicId;
|
|
|
|
|
|
- let arrPrint = [];
|
|
|
- //初始化打印机
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x40])); //16进制
|
|
|
- //正文
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
- //字体宽高加倍
|
|
|
- arrPrint.push(util.sendDirective([0x1d, 0x21, 0x11]));
|
|
|
- arrPrint.push(util.hexStringToBuff(BleVal.sendNum));
|
|
|
- //字体不放大,宽高不再加倍
|
|
|
- arrPrint.push(util.sendDirective([0x1d, 0x21, 0x00]));
|
|
|
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
- arrPrint.push(util.hexStringToBuff(" |纯彩花艺\n"));
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
+ let printerJobs = new PrinterJobs();
|
|
|
+ printerJobs
|
|
|
+ .print('2018年12月5日17:34')
|
|
|
+ .print(printerUtil.fillLine())
|
|
|
+ .setAlign('ct')
|
|
|
+ .setSize(2, 2)
|
|
|
+ .print('#20饿了么外卖')
|
|
|
+ .setSize(1, 1)
|
|
|
+ .print('切尔西Chelsea')
|
|
|
+ .setSize(2, 2)
|
|
|
+ .print('在线支付(已支付)')
|
|
|
+ .setSize(1, 1)
|
|
|
+ .print('订单号:5415221202244734')
|
|
|
+ .print('下单时间:2017-07-07 18:08:08')
|
|
|
+ .setAlign('lt')
|
|
|
+ .print(printerUtil.fillAround('一号口袋'))
|
|
|
+ .print(printerUtil.inline('意大利茄汁一面 * 1', '15'))
|
|
|
+ .print(printerUtil.fillAround('其他'))
|
|
|
+ .print('餐盒费:1')
|
|
|
+ .print('[赠送康师傅冰红茶] * 1')
|
|
|
+ .print(printerUtil.fillLine())
|
|
|
+ .setAlign('rt')
|
|
|
+ .print('原价:¥16')
|
|
|
+ .print('总价:¥16')
|
|
|
+ .setAlign('lt')
|
|
|
+ .print(printerUtil.fillLine())
|
|
|
+ .print('备注')
|
|
|
+ .print("无")
|
|
|
+ .print(printerUtil.fillLine())
|
|
|
+ .println();
|
|
|
+
|
|
|
+ let buffer = printerJobs.buffer();
|
|
|
|
|
|
- arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
+ // 1.并行调用多次会存在写失败的可能性
|
|
|
+ // 2.建议每次写入不超过20字节
|
|
|
+ // 分包处理,延时调用
|
|
|
+ const maxChunk = 20;
|
|
|
+ const delay = 20;
|
|
|
+ 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(this._writeBLECharacteristicValue, j * delay, {deviceId:deviceId, serviceId:serviceId, characteristicId:characteristicId,buffer:subPackage});
|
|
|
+ }
|
|
|
|
|
|
- //字体宽高加倍
|
|
|
- arrPrint.push(util.sendDirective([0x1d, 0x21, 0x11]));
|
|
|
+
|
|
|
+ // let arrPrint = [];
|
|
|
+ // //初始化打印机
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x40])); //16进制
|
|
|
+ // //正文
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
+ // //字体宽高加倍
|
|
|
+ // arrPrint.push(util.sendDirective([0x1d, 0x21, 0x11]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(BleVal.sendNum));
|
|
|
+ // //字体不放大,宽高不再加倍
|
|
|
+ // arrPrint.push(util.sendDirective([0x1d, 0x21, 0x00]));
|
|
|
|
|
|
- arrPrint.push(util.hexStringToBuff(BleVal.custom.fullAddress+ "\n"));
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
- arrPrint.push(util.hexStringToBuff(BleVal.custom.customName+"\n"+BleVal.custom.customMobile+ "\n"));
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(" |纯彩花艺\n"));
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
+
|
|
|
+ // arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
|
|
|
- //字体不放大,宽高不再加倍
|
|
|
- arrPrint.push(util.sendDirective([0x1d, 0x21, 0x00]));
|
|
|
+ // //字体宽高加倍
|
|
|
+ // arrPrint.push(util.sendDirective([0x1d, 0x21, 0x11]));
|
|
|
|
|
|
- if(BleVal.remark.length > 0){
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
- arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
- arrPrint.push(util.hexStringToBuff("备注:\n"));
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
- //字体宽高加倍
|
|
|
- arrPrint.push(util.sendDirective([0x1d, 0x21, 0x11]));
|
|
|
- arrPrint.push(util.hexStringToBuff(BleVal.remark+"\n"));
|
|
|
- //字体不放大,宽高不再加倍
|
|
|
- arrPrint.push(util.sendDirective([0x1d, 0x21, 0x00]));
|
|
|
- }
|
|
|
+ // arrPrint.push(util.hexStringToBuff(BleVal.custom.fullAddress+ "\n"));
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(BleVal.custom.customName+"\n"+BleVal.custom.customMobile+ "\n"));
|
|
|
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
- arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printThreeData('花材', '数量', '价格')));
|
|
|
- if(BleVal.product.length > 0){
|
|
|
- BleVal.product.forEach(function(currentItem){
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printThreeData(currentItem.name, currentItem.num, currentItem.price)))
|
|
|
- })
|
|
|
- }
|
|
|
- arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("运费:", BleVal.sendCost)));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("总金额:", BleVal.prePrice)));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("优惠:", BleVal.discountAmount)));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("应付金额:", BleVal.realPrice)));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("实付金额:", BleVal.debt == 1 ? '0.00' : BleVal.realPrice)));
|
|
|
- if(BleVal.debtAmount > 0){
|
|
|
- //加粗
|
|
|
- //arrPrint.push(util.sendDirective([0x1b, 0x45, 0x01]));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("累计欠款:", BleVal.debtAmount)));
|
|
|
- //取消加粗
|
|
|
- //arrPrint.push(util.sendDirective([0x1b, 0x45, 0x00]));
|
|
|
- }
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("订单日期:", BleVal.date)));
|
|
|
- arrPrint.push(util.hexStringToBuff(util.printTwoData("订单编号:", BleVal.orderSn)));
|
|
|
- arrPrint.push(util.sendDirective([0x1B, 0x61, 0x00]));
|
|
|
- arrPrint.push(util.hexStringToBuff("门店地址:"+BleVal.address+"\n"));
|
|
|
- arrPrint.push(util.hexStringToBuff("\n\n\n\n"));
|
|
|
+ // //字体不放大,宽高不再加倍
|
|
|
+ // arrPrint.push(util.sendDirective([0x1d, 0x21, 0x00]));
|
|
|
+
|
|
|
+ // if(BleVal.remark.length > 0){
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
+ // arrPrint.push(util.hexStringToBuff("备注:\n"));
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x0E]));
|
|
|
+ // //字体宽高加倍
|
|
|
+ // arrPrint.push(util.sendDirective([0x1d, 0x21, 0x11]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(BleVal.remark+"\n"));
|
|
|
+ // //字体不放大,宽高不再加倍
|
|
|
+ // arrPrint.push(util.sendDirective([0x1d, 0x21, 0x00]));
|
|
|
+ // }
|
|
|
+
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x14]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printThreeData('花材', '数量', '价格')));
|
|
|
+ // if(BleVal.product.length > 0){
|
|
|
+ // BleVal.product.forEach(function(currentItem){
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printThreeData(currentItem.name, currentItem.num, currentItem.price)))
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // arrPrint.push(util.hexStringToBuff("--------------------------------\n"));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("运费:", BleVal.sendCost)));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("总金额:", BleVal.prePrice)));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("优惠:", BleVal.discountAmount)));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("应付金额:", BleVal.realPrice)));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("实付金额:", BleVal.debt == 1 ? '0.00' : BleVal.realPrice)));
|
|
|
+ // if(BleVal.debtAmount > 0){
|
|
|
+ // //加粗
|
|
|
+ // //arrPrint.push(util.sendDirective([0x1b, 0x45, 0x01]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("累计欠款:", BleVal.debtAmount)));
|
|
|
+ // //取消加粗
|
|
|
+ // //arrPrint.push(util.sendDirective([0x1b, 0x45, 0x00]));
|
|
|
+ // }
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("订单日期:", BleVal.date)));
|
|
|
+ // arrPrint.push(util.hexStringToBuff(util.printTwoData("订单编号:", BleVal.orderSn)));
|
|
|
+ // arrPrint.push(util.sendDirective([0x1B, 0x61, 0x00]));
|
|
|
+ // arrPrint.push(util.hexStringToBuff("门店地址:"+BleVal.address+"\n"));
|
|
|
+ // arrPrint.push(util.hexStringToBuff("\n\n\n\n"));
|
|
|
|
|
|
// const ctx = uni.createCanvasContext('canvas');
|
|
|
// ctx.clearRect(0, 0, 130, 130);
|
|
|
@@ -369,20 +432,20 @@ export default {
|
|
|
// }
|
|
|
// });
|
|
|
|
|
|
- addPrintNum({id:self.orderId}).then(res=>{
|
|
|
- if(!self.$util.isEmpty(self.detailInfo)){
|
|
|
- self.detailInfo.printNum++;
|
|
|
- }
|
|
|
- if(!self.$util.isEmpty(self.list.data)){
|
|
|
- self.list.data.forEach(ele=>{
|
|
|
- if (ele.id==self.orderId) {
|
|
|
- ele.printNum++;
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ // addPrintNum({id:self.orderId}).then(res=>{
|
|
|
+ // if(!self.$util.isEmpty(self.detailInfo)){
|
|
|
+ // self.detailInfo.printNum++;
|
|
|
+ // }
|
|
|
+ // if(!self.$util.isEmpty(self.list.data)){
|
|
|
+ // self.list.data.forEach(ele=>{
|
|
|
+ // if (ele.id==self.orderId) {
|
|
|
+ // ele.printNum++;
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
|
|
|
- })
|
|
|
- this.printInfo({deviceId:deviceId, serviceId:serviceId, characteristicId:characteristicId}, arrPrint);
|
|
|
+ // })
|
|
|
+ // this.printInfo({deviceId:deviceId, serviceId:serviceId, characteristicId:characteristicId}, arrPrint);
|
|
|
|
|
|
},
|
|
|
|