Commit cf59893b by LJM

香港wms-理货确认-打印标签

parent 7f901591
......@@ -61,323 +61,234 @@
</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, findIndexOrZero } from '@/util/util.js';
const ToBase64 = require('../../util/base64gb2312.js');
export default {
data() {
return {
print_number: 0,
serviceId: '',
deviceId: '',
device_name: '',
characteristics: '',
text: '标签数量',
index: -1,
index_erp_order_sn_pre: -1,
index_print_type: 1,
items_erp_order_sn_pre: ['A单号', 'B单号', 'D单号'],
items_print_type: ['卡板', '散箱'],
traySelectOption: [],
sendData64: '',
printLabelData: [],
print_text: '总箱数',
platform: '',
wstyptll_id: '',
batchArr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
flag: false,
numberList: [],
numberArr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
numberIndex: 0,
form: {
batch: 0, //批次
print_type: 2, //打印类型
erp_order_sn: '', //入仓号
label_num: '1', //总箱数
number: 1,
numbers: []
export default {
data() {
return {
print_number: 0,
serviceId: '',
deviceId: '',
device_name: '',
characteristics: '',
text: '标签数量',
index: -1,
index_erp_order_sn_pre: -1,
index_print_type: 1,
items_erp_order_sn_pre: ['A单号', 'B单号', 'D单号'],
items_print_type: ['卡板', '散箱'],
traySelectOption: [],
sendData64: '',
printLabelData: [],
print_text: '总箱数',
platform: '',
wstyptll_id: '',
batchArr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
flag: false,
numberList: [],
numberArr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
numberIndex: 0,
form: {
batch: 0, //批次
print_type: 2, //打印类型
erp_order_sn: '', //入仓号
label_num: '1', //总箱数
number: 1,
numbers: []
},
printParams: {
board_num: '', //板子数
box_num: '', //箱子数
erp_order_sn: '' //入仓号
}
};
},
onLoad(option) {
this.platform = getPlatform();
this.printParams.board_num = option.board_num || '';
this.printParams.box_num = option.box_num || '';
this.printParams.erp_order_sn = option.erp_order_sn || '';
//如果【理货确认-箱】有数值,则【打印标签】打印类型为【散箱】并继承数据【标签数量】
if (this.printParams.box_num) {
this.index_print_type = 1;
this.form.label_num = this.printParams.box_num;
this.form.erp_order_sn = this.printParams.erp_order_sn;
}
};
},
onLoad(option) {
this.platform = getPlatform();
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
console.log('停止搜索', JSON.stringify(res.errMsg));
//如果【理货确认-板】有数值,则【打印标签】打印类型为【卡板】并继承卡板数
if (this.printParams.board_num) {
this.index_print_type = 0;
this.form.erp_order_sn = this.printParams.erp_order_sn;
this.numberIndex = findIndexOrZero(this.numberArr, Number(this.printParams.board_num)); //匹配到卡板数就选中,否则就是默认0
}
});
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: {
scanChange() {
uni.scanCode({
//如果【理货确认-板/箱 均不为0】,则【打印标签】打印类型只继承入仓号,打印类型默认为【散箱】标签数量1 批次为0(保持原默认值)
if (this.printParams.box_num && this.printParams.board_num) {
this.form.erp_order_sn = this.printParams.erp_order_sn;
}
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
if (res.errMsg == 'scanCode:ok') {
this.form.erp_order_sn = res.result;
}
},
fail: function(res) {
uni.showToast({
title: '扫码失败',
icon: 'error'
});
console.log('停止搜索', JSON.stringify(res.errMsg));
}
});
},
/**
* 卡板数监听
*/
bindPickerChange(e) {
this.numberIndex = Number(e.detail.value);
this.form.number = Number(e.target.value) + 1;
if (this.form.number > 1) {
this.flag = true;
this.numberList = [];
this.form.numbers = [];
for (var i = 0; i < this.form.number; i++) {
if (i < this.form.number - 1) {
this.numberList.push(i);
this.form.numbers.push({
value: ''
});
}
}
} else {
this.flag = false;
this.numberList = [];
this.form.numbers = [];
try {
uni.removeStorageSync('device');
} catch (e) {
// error
}
},
/**
* 批次监听
*/
bindPickerChangeBatch(e) {
this.form.batch = e.target.value;
},
/**
* 卡板数量list监听
*/
onInput(e, index) {
this.form.numbers[index].value = e.detail.value;
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 = '';
}
},
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('用户点击取消');
methods: {
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'
});
}
});
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;
}
if (this.index_print_type == 0 && this.form.number > 1) {
let label_num = this.form.label_num * 1; //总箱数
let num = 0;
},
/**
* 卡板数监听
*/
bindPickerChange(e) {
this.numberIndex = Number(e.detail.value);
this.form.number = Number(e.target.value) + 1;
if (this.form.numbers.length > 0) {
for (let i = 0; i < this.form.numbers.length; i++) {
num += this.form.numbers[i].value * 1;
if (this.form.number > 1) {
this.flag = true;
this.numberList = [];
this.form.numbers = [];
for (var i = 0; i < this.form.number; i++) {
if (i < this.form.number - 1) {
this.numberList.push(i);
this.form.numbers.push({
value: ''
});
}
}
} else {
this.flag = false;
this.numberList = [];
this.form.numbers = [];
}
if (label_num != num) {
},
/**
* 批次监听
*/
bindPickerChangeBatch(e) {
this.form.batch = e.target.value;
},
/**
* 卡板数量list监听
*/
onInput(e, index) {
this.form.numbers[index].value = e.detail.value;
},
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: '卡板数量总和必须等于总箱数',
content: '请输入入仓号',
showCancel: false
});
return false;
}
}
let params = Object.assign(this.form, {
is_add: 0
});
this.request(API.checkRepeatPrintLabel, 'POST', params, true).then(res => {
if (res.err_code === 0) {
this.printLabelChange();
} else {
if (!this.form.label_num) {
uni.showModal({
title: '提示',
content: res.err_msg,
confirmText: '继续打印',
success: res => {
if (res.confirm) {
this.printLabelChange();
} else if (res.cancel) {
console.log('用户点击取消');
}
}
content: '请输入' + this.text,
showCancel: false
});
return false;
}
});
},
printLabelChange() {
this.request(API.printLabel, 'POST', this.form, true).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
this.wstyptll_id = res.data[0].wstyptll_id;
this.sendDataChange(); //发送数据
} else {
if (!/(^[0-9]*$)/.test(this.form.label_num)) {
uni.showModal({
title: '提示',
content: res.err_msg,
confirmText: '关闭'
content: this.text + '为纯数字',
showCancel: false
});
return false;
}
});
},
/**
* 向蓝牙发送数据
*/
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.form.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');
if (this.index_print_type == 0 && this.form.number > 1) {
let label_num = this.form.label_num * 1; //总箱数
let num = 0;
if (this.form.numbers.length > 0) {
for (let i = 0; i < this.form.numbers.length; i++) {
num += this.form.numbers[i].value * 1;
}
}
if (label_num != num) {
uni.showModal({
title: '提示',
content: '卡板数量总和必须等于总箱数',
showCancel: false
});
return false;
}
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: '关闭'
let params = Object.assign(this.form, {
is_add: 0
});
}
},
/**
* 分批传输数据
*/
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)));
}
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: res => {
uni.hideLoading();
this.request(API.checkRepeatPrintLabel, 'POST', params, true).then(res => {
if (res.err_code === 0) {
this.printLabelChange();
} else {
uni.showModal({
title: '提示',
content: '打印失败,请重新进入打印页面',
showCancel: false,
confirmText: '关闭',
content: res.err_msg,
confirmText: '继续打印',
success: res => {
if (res.confirm) {
this.characteristics = ''; //连接蓝牙信息清空
this.deviceId = ''; //连接蓝牙信息清空
this.device_name = ''; //连接蓝牙信息清空
this.print_number = 0; //打印计数归零
this.printLabelData = []; //打印数据清空
this.sendData64 = ''; //发送蓝牙数据清空
this.delErpOrderSnCodeManage(); //及时作废
this.printLabelChange();
} else if (res.cancel) {
console.log('用户点击取消');
}
......@@ -385,71 +296,186 @@ export default {
});
}
});
} else {
this.print_number++;
console.log('第' + this.print_number + '次传输完成end');
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
},
printLabelChange() {
this.request(API.printLabel, 'POST', this.form, 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,
confirmText: '关闭'
});
}
});
},
/**
* 向蓝牙发送数据
*/
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.form.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();
//重置
this.print_number = 0; //打印计数归零
this.printLabelData = []; //打印数据清空
this.sendData64 = ''; //发送蓝牙数据清空
uni.showModal({
title: '提示',
content: '打印成功,请查看标签打印机',
content: '数据异常,请重试',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
confirmText: '关闭'
});
}
}
},
delErpOrderSnCodeManage() {
this.request(API.delWstyptllIdErpOrderSnCodeManage, 'POST', { wstyptll_id: this.wstyptll_id }, false).then(res => {
if (res.err_code === 0) {
} else {
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
},
/**
* 分批传输数据
*/
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)));
}
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: res => {
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('用户点击取消');
}
}
});
}
}
});
},
change(index, type) {
if (type == 'print_type') {
//打印类型
this.index_print_type = index;
if (index == 0) {
this.form.print_type = 1;
this.text = '总箱数';
this.print_text = '总箱数';
this.numberIndex = 0;
} else if (index == 1) {
this.form.print_type = 2;
this.text = '标签数量';
this.print_text = '箱号';
},
delErpOrderSnCodeManage() {
this.request(API.delWstyptllIdErpOrderSnCodeManage, 'POST', { wstyptll_id: this.wstyptll_id }, false).then(res => {
if (res.err_code === 0) {} else {
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
});
}
});
},
change(index, type) {
if (type == 'print_type') {
//打印类型
this.index_print_type = index;
if (index == 0) {
this.form.print_type = 1;
this.text = '总箱数';
this.print_text = '总箱数';
this.numberIndex = 0;
} else if (index == 1) {
this.form.print_type = 2;
this.text = '标签数量';
this.print_text = '箱号';
//置空卡板
this.flag = false;
this.form.number = '';
this.form.numbers = [];
//置空卡板
this.flag = false;
this.form.number = '';
this.form.numbers = [];
}
}
}
}
}
};
};
</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
......@@ -110,6 +110,7 @@
</view>
</view>
<view class="btn row rowCenter verCenter" @click="submit()" :class="{ disabled: disabled }">确认提交</view>
<view class="btn row rowCenter verCenter" style="margin-top: 12rpx;background-color: #f00;" @click="submit(1)" :class="{ disabled: disabled }">确认提交并打印</view>
</view>
</template>
......@@ -456,9 +457,10 @@
this.form.customs_clearance_price = index;
},
/**
* @param {Object} type 1提交并打印
* 提交
*/
submit() {
submit(type) {
if (!this.form.erp_order_sn) {
uni.showModal({
title: '提示',
......@@ -524,11 +526,18 @@
showCancel: false,
success: res => {
if (res.confirm) {
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 2000);
if (type == 1) {
//点击【确认提交并打印】跳转至【打印标签】页面
uni.navigateTo({
url: '/pages/tag/print?board_num=' + this.form.board_num + '&box_num=' + this.form.box_num + '&erp_order_sn=' + this.form.erp_order_sn
})
} else {
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 2000);
}
} else if (res.cancel) {
console.log('用户点击取消');
}
......
......@@ -86,7 +86,6 @@ const debounce = (fn, wait) => {
}
}
/**
* 来创建指定长度且所有元素都被初始化为 false 的数组
*/
......@@ -94,11 +93,21 @@ const createArray = (length, value) => {
return Array(length).fill(value);
}
/**
* 数组内找出对于的索引
*/
const findIndexOrZero = (arr, value) => {
var index = arr.indexOf(value);
return index !== -1 ? index : 0;
}
module.exports = {
request,
getPlatform,
titleCase,
debounce,
createArray
createArray,
findIndexOrZero
}
\ No newline at end of file
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