Commit e750f4ab by LJM

标签打印

parent 1e28a8b1
......@@ -342,10 +342,26 @@
is_add: 0
});
this.request(API.checkRepeatPrintLabel, 'POST', params, true).then(res => {
this.request(API.checkIsTallyGoods, 'POST', params, true).then(res => {
if (res.err_code === 0) {
this.printLabelChange();
this.request(API.checkRepeatPrintLabel, 'POST', params, true).then(res => {
if (res.err_code === 0) {
this.printLabelChange();
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
confirmText: '继续打印',
success: res => {
if (res.confirm) {
this.printLabelChange();
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
});
} else {
uni.showModal({
title: '提示',
......@@ -353,7 +369,24 @@
confirmText: '继续打印',
success: res => {
if (res.confirm) {
this.printLabelChange();
this.request(API.checkRepeatPrintLabel, 'POST', params, true).then(res => {
if (res.err_code === 0) {
this.printLabelChange();
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
confirmText: '继续打印',
success: res => {
if (res.confirm) {
this.printLabelChange();
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
});
} else if (res.cancel) {
console.log('用户点击取消');
}
......@@ -361,6 +394,7 @@
});
}
});
},
printLabelChange() {
this.request(API.printLabel, 'POST', this.form, true).then(res => {
......
......@@ -53,315 +53,344 @@
</template>
<script>
import { API } from '@/util/api.js';
import { getPlatform } from '@/util/util.js';
const ToBase64 = require('../../util/base64gb2312.js');
import { API } from '@/util/api.js';
import { getPlatform } from '@/util/util.js';
const ToBase64 = require('../../util/base64gb2312.js');
export default {
data() {
return {
print_number: 0,
serviceId: '',
deviceId: '',
device_name: '',
characteristics: '',
text: '标签数量',
index_erp_order_sn_pre: -1,
index_print_type: 1,
items_erp_order_sn_pre: ['A单号', 'B单号', 'D单号'],
items_print_type: ['卡板', '散箱'],
sendData64: '',
platform: 'android',
printLabelData: [],
wstyptll_id: '',
batchArr: [0, 1, 2, 3, 4, 5, 6],
form: {
batch: 0, //批次
is_add: 1,
print_type: 2,
erp_order_sn_pre: '',
erp_order_sn_number: '',
erp_order_sn: '', //入仓号
label_num: ''
}
};
},
onLoad(option) {
this.platform = getPlatform();
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
console.log('停止搜索', JSON.stringify(res.errMsg));
}
});
try {
uni.removeStorageSync('device');
} catch (e) {
// error
}
},
onShow() {
//获取已连接蓝牙设备信息
const deviceData = uni.getStorageSync('device') || '';
if (deviceData) {
this.deviceId = deviceData.deviceId;
this.serviceId = deviceData.serviceId;
this.characteristics = deviceData.characteristics;
this.device_name = deviceData.name;
} else {
this.deviceId = '';
this.device_name = '';
}
},
methods: {
bindPickerChangeBatch(e) {
this.form.batch = e.target.value;
},
scanChange() {
uni.scanCode({
success: res => {
if (res.errMsg == 'scanCode:ok') {
this.form.erp_order_sn = res.result;
}
},
fail: function(res) {
uni.showToast({
title: '扫码失败',
icon: 'error'
});
export default {
data() {
return {
print_number: 0,
serviceId: '',
deviceId: '',
device_name: '',
characteristics: '',
text: '标签数量',
index_erp_order_sn_pre: -1,
index_print_type: 1,
items_erp_order_sn_pre: ['A单号', 'B单号', 'D单号'],
items_print_type: ['卡板', '散箱'],
sendData64: '',
platform: 'android',
printLabelData: [],
wstyptll_id: '',
batchArr: [0, 1, 2, 3, 4, 5, 6],
form: {
batch: 0, //批次
is_add: 1,
print_type: 2,
erp_order_sn_pre: '',
erp_order_sn_number: '',
erp_order_sn: '', //入仓号
label_num: ''
}
});
};
},
submit() {
if (!this.device_name) {
uni.showModal({
title: '提示',
content: '请连接蓝牙设备',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
uni.navigateTo({
url: '/pages/tag/deviceList'
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
return false;
}
if (!this.form.erp_order_sn) {
uni.showModal({
title: '提示',
content: '请输入入仓号',
showCancel: false
});
return false;
}
if (!this.form.label_num) {
uni.showModal({
title: '提示',
content: '请输入' + this.text,
showCancel: false
});
return false;
}
if (!/(^[0-9]*$)/.test(this.form.label_num)) {
uni.showModal({
title: '提示',
content: this.text + '为纯数字',
showCancel: false
});
return false;
}
onLoad(option) {
this.platform = getPlatform();
this.request(API.printLabel, 'POST', { erp_order_sn: this.form.erp_order_sn, batch: this.form.batch, label_num: this.form.label_num, is_add: 1, print_type: this.form.print_type }, true).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
this.wstyptll_id = res.data[0].wstyptll_id;
this.sendDataChange(); //发送数据
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
});
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
console.log('停止搜索', JSON.stringify(res.errMsg));
}
});
},
/**
* 向蓝牙发送数据
*/
sendDataChange() {
try {
uni.showLoading({
title: '打印中...'
});
console.log('第' + this.print_number + '次开始打印start...');
let data = [];
if (this.printLabelData.length > 0) {
data.push('! 60 200 200 300 1\r\n');
data.push('SETMAG 3 4\r\n');
data.push('T 7 0 10 20 ' + this.printLabelData[this.print_number].erp_order_sn + '\r\n');
data.push('SETMAG 0 0\r\n');
if (this.print_type == 1) {
data.push('T 5 0 10 120 总箱数:' + this.printLabelData[this.print_number].label_num + '箱\r\n');
} else {
data.push('T 5 0 10 120 箱号:' + this.printLabelData[this.print_number].label_sort + '/' + this.printLabelData[this.print_number].label_num + '\r\n');
}
data.push('T 8 0 10 180 时间:' + this.printLabelData[this.print_number].create_time_cn + '\r\n');
data.push('T 8 0 10 220 仓库代码:' + this.printLabelData[this.print_number].warehouse_code + '\r\n');
data.push('T 8 0 10 260 流水号:' + this.printLabelData[this.print_number].wstyptll_id_sn + '\r\n');
data.push('SETMAG 4 1' + '\r\n');
data.push('T 8 0 350 30 ' + this.printLabelData[this.print_number].batch + '\r\n');
data.push('SETMAG 0 0' + '\r\n');
data.push('B QR 260 120 M 2 U 8\r\n');
data.push('MA,' + this.printLabelData[this.print_number]['box_code'] + '|\r\n');
data.push('ENDQR\r\n');
data.push('FORM\r\n');
data.push('PRINT\r\n');
}
console.log(data.join(''));
this.cutCommand(data.join(''));
uni.removeStorageSync('device');
} catch (e) {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '数据异常,请重试',
showCancel: false,
confirmText: '关闭'
});
// error
}
},
/**
* 分批传输数据
*/
cutCommand: function(data) {
var packageLength = 10; //安卓不超过10个字节传输
var sendData64 = [];
if (this.platform == 'ios') {
packageLength = 30;
}
console.log('package长度:' + packageLength);
for (let i = 0; i < Math.ceil(data.length / packageLength); i++) {
sendData64[i] = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data.substr(i * packageLength, packageLength)));
onShow() {
//获取已连接蓝牙设备信息
const deviceData = uni.getStorageSync('device') || '';
if (deviceData) {
this.deviceId = deviceData.deviceId;
this.serviceId = deviceData.serviceId;
this.characteristics = deviceData.characteristics;
this.device_name = deviceData.name;
} else {
this.deviceId = '';
this.device_name = '';
}
this.sendData64 = sendData64;
console.log(sendData64);
this.writeBLECharacteristicValue(1);
},
/**
* 写入二进制数据
*/
writeBLECharacteristicValue(times) {
var sendData64 = this.sendData64;
if (sendData64.length >= times) {
uni.writeBLECharacteristicValue({
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: sendData64[times - 1],
methods: {
bindPickerChangeBatch(e) {
this.form.batch = e.target.value;
},
scanChange() {
uni.scanCode({
success: res => {
this.writeBLECharacteristicValue(++times);
if (res.errMsg == 'scanCode:ok') {
this.form.erp_order_sn = res.result;
}
},
fail() {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '打印失败,请重新进入打印页面',
showCancel: false,
confirmText: '关闭',
success: res => {
if (res.confirm) {
this.characteristics = ''; //连接蓝牙信息清空
this.deviceId = ''; //连接蓝牙信息清空
this.device_name = ''; //连接蓝牙信息清空
this.print_number = 0; //打印计数归零
this.printLabelData = []; //打印数据清空
this.sendData64 = ''; //发送蓝牙数据清空
this.delErpOrderSnCodeManage(); //及时作废
} else if (res.cancel) {
console.log('用户点击取消');
}
}
fail: function(res) {
uni.showToast({
title: '扫码失败',
icon: 'error'
});
}
});
} else {
this.print_number++;
console.log('第' + this.print_number + '次传输完成end');
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
uni.hideLoading();
//重置
this.print_number = 0; //打印计数归零
this.printLabelData = []; //打印数据清空
this.sendData64 = ''; //发送蓝牙数据清空
},
submit() {
if (!this.device_name) {
uni.showModal({
title: '提示',
content: '打印成功,请查看标签打印机',
content: '请连接蓝牙设备',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
uni.navigateTo({
url: '/pages/tag/deviceList'
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
return false;
}
}
},
delErpOrderSnCodeManage() {
this.request(API.delWstyptllIdErpOrderSnCodeManage, 'POST', { wstyptll_id: this.wstyptll_id }, true).then(res => {
if (res.err_code === 0) {
} else {
if (!this.form.erp_order_sn) {
uni.showModal({
title: '提示',
content: res.err_msg,
content: '请输入入仓号',
showCancel: false
});
return false;
}
if (!this.form.label_num) {
uni.showModal({
title: '提示',
content: '请输入' + this.text,
showCancel: false
});
return false;
}
if (!/(^[0-9]*$)/.test(this.form.label_num)) {
uni.showModal({
title: '提示',
content: this.text + '为纯数字',
showCancel: false
});
return false;
}
this.request(API.checkIsTallyGoods, 'POST', { erp_order_sn: this.form.erp_order_sn, batch: this.form.batch }, true).then(res => {
if (res.err_code === 0) {
this.request(API.printLabel, 'POST', { erp_order_sn: this.form.erp_order_sn, batch: this.form.batch, label_num: this.form.label_num, is_add: 1, print_type: this.form.print_type }, true).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
this.wstyptll_id = res.data[0].wstyptll_id;
this.sendDataChange(); //发送数据
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
});
}
});
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
confirmText: '继续打印',
success: res => {
if (res.confirm) {
this.request(API.printLabel, 'POST', { erp_order_sn: this.form.erp_order_sn, batch: this.form.batch, label_num: this.form.label_num, is_add: 1, print_type: this.form.print_type }, true).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
this.wstyptll_id = res.data[0].wstyptll_id;
this.sendDataChange(); //发送数据
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
});
}
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
});
},
/**
* 向蓝牙发送数据
*/
sendDataChange() {
try {
uni.showLoading({
title: '打印中...'
});
console.log('第' + this.print_number + '次开始打印start...');
let data = [];
if (this.printLabelData.length > 0) {
data.push('! 60 200 200 300 1\r\n');
data.push('SETMAG 3 4\r\n');
data.push('T 7 0 10 20 ' + this.printLabelData[this.print_number].erp_order_sn + '\r\n');
data.push('SETMAG 0 0\r\n');
if (this.print_type == 1) {
data.push('T 5 0 10 120 总箱数:' + this.printLabelData[this.print_number].label_num + '箱\r\n');
} else {
data.push('T 5 0 10 120 箱号:' + this.printLabelData[this.print_number].label_sort + '/' + this.printLabelData[this.print_number].label_num + '\r\n');
}
data.push('T 8 0 10 180 时间:' + this.printLabelData[this.print_number].create_time_cn + '\r\n');
data.push('T 8 0 10 220 仓库代码:' + this.printLabelData[this.print_number].warehouse_code + '\r\n');
data.push('T 8 0 10 260 流水号:' + this.printLabelData[this.print_number].wstyptll_id_sn + '\r\n');
data.push('SETMAG 4 1' + '\r\n');
data.push('T 8 0 350 30 ' + this.printLabelData[this.print_number].batch + '\r\n');
data.push('SETMAG 0 0' + '\r\n');
data.push('B QR 260 120 M 2 U 8\r\n');
data.push('MA,' + this.printLabelData[this.print_number]['box_code'] + '|\r\n');
data.push('ENDQR\r\n');
data.push('FORM\r\n');
data.push('PRINT\r\n');
}
console.log(data.join(''));
this.cutCommand(data.join(''));
} catch (e) {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '数据异常,请重试',
showCancel: false,
confirmText: '关闭'
});
}
});
},
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';
},
/**
* 分批传输数据
*/
cutCommand: function(data) {
var packageLength = 10; //安卓不超过10个字节传输
var sendData64 = [];
if (this.platform == 'ios') {
packageLength = 30;
}
console.log('package长度:' + packageLength);
for (let i = 0; i < Math.ceil(data.length / packageLength); i++) {
sendData64[i] = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data.substr(i * packageLength, packageLength)));
}
} else if (type == 'print_type') {
//打印类型
this.index_print_type = index;
if (index == 0) {
this.form.print_type = 1;
this.text = '总箱数';
} else if (index == 1) {
this.form.print_type = 2;
this.text = '标签数量';
this.sendData64 = sendData64;
console.log(sendData64);
this.writeBLECharacteristicValue(1);
},
/**
* 写入二进制数据
*/
writeBLECharacteristicValue(times) {
var sendData64 = this.sendData64;
if (sendData64.length >= times) {
uni.writeBLECharacteristicValue({
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: sendData64[times - 1],
success: res => {
this.writeBLECharacteristicValue(++times);
},
fail() {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '打印失败,请重新进入打印页面',
showCancel: false,
confirmText: '关闭',
success: res => {
if (res.confirm) {
this.characteristics = ''; //连接蓝牙信息清空
this.deviceId = ''; //连接蓝牙信息清空
this.device_name = ''; //连接蓝牙信息清空
this.print_number = 0; //打印计数归零
this.printLabelData = []; //打印数据清空
this.sendData64 = ''; //发送蓝牙数据清空
this.delErpOrderSnCodeManage(); //及时作废
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
});
} else {
this.print_number++;
console.log('第' + this.print_number + '次传输完成end');
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
uni.hideLoading();
//重置
this.print_number = 0; //打印计数归零
this.printLabelData = []; //打印数据清空
this.sendData64 = ''; //发送蓝牙数据清空
uni.showModal({
title: '提示',
content: '打印成功,请查看标签打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
}
},
delErpOrderSnCodeManage() {
this.request(API.delWstyptllIdErpOrderSnCodeManage, 'POST', { wstyptll_id: this.wstyptll_id }, true).then(res => {
if (res.err_code === 0) {} else {
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
});
}
});
},
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';
}
} else if (type == 'print_type') {
//打印类型
this.index_print_type = index;
if (index == 0) {
this.form.print_type = 1;
this.text = '总箱数';
} else if (index == 1) {
this.form.print_type = 2;
this.text = '标签数量';
}
}
}
}
}
};
};
</script>
<style scoped lang="scss">
@import '../../assets/css/tag/print.scss';
</style>
@import '../../assets/css/tag/print.scss';
</style>
\ No newline at end of file
const API_BASE = 'https://api.ichunt.com';
const API_BASE_OSS = 'https://image.ichunt.net'; //oss系统
const API_BASE_WMS = 'https://wms.ichunt.net'; //WMS系统
// const API_BASE = 'https://api.ichunt.com';
// const API_BASE_OSS = 'https://image.ichunt.net'; //oss系统
// const API_BASE_WMS = 'https://wms.ichunt.net'; //WMS系统
// const API_BASE = 'http://api.liexin.com';
// const API_BASE_OSS = 'http://image.liexindev.net';
// const API_BASE_WMS = 'http://wms.liexindev.net'; //WMS系统
const API_BASE = 'http://api.liexin.com';
const API_BASE_OSS = 'http://image.liexindev.net';
const API_BASE_WMS = 'http://wms.liexindev.net'; //WMS系统
const API = {
/**
......@@ -132,6 +132,10 @@ const API = {
*/
checkRepeatPrintLabel: API_BASE + '/supplywechatwms/checkRepeatPrintLabel',
/**
* 入仓号是否理货
*/
checkIsTallyGoods: API_BASE + '/supplywechatwms/checkIsTallyGoods',
/**
* 扫描入库
*/
szScanIn: API_BASE + '/supplywechatwms/szScanIn',
......
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