diff --git a/apps/hand-factory/components/panels/code/apart.vue b/apps/hand-factory/components/panels/code/apart.vue index 549a066..686f115 100644 --- a/apps/hand-factory/components/panels/code/apart.vue +++ b/apps/hand-factory/components/panels/code/apart.vue @@ -248,56 +248,37 @@ 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; + // 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 (!enterCoilNo) { - throw new Error('二维码中未包含有效的入场钢卷号'); - } + // 检查二维码状态 + if (qrcodeRecord.status === 0) { + uni.showModal({ + title: '提示', + content: '该二维码已失效,无法进行分卷操作', + showCancel: false + }); + return; + } - // 3. 通过追溯接口获取钢卷信息 - const traceRes = await getMaterialCoilTrace(enterCoilNo, currentCoilNo); - if (traceRes.code !== 200 || !traceRes.data || !traceRes.data.records || traceRes.data.records - .length === 0) { - throw new Error('未找到钢卷信息'); - } + if (!coilId) { + throw new Error('二维码中未包含有效的钢卷ID'); + } - // 4. 根据二维码内容匹配对应的钢卷数据 - let coilData = null; - const records = traceRes.data.records; + // 3. 直接通过钢卷ID获取钢卷详情 + const coilRes = await getMaterialCoil(coilId); + if (coilRes.code !== 200 || !coilRes.data) { + throw new Error('未找到钢卷信息'); + } - // 优先使用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; - } + const coilData = coilRes.data; this.coilDetail = coilData; this.form.coilId = coilData.coilId; diff --git a/apps/hand-factory/components/panels/code/merge.vue b/apps/hand-factory/components/panels/code/merge.vue index 2aaf265..2d83af8 100644 --- a/apps/hand-factory/components/panels/code/merge.vue +++ b/apps/hand-factory/components/panels/code/merge.vue @@ -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); diff --git a/apps/hand-factory/components/panels/code/typing.vue b/apps/hand-factory/components/panels/code/typing.vue index 94a4ab2..51d6c54 100644 --- a/apps/hand-factory/components/panels/code/typing.vue +++ b/apps/hand-factory/components/panels/code/typing.vue @@ -223,58 +223,39 @@ 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; + // 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; + } - // 保存二维码状态(0=历史码,1=当前有效码) - this.qrcodeStatus = qrcodeRecord.status || 1; + // 保存二维码状态(0=失效,1=有效) + this.qrcodeStatus = qrcodeRecord.status || 1; - if (!enterCoilNo) { - throw new Error('二维码中未包含有效的入场钢卷号'); - } + // 3. 如果是失效码,提示用户 + if (this.qrcodeStatus === 0) { + uni.showToast({ + title: '该二维码已失效', + icon: 'none', + duration: 2000 + }); + } - // 3. 如果是历史码,提示用户 - if (this.qrcodeStatus === 0) { - uni.showToast({ - title: '历史二维码,仅供查看', - icon: 'none', - duration: 2000 - }); - } + if (!coilId) { + throw new Error('二维码中未包含有效的钢卷ID'); + } - // 4. 通过入场钢卷号查询钢卷追溯信息 - const traceRes = await getMaterialCoilTrace(enterCoilNo, currentCoilNo); - if (traceRes.code !== 200 || !traceRes.data || !traceRes.data.records || traceRes.data.records - .length === 0) { - throw new Error('未找到钢卷信息'); - } + // 4. 直接通过钢卷ID获取钢卷详情 + const coilRes = await getMaterialCoil(coilId); + if (coilRes.code !== 200 || !coilRes.data) { + throw new Error('未找到钢卷信息'); + } - // 5. 根据二维码内容匹配对应的钢卷数据 - 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('未找到对应的钢卷数据'); - } + const coilData = coilRes.data; // 保存钢卷详情 this.coilDetail = coilData;