You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.2 KiB

1 year ago
let labelDic = [];
import {
getLabelByHeader,
getPackageByNumber
} from '@/api/request2.js';
export function getLabelInfo(scanMsg, callBack) {
console.log('扫描信息:', scanMsg);
if (scanMsg.length == 0) {
return null
}
let items = scanMsg.split(';');
let header = items[0];
let version = items[1];
if ((header != undefined) && (version!=undefined)) {
1 year ago
//解析扫描的是一维码还是二维码
let type = header.substring(header.length - 1, header.length);
if (type == 'Q') //qrcode
{
getQRCodeInfo(header, version, scanMsg, callBack);
} else if (type == 'B') //barcode
{
getBarCodeInfo(header, version, items[2], callBack);
} else { //直接输入文本
getBarCodeInfo('text', 'V1.0', scanMsg, callBack);
}
}else {
let labelResult = {
label: {
labelType: "",
barType: '',
code:""
},
package: null,
success: false,
message: '标签格式不正确',
}
callBack(labelResult);
1 year ago
}
}
export function getQRCodeInfo(header, version, scanMsg, callBack) {
//获取包装信息
let labelItem = labelDic.find(r => r.header == header && r.version == version);
if (labelItem == undefined) {
let labelResult = {
label: {
barType: 'QRCode',
},
package: {},
success: true,
1 year ago
message: ''
}
getLabelByHeader(header, version).then(res => {
if (res.data==null) {
labelResult.success = false;
1 year ago
labelResult.message = '未查找到标签头为[' + header + ']的标签类型';
callBack(labelResult);
} else {
let newItem = {
header: header,
version: version,
label: res.data,
};
labelDic.push(newItem);
getLabelItems(newItem, scanMsg, callBack);
}
}).catch(err => {
labelResult.success = false;
1 year ago
labelResult.message = err;
callBack(err);
})
} else {
getLabelItems(labelItem, scanMsg, callBack);
}
}
export function getLabelItems(labelItem, scanMsg, callBack) {
let labelResult = analysisQRCodeLabel(labelItem, scanMsg);
if (labelResult.label.labelType == 'PurchaseLabel' || labelResult.label.labelType == 'MakeLabel') {
//查询包装信息
let packingNumber = labelResult.label.packingNumber
if (packingNumber != undefined) {
getPackageByNumber(packingNumber).then(pack => {
if (pack.data.list.length == 0) {
labelResult.success = false;
1 year ago
labelResult.message = '包装号[' + packingNumber + ']没有包装信息';
} else {
labelResult.package = pack.data.list[0];
console.log('包装信息', JSON.stringify(labelResult.package))
}
callBack(labelResult);
}).catch(err => {
labelResult.success = false;
1 year ago
labelResult.message = err;
callBack(labelResult);
})
} else {
labelResult.success = false;
1 year ago
labelResult.message = '在条码中未解析到箱码';
callBack(labelResult);
}
} else {
callBack(labelResult);
}
}
export function analysisQRCodeLabel(labelItem, scanMsg) {
let labelResult = {
label: {
labelType: labelItem.label.labelType,
barType: 'QRCode',
},
package: {},
success: true,
1 year ago
message: ''
}
let separators = labelItem.label.separators;
if (separators == undefined || separators == null) {
labelResult.message = "未读取到分隔符";
} else {
if (scanMsg.indexOf(separators) < 0) {
labelResult.success = false;
1 year ago
labelResult.message = "标签格式不正确";
} else {
try {
let scanItems = scanMsg.split(separators);
if (scanItems.length > 0) {
scanItems.forEach((item, index) => {
let type = item.substring(0, 1);
let value = item.substring(1, item.length);
if (type == 'H') {
labelResult.label.header = item;
} else if (type == 'V') {
labelResult.label.version = item;
} else {
let barcode = labelItem.label.subList.find(code => code.prefixChar.toUpperCase() ==
type
.toUpperCase());
if (barcode != undefined) {
labelResult.label[barcode.code] = value;
}
}
})
}
} catch (e) {
labelResult.message = e.message;
}
}
}
// console.log('标签', labelResult.label)
return labelResult;
}
export function getBarCodeInfo(header, version, value, callBack) {
let labelResult = {
label: {
labelType: header,
barType: 'BarCode',
code:value
},
package: null,
success: true,
1 year ago
message: '',
}
callBack(labelResult);
}