Commit 2fc34521 by liangjianmin

js

parent ef311d5b
Showing with 43 additions and 33 deletions
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
this.request(API.printLabel, 'POST', this.form, false).then(res => { this.request(API.printLabel, 'POST', this.form, false).then(res => {
if (res.err_code === 0) { if (res.err_code === 0) {
this.printLabelData = res.data; this.printLabelData = res.data;
this.sendDataChangeAll();
this.openBluetoothAdapter(); this.openBluetoothAdapter();
} else { } else {
uni.showToast({ uni.showToast({
...@@ -224,7 +225,7 @@ ...@@ -224,7 +225,7 @@
serviceId: that.serviceId, serviceId: that.serviceId,
success: res => { success: res => {
that.characteristics = res.characteristics[0].uuid; that.characteristics = res.characteristics[0].uuid;
that.sendDataChange(); that.sendDataChangeAll();
console.log('服务功能特征值', res); console.log('服务功能特征值', res);
}, },
fail: res => { fail: res => {
...@@ -232,6 +233,28 @@ ...@@ -232,6 +233,28 @@
} }
}); });
}, },
sendDataChangeAll() {
console.log('第' + this.print_number + '次打印');
//发送数据 二进制
let data = [];
var h = 0; //记录高度增量
data.push("! 10 200 200 " + (this.printLabelData.length * 250) + " 1\r\n");
for (let i = 0; i < this.printLabelData.length; i++) {
data.push("T 8 0 10 " + ((50 * (i + 1)) - (30 * 1) + h) + " 入仓号:" + this.printLabelData[i].erp_order_sn + "\r\n")
data.push("T 8 0 10 " + ((50 * (i + 2)) - (30 * 1) + h) + " 箱号:" + this.printLabelData[i].label_sort + '/' + this.printLabelData[0].label_num + "\r\n");
data.push("T 8 0 10 " + ((50 * (i + 3)) - (30 * 1) + h) + " 时间:" + this.printLabelData[i].create_time_cn + "\r\n");
data.push("T 8 0 10 " + ((50 * (i + 4)) - (30 * 1) + h) + " 仓库代码:" + i + "\r\n");
data.push("B QR 290 " + ((50 * (i + 1)) - (30 * 1) + h) + " M 2 U 8\r\n");
data.push("MA," + this.printLabelData[i].erp_order_sn + "\r\n");
data.push("ENDQR\r\n");
h += 210;
}
data.push("PRINT\r\n");
let arrayBuffer = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data.join('')));
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
console.log(data.join(''))
},
sendDataChange() { sendDataChange() {
console.log('第' + this.print_number + '次打印'); console.log('第' + this.print_number + '次打印');
//发送数据 二进制 //发送数据 二进制
...@@ -262,39 +285,26 @@ ...@@ -262,39 +285,26 @@
value: that.sendData64, value: that.sendData64,
success(res) { success(res) {
console.log('writeBLECharacteristicValue success', res.errMsg) console.log('writeBLECharacteristicValue success', res.errMsg)
that.print_number++; uni.hideLoading();
if (that.print_number < that.printLabelData.length) { uni.closeBLEConnection({
uni.closeBLEConnection({ deviceId: that.deviceId,
deviceId: that.deviceId, success(res) {
success(res) { uni.showModal({
console.log(res) title: '提示',
setTimeout(function() { content: '提交成功,打印中,请查看标签打印机',
that.openBluetoothAdapter(); showCancel: false,
}, 0); confirmText: '关闭',
} success: function(res) {
}) if (res.confirm) {
} else { console.log('用户点击确定');
uni.hideLoading();
uni.showModal({ } else if (res.cancel) {
title: '提示', console.log('用户点击取消');
content: '提交成功,打印中,请查看标签打印机', }
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
uni.closeBLEConnection({
deviceId: that.deviceId,
success(res) {
console.log(res)
}
})
} else if (res.cancel) {
console.log('用户点击取消');
} }
} });
}); }
} })
}, },
fail() { fail() {
uni.hideLoading(); uni.hideLoading();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment