Commit 1ea3c773 by liangjianmin

js

parent 2fc34521
Showing with 297 additions and 103 deletions
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
import { API } from '@/util/api.js'; import { API } from '@/util/api.js';
import { getPlatform } from '@/util/util.js' import { getPlatform } from '@/util/util.js'
const ToBase64 = require('../../util/base64gb2312.js'); const ToBase64 = require('../../util/base64gb2312.js');
const cpclExp = require('../../util/cpcl-exp.js');
export default { export default {
data() { data() {
...@@ -57,6 +56,7 @@ ...@@ -57,6 +56,7 @@
sendData64: '', sendData64: '',
platform: 'android', platform: 'android',
printLabelData: [], printLabelData: [],
print_text: '总箱数',
form: { form: {
erp_order_sn_pre: '', erp_order_sn_pre: '',
print_type: 1, print_type: 1,
...@@ -132,7 +132,6 @@ ...@@ -132,7 +132,6 @@
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({
...@@ -240,8 +239,12 @@ ...@@ -240,8 +239,12 @@
var h = 0; //记录高度增量 var h = 0; //记录高度增量
data.push("! 10 200 200 " + (this.printLabelData.length * 250) + " 1\r\n"); data.push("! 10 200 200 " + (this.printLabelData.length * 250) + " 1\r\n");
for (let i = 0; i < this.printLabelData.length; i++) { 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 + 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"); if (this.form.print_type == 1) {
data.push("T 8 0 10 " + ((50 * (i + 2)) - (30 * 1) + h) + " 总箱数:" + this.printLabelData[0].label_num + "箱\r\n");
} else {
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 + 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("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("B QR 290 " + ((50 * (i + 1)) - (30 * 1) + h) + " M 2 U 8\r\n");
...@@ -341,9 +344,11 @@ ...@@ -341,9 +344,11 @@
if (index == 0) { if (index == 0) {
this.form.print_type = 1; this.form.print_type = 1;
this.text = '总箱数'; this.text = '总箱数';
this.print_text = '总箱数';
} else if (index == 1) { } else if (index == 1) {
this.text = '标签数量';
this.form.print_type = 2; this.form.print_type = 2;
this.text = '标签数量';
this.print_text = '箱号';
} }
} }
} }
......
...@@ -21,118 +21,307 @@ ...@@ -21,118 +21,307 @@
</template> </template>
<script> <script>
import { API } from '@/util/api.js'; import { API } from '@/util/api.js';
import { getPlatform } from '@/util/util.js'
const ToBase64 = require('../../util/base64gb2312.js');
export default { export default {
data() { data() {
return { return {
text: '标签数量', print_number: 0,
index_erp_order_sn_pre: -1, serviceId: '',
items_erp_order_sn_pre: ['A单号', 'B单号', 'D单号'], deviceId: '',
form: { characteristics: '',
erp_order_sn_pre: '', text: '标签数量',
erp_order_sn_number: '', index_erp_order_sn_pre: -1,
label_sort: '' items_erp_order_sn_pre: ['A单号', 'B单号', 'D单号'],
} sendData64: '',
}; platform: 'android',
}, printLabelData: [],
methods: { print_text: '总箱数',
onKeyInput: function(event) { print_type: 1,
if(event.target.value.length >3){ form: {
this.getErpOrderSnPrintLabelType(); erp_order_sn_pre: '',
} erp_order_sn_number: '',
}, label_sort: ''
getErpOrderSnPrintLabelType(){
this.request(API.getErpOrderSnPrintLabelType, 'POST', { erp_order_sn: this.form.erp_order_sn_pre + this.form.erp_order_sn_number}, false).then(res => {
if (res.err_code === 0) {
if(res.data == 1){
this.text='标签数量';
}else{
this.text='子箱号';
}
} }
}); };
}, },
submit() { methods: {
if (!this.form.erp_order_sn_pre) { onKeyInput: function(event) {
uni.showToast({ if (event.target.value.length > 3) {
icon: 'error', this.getErpOrderSnPrintLabelType();
title: '请选择订单类型' }
}); },
return false; getErpOrderSnPrintLabelType() {
} this.request(API.getErpOrderSnPrintLabelType, 'POST', { erp_order_sn: this.form.erp_order_sn_pre + this.form.erp_order_sn_number }, false).then(res => {
if (!this.form.erp_order_sn_number) { if (res.err_code === 0) {
uni.showToast({ if (res.data == 1) {
icon: 'error', this.text = '标签数量';
title: '请输入入仓号' this.print_type = 2;
}); } else {
return false; this.text = '子箱号';
} this.print_type = 1;
}
if (!/(^[0-9]*$)/.test(this.form.erp_order_sn_number)) { }
uni.showToast({
icon: 'error',
title: '入仓号为纯数字'
});
return false;
}
if (!this.form.label_sort) {
uni.showToast({
icon: 'error',
title: '请输入' + this.text
}); });
return false; },
} submit() {
if (!this.form.erp_order_sn_pre) {
uni.showToast({
icon: 'error',
title: '请选择订单类型'
});
return false;
}
if (!this.form.erp_order_sn_number) {
uni.showToast({
icon: 'error',
title: '请输入入仓号'
});
return false;
}
if (!/(^[0-9]*$)/.test(this.form.label_sort)) { if (!/(^[0-9]*$)/.test(this.form.erp_order_sn_number)) {
uni.showToast({ uni.showToast({
icon: 'error', icon: 'error',
title: this.text + '为纯数字' title: '入仓号为纯数字'
}); });
return false; return false;
} }
this.request(API.getPrintLabel, 'POST', { erp_order_sn: this.form.erp_order_sn_pre + this.form.erp_order_sn_number, label_sort: this.form.label_sort },true).then(res => { if (!this.form.label_sort) {
if (res.err_code === 0) { uni.showToast({
uni.showModal({ icon: 'error',
title: '提示', title: '请输入' + this.text
content: '提交成功,打印中,请查看标签打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
}); });
} else { return false;
}
if (!/(^[0-9]*$)/.test(this.form.label_sort)) {
uni.showToast({ uni.showToast({
title: res.err_msg, icon: 'error',
icon: 'error' title: this.text + '为纯数字'
}); });
return false;
} }
});
}, this.request(API.getPrintLabel, 'POST', { erp_order_sn: this.form.erp_order_sn_pre + this.form.erp_order_sn_number, label_sort: this.form.label_sort }, true).then(res => {
change(index, type) { if (res.err_code === 0) {
if (type == 'erp_order_sn_pre') { this.printLabelData = res.data;
//订单类型 this.sendDataChangeAll();
this.index_erp_order_sn_pre = index; this.openBluetoothAdapter();
if (index == 0) { } else {
this.form.erp_order_sn_pre = 'A'; uni.showToast({
} else if (index == 1) { title: res.err_msg,
this.form.erp_order_sn_pre = 'B'; icon: 'error'
} else if (index == 2) { });
this.form.erp_order_sn_pre = 'D'; }
});
},
openBluetoothAdapter() {
//先查看系统蓝牙状态
let that = this;
uni.openBluetoothAdapter({
success(res) {
that.startBluetoothDevicesDiscovery();
},
fail() {
uni.showToast({
title: '请打开蓝牙',
icon: 'error'
});
}
});
},
startBluetoothDevicesDiscovery() {
//搜索附近的蓝牙设备并且监听寻找到新设备的事件
let that = this;
uni.showLoading({
title: '连接设备中',
mask: true
});
uni.startBluetoothDevicesDiscovery({
success: function(res) {
console.log('搜索设备start', res);
uni.onBluetoothDeviceFound(function(el) {
//找到对应蓝牙设备名字
if (el.devices[0].name == 'HM-A300-87d9') {
that.deviceId = el.devices[0].deviceId; //成功后存储设备id
that.stopBluetoothDevicesDiscovery(); //关闭搜索
console.log("成功搜索设备", el);
console.log(el.devices[0].deviceId);
}
});
},
fail: function() {
uni.hideLoading();
uni.showToast({
title: '请断开蓝牙,重新连接',
icon: 'error'
});
}
});
},
stopBluetoothDevicesDiscovery() {
//成功找到对应蓝牙设备后 停止搜寻附近的蓝牙外围设备
let that = this;
uni.stopBluetoothDevicesDiscovery({
success(res) {
console.log('停止搜索', res);
that.getBLEDeviceServices();
}
});
},
getBLEDeviceServices() {
//来获取蓝牙设备所有服务
let that = this;
uni.createBLEConnection({
deviceId: this.deviceId,
success: res => {
console.log('连接成功', JSON.stringify(res));
//需延时连接,不然会报错
setTimeout(function() {
uni.getBLEDeviceServices({
deviceId: that.deviceId,
success: res => {
console.log('获取蓝牙设备所有服务', res);
that.serviceId = res.services[0].uuid;
that.getBLEDeviceCharacteristics();
}
});
}, 0);
}
});
},
getBLEDeviceCharacteristics() {
//获取蓝牙设备某个服务中所有特征值
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
that.characteristics = res.characteristics[0].uuid;
that.sendDataChangeAll();
console.log('服务功能特征值', res);
},
fail: res => {
console.log('失败', res);
}
});
},
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");
if (this.print_type == 1) {
data.push("T 8 0 10 " + ((50 * (i + 2)) - (30 * 1) + h) + " 总箱数:" + this.printLabelData[0].label_num + "箱\r\n");
} else {
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() {
console.log('第' + this.print_number + '次打印');
//发送数据 二进制
let data = "";
if (this.printLabelData.length > 0) {
data = "! 10 200 200 250 1\r\n" +
"T 8 0 10 10 入仓号:" + this.printLabelData[this.print_number].erp_order_sn + "\r\n" +
"T 8 0 10 50 箱号:" + this.printLabelData[this.print_number].label_sort + '/' + this.printLabelData[0].label_num + "\r\n" +
"T 8 0 10 90 时间:" + this.printLabelData[this.print_number].create_time_cn + "\r\n" +
"T 8 0 10 130 仓库代码:" + this.print_number + "\r\n" +
"B QR 290 0 M 2 U 8\r\n" +
"MA," + this.printLabelData[this.print_number].erp_order_sn + "\r\n" +
"ENDQR\r\n" +
"PRINT\r\n";
}
console.log(data)
let arrayBuffer = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data));
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
},
writeBLECharacteristicValue() {
//写入二进制数据
let that = this;
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.characteristics,
value: that.sendData64,
success(res) {
console.log('writeBLECharacteristicValue success', res.errMsg)
uni.hideLoading();
uni.closeBLEConnection({
deviceId: that.deviceId,
success(res) {
uni.showModal({
title: '提示',
content: '提交成功,打印中,请查看标签打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
})
},
fail() {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '无法打印,请查看标签打印机连接状态',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
})
},
change(index, type) {
if (type == 'erp_order_sn_pre') {
//订单类型
this.index_erp_order_sn_pre = index;
if (index == 0) {
this.form.erp_order_sn_pre = 'A';
} else if (index == 1) {
this.form.erp_order_sn_pre = 'B';
} else if (index == 2) {
this.form.erp_order_sn_pre = 'D';
}
} }
} }
} }
} };
};
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import '../../assets/css/tag/print.scss'; @import '../../assets/css/tag/print.scss';
</style> </style>
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