web,app,后端更改二维码唯一
This commit is contained in:
@@ -188,55 +188,37 @@ export default {
|
||||
throw new Error('未找到二维码记录');
|
||||
}
|
||||
|
||||
// 2. 解析content获取enter_coil_no、current_coil_no和coil_id
|
||||
const qrcodeRecord = qrcodeRes.data;
|
||||
const content = JSON.parse(qrcodeRecord.content);
|
||||
const enterCoilNo = content.enter_coil_no;
|
||||
const currentCoilNo = content.current_coil_no;
|
||||
const coilId = content.coil_id && content.coil_id !== 'null' ? content.coil_id : null;
|
||||
|
||||
if (!enterCoilNo) {
|
||||
throw new Error('二维码中未包含有效的入场钢卷号');
|
||||
}
|
||||
|
||||
// 3. 通过追溯接口获取钢卷信息
|
||||
const traceRes = await getMaterialCoilTrace(enterCoilNo, currentCoilNo);
|
||||
if (traceRes.code !== 200 || !traceRes.data || !traceRes.data.records || traceRes.data.records.length === 0) {
|
||||
throw new Error('未找到钢卷信息');
|
||||
}
|
||||
|
||||
// 4. 根据二维码内容匹配对应的钢卷数据
|
||||
let coilData = null;
|
||||
const records = traceRes.data.records;
|
||||
|
||||
// 优先使用coil_id精确匹配
|
||||
if (coilId) {
|
||||
coilData = records.find(record => String(record.coilId) === String(coilId));
|
||||
}
|
||||
|
||||
// 如果没找到,使用currentCoilNo匹配
|
||||
if (!coilData && currentCoilNo) {
|
||||
coilData = records.find(record => record.currentCoilNo === currentCoilNo);
|
||||
}
|
||||
|
||||
// 如果还是没找到,取第一条记录
|
||||
if (!coilData && records.length > 0) {
|
||||
coilData = records[0];
|
||||
}
|
||||
|
||||
if (!coilData) {
|
||||
throw new Error('未找到对应的钢卷数据');
|
||||
}
|
||||
|
||||
// 5. 检查是否为历史数据
|
||||
if (coilData.dataType === 0) {
|
||||
uni.showModal({
|
||||
title: '历史数据',
|
||||
content: '此为历史记录,不允许进行合卷操作',
|
||||
showCancel: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 2. 解析content获取current_coil_id
|
||||
const qrcodeRecord = qrcodeRes.data;
|
||||
const content = JSON.parse(qrcodeRecord.content);
|
||||
|
||||
// 优先使用current_coil_id(当前有效的钢卷ID),如果没有则使用coil_id(兼容旧数据)
|
||||
let coilId = content.current_coil_id && content.current_coil_id !== 'null' ? content.current_coil_id : null;
|
||||
if (!coilId) {
|
||||
coilId = content.coil_id && content.coil_id !== 'null' ? content.coil_id : null;
|
||||
}
|
||||
|
||||
// 检查二维码状态
|
||||
if (qrcodeRecord.status === 0) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '该二维码已失效,无法进行合卷操作',
|
||||
showCancel: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!coilId) {
|
||||
throw new Error('二维码中未包含有效的钢卷ID');
|
||||
}
|
||||
|
||||
// 3. 直接通过钢卷ID获取钢卷详情
|
||||
const coilRes = await getMaterialCoil(coilId);
|
||||
if (coilRes.code !== 200 || !coilRes.data) {
|
||||
throw new Error('未找到钢卷信息');
|
||||
}
|
||||
|
||||
const coilData = coilRes.data;
|
||||
|
||||
// 6. 检查是否已扫描过
|
||||
const exists = this.scannedCoils.some(coil => coil.coilId === coilData.coilId);
|
||||
|
||||
Reference in New Issue
Block a user