Commit f2b558bd by liangjianmin

bug

parent 6513638c
......@@ -137,7 +137,7 @@
<textarea @input="inputChange()" maxlength="200" placeholder="请输入理货备注" placeholder-style="color:#6E767A;" v-model="form.sort_goods_remark"></textarea>
<text class="text">{{ limitword }}/200</text>
</view>
<view class="box row verCenter" style="border-bottom: none;">
<!-- <view class="box row verCenter" style="border-bottom: none;">
<text class="label">放置托盘</text>
<view class="uni-list-cell-db">
<text class="iconfont icon-sanjiaoxing1"></text>
......@@ -145,7 +145,7 @@
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
</picker>
</view>
</view>
</view> -->
</view>
</view>
<view class="btn row rowCenter verCenter" @click="submit()">确认收货</view>
......@@ -203,12 +203,26 @@ export default {
},
onLoad(options) {
this.form.number = options.number || ''; //获取参数入仓号
this.getTraySelectOption(); //获取托盘数据
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
console.log('停止搜索', JSON.stringify(res.errMsg));
}
});
try {
uni.removeStorageSync('device');
} catch (e) {
// error
}
},
onShow() {
const deviceData = uni.getStorageSync('device') || ''; //获取已连接蓝牙设备信息
//获取已连接蓝牙设备信息
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 = '';
......@@ -370,15 +384,6 @@ export default {
return false;
}
if (!this.form.wstylt_id) {
uni.showModal({
title: '提示',
content: '请选择放置托盘',
showCancel: false
});
return false;
}
//截取入仓号
if (this.form.number) {
this.printForm.erp_order_sn_pre = this.form.number.substr(0, 1);
......@@ -430,16 +435,28 @@ export default {
*/
print() {
if (!this.device_name) {
uni.showToast({
icon: 'error',
title: '请连接蓝牙'
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;
}
this.request(API.printLabel, 'POST', this.printForm, true).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
this.getBLEDeviceServices(); //根据获取的设备信息,连接设备
this.sendDataChange(); //发送数据
} else {
uni.showToast({
title: res.err_msg,
......@@ -449,66 +466,10 @@ export default {
});
},
/**
* 来获取蓝牙设备所有服务
*/
getBLEDeviceServices() {
let that = this;
uni.showLoading({
title: '设备打印中'
});
uni.createBLEConnection({
deviceId: this.deviceId,
success: res => {
console.log('连接成功', JSON.stringify(res.errMsg));
//需延时连接,不然会报错
setTimeout(() => {
uni.getBLEDeviceServices({
deviceId: that.deviceId,
success: res => {
console.log('获取蓝牙设备所有服务', JSON.stringify(res.errMsg));
that.serviceId = res.services[0].uuid;
that.getBLEDeviceCharacteristics();
}
});
}, 1000);
},
fail: res => {
uni.hideLoading();
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
});
}
});
},
/**
* 获取蓝牙设备某个服务中所有特征值
*/
getBLEDeviceCharacteristics() {
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
that.characteristics = res.characteristics[0].uuid;
that.sendDataChange();
console.log('服务功能特征值', JSON.stringify(res.errMsg));
},
fail: res => {
uni.hideLoading();
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
});
}
});
},
/**
* 向蓝牙发送数据
*/
sendDataChange() {
try {
console.log('第' + this.print_number + '次打印');
let data = [];
if (this.printLabelData.length > 0) {
......@@ -532,6 +493,15 @@ export default {
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
console.log(data.join(''));
} catch (e) {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '数据异常,请重试',
showCancel: false,
confirmText: '关闭'
});
}
},
/**
* 写入二进制数据
......@@ -539,22 +509,17 @@ export default {
writeBLECharacteristicValue() {
let that = this;
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.characteristics,
value: that.sendData64,
success(res) {
that.print_number++;
console.log('蓝牙写入成功:', JSON.stringify(res.errMsg));
console.log('打印计数:' + that.print_number);
if (that.print_number < that.printLabelData.length) {
that.sendDataChange();
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: this.sendData64,
success: res => {
this.print_number++;
console.log('打印张数:' + this.print_number);
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
uni.hideLoading();
uni.closeBLEConnection({
deviceId: that.deviceId,
success(res) {
console.log('关闭蓝牙连接:', JSON.stringify(res.errMsg));
//清空数据
that.print_number = 0;
that.printLabelData = [];
......@@ -573,14 +538,12 @@ export default {
}
});
}
});
}
},
fail() {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '无法打印,请查看标签打印机连接状态',
content: '打印失败,请检查打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
......
......@@ -36,14 +36,14 @@
<view class="label">{{ text }}</view>
<input type="number" v-model="form.label_num" placeholder-style="font-size:24rpx;color:#404547;" class="uni-input" placeholder="请输入" />
</view>
<view class="box row verCenter">
<!-- <view class="box row verCenter">
<view class="label">放置托盘</view>
<view class="el-select row verCenter">
<picker @change="bindPickerChange" :value="index" :range="traySelectOption" range-key="tray_sn">
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
</picker>
</view>
</view>
</view> -->
</view>
<view class="btn row rowCenter verCenter" @click="submit()">提交打印</view>
</view>
......@@ -81,7 +81,13 @@ export default {
};
},
onLoad(option) {
this.getTraySelectOption();
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
console.log('停止搜索', JSON.stringify(res.errMsg));
}
});
try {
uni.removeStorageSync('device');
} catch (e) {
......@@ -89,9 +95,12 @@ export default {
}
},
onShow() {
const deviceData = uni.getStorageSync('device') || ''; //获取已连接蓝牙设备信息
//获取已连接蓝牙设备信息
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 = '';
......@@ -121,12 +130,24 @@ export default {
},
submit() {
if (!this.device_name) {
uni.showToast({
icon: 'error',
title: '请连接蓝牙设备'
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_pre) {
uni.showToast({
icon: 'error',
......@@ -165,78 +186,16 @@ export default {
return false;
}
if (!this.form.tray_remark) {
uni.showToast({
icon: 'error',
title: '请选择放置托盘'
});
return false;
}
this.request(API.printLabel, 'POST', this.form, false).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
this.getBLEDeviceServices(); //根据获取的设备信息,连接设备
this.sendDataChange(); //发送数据
} else {
uni.showToast({
title: res.err_msg,
icon: 'error'
});
}
});
},
/**
* 来获取蓝牙设备所有服务
*/
getBLEDeviceServices() {
let that = this;
uni.showLoading({
title: '设备打印中'
});
uni.createBLEConnection({
deviceId: this.deviceId,
success: res => {
console.log('连接成功', JSON.stringify(res.errMsg));
//需延时连接,不然会报错
setTimeout(() => {
uni.getBLEDeviceServices({
deviceId: that.deviceId,
success: res => {
console.log('获取蓝牙设备所有服务', JSON.stringify(res.errMsg));
that.serviceId = res.services[0].uuid;
that.getBLEDeviceCharacteristics();
}
});
}, 1000);
},
fail: res => {
uni.hideLoading();
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
});
}
});
},
/**
* 获取蓝牙设备某个服务中所有特征值
*/
getBLEDeviceCharacteristics() {
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
that.characteristics = res.characteristics[0].uuid;
that.sendDataChange();
console.log('服务功能特征值', JSON.stringify(res.errMsg));
},
fail: res => {
uni.hideLoading();
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
uni.showModal({
title: '提示',
content: res.err_msg,
showCancel: false,
confirmText: '关闭'
});
}
});
......@@ -245,6 +204,10 @@ export default {
* 向蓝牙发送数据
*/
sendDataChange() {
try {
uni.showLoading({
title: '打印中...'
});
console.log('第' + this.print_number + '次打印');
let data = [];
if (this.printLabelData.length > 0) {
......@@ -268,6 +231,15 @@ export default {
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
console.log(data.join(''));
} catch (e) {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '数据异常,请重试',
showCancel: false,
confirmText: '关闭'
});
}
},
/**
* 写入二进制数据
......@@ -275,22 +247,17 @@ export default {
writeBLECharacteristicValue() {
let that = this;
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.characteristics,
value: that.sendData64,
success(res) {
that.print_number++;
console.log('蓝牙写入成功:', JSON.stringify(res.errMsg));
console.log('打印计数:' + that.print_number);
if (that.print_number < that.printLabelData.length) {
that.sendDataChange();
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: this.sendData64,
success: res => {
this.print_number++;
console.log('打印张数:' + this.print_number);
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
uni.hideLoading();
uni.closeBLEConnection({
deviceId: that.deviceId,
success(res) {
console.log('关闭蓝牙连接:', JSON.stringify(res.errMsg));
//清空数据
that.print_number = 0;
that.printLabelData = [];
......@@ -309,14 +276,12 @@ export default {
}
});
}
});
}
},
fail() {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '无法打印,请查看标签打印机连接状态',
content: '打印失败,请检查打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
......
......@@ -63,10 +63,27 @@ export default {
}
};
},
onLoad(option) {
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
console.log('停止搜索', JSON.stringify(res.errMsg));
}
});
try {
uni.removeStorageSync('device');
} catch (e) {
// error
}
},
onShow() {
const deviceData = uni.getStorageSync('device') || ''; //获取已连接蓝牙设备信息
//获取已连接蓝牙设备信息
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 = '';
......@@ -94,9 +111,20 @@ export default {
},
submit() {
if (!this.device_name) {
uni.showToast({
icon: 'error',
title: '请连接蓝牙设备'
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;
}
......@@ -142,7 +170,7 @@ export default {
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 (res.err_code === 0) {
this.printLabelData = res.data;
this.getBLEDeviceServices(); //根据获取的设备信息,连接设备
this.sendDataChange(); //发送数据
} else {
uni.showToast({
title: res.err_msg,
......@@ -152,66 +180,13 @@ export default {
});
},
/**
* 来获取蓝牙设备所有服务
*/
getBLEDeviceServices() {
let that = this;
uni.showLoading({
title: '设备打印中'
});
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();
}
});
}, 1000);
},
fail: res => {
uni.hideLoading();
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
});
}
});
},
/**
* 获取蓝牙设备某个服务中所有特征值
*/
getBLEDeviceCharacteristics() {
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
that.characteristics = res.characteristics[0].uuid;
that.sendDataChange();
console.log('服务功能特征值', res);
},
fail: res => {
uni.hideLoading();
uni.showToast({
icon: 'error',
title: '连接设备失败!',
duration: 3000
});
}
});
},
/**
* 向蓝牙发送数据
*/
sendDataChange() {
try {
uni.showLoading({
title: '打印中...'
});
console.log('第' + this.print_number + '次打印');
let data = [];
if (this.printLabelData.length > 0) {
......@@ -234,6 +209,15 @@ export default {
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
console.log(data.join(''));
} catch (e) {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '数据异常,请重试',
showCancel: false,
confirmText: '关闭'
});
}
},
/**
* 写入二进制数据
......@@ -241,24 +225,17 @@ export default {
writeBLECharacteristicValue() {
let that = this;
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.characteristics,
value: that.sendData64,
success(res) {
that.print_number++;
console.log('蓝牙写入成功:', JSON.stringify(res.errMsg));
console.log('打印计数:' + that.print_number);
if (that.print_number < that.printLabelData.length) {
setTimeout(function() {
that.sendDataChange();
}, 0);
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: this.sendData64,
success: res => {
this.print_number++;
console.log('打印张数:' + this.print_number);
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
uni.hideLoading();
uni.closeBLEConnection({
deviceId: that.deviceId,
success(res) {
console.log('关闭蓝牙连接:', JSON.stringify(res.errMsg));
//清空数据
that.print_number = 0;
that.printLabelData = [];
......@@ -277,14 +254,12 @@ export default {
}
});
}
});
}
},
fail() {
uni.hideLoading();
uni.showModal({
title: '提示',
content: '无法打印,请查看标签打印机连接状态',
content: '打印失败,请检查打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
......
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