| | |
| | | data[i].selected = true; |
| | | } |
| | | that.showBackData(data) |
| | | // 加载物料成功后,清空物料编码输入框 |
| | | that.matnrCode = ''; |
| | | // 加载物料成功后,不清空物料编码输入框,方便连续扫描不同物料 |
| | | // 用户可以通过手动清空或点击清空按钮来清空输入框 |
| | | // 重复扫描同一物料会通过showBackData中的去重逻辑自动过滤 |
| | | } else { |
| | | uni.showToast({ |
| | | title: msg || "查询失败", |
| | |
| | | } |
| | | }, |
| | | showBackData(data) { |
| | | // 追加新物料到列表,只根据id去重,不限制质检结果 |
| | | // 追加新物料到列表,根据物料编码和跟踪码组合去重 |
| | | let addedCount = 0; |
| | | let skippedCount = 0; |
| | | data.forEach(item => { |
| | | // 检查是否已存在相同id的物料,如果不存在则追加 |
| | | const exists = this.list.some(existingItem => existingItem.id === item.id); |
| | | // 检查是否已存在相同的物料 |
| | | const exists = this.list.some(existingItem => { |
| | | // 优先检查物料编码,如果物料编码不同,认为是不同物料,允许添加 |
| | | if (existingItem.matnrCode && item.matnrCode) { |
| | | // 两个都有物料编码,如果不同则允许添加 |
| | | if (existingItem.matnrCode !== item.matnrCode) { |
| | | return false; // 物料编码不同,不存在,允许添加 |
| | | } |
| | | // 物料编码相同,继续检查其他字段 |
| | | } else if (existingItem.matnrCode || item.matnrCode) { |
| | | // 一个有一个没有物料编码,认为是不同物料,允许添加 |
| | | return false; |
| | | } |
| | | // 两个都没有物料编码,继续检查其他字段 |
| | | // 如果两个都有id且相同,认为是同一物料 |
| | | if (existingItem.id && item.id && existingItem.id === item.id) { |
| | | return true; |
| | | } |
| | | // 物料编码相同(或都为空),检查跟踪码(如果有跟踪码,跟踪码不同则允许添加) |
| | | if (existingItem.trackCode && item.trackCode) { |
| | | // 都有跟踪码,跟踪码相同则认为是同一物料 |
| | | return existingItem.trackCode === item.trackCode; |
| | | } |
| | | // 物料编码相同,检查ASN单号(如果有ASN单号,ASN单号不同则允许添加) |
| | | if (existingItem.asnCode && item.asnCode) { |
| | | // 都有ASN单号,ASN单号相同则认为是同一物料 |
| | | return existingItem.asnCode === item.asnCode; |
| | | } |
| | | // 物料编码相同,但都没有跟踪码和ASN单号(都是从物料信息表获取的),认为是同一物料 |
| | | if (existingItem.matnrCode === item.matnrCode && |
| | | !existingItem.trackCode && !item.trackCode && |
| | | !existingItem.asnCode && !item.asnCode) { |
| | | return true; |
| | | } |
| | | // 物料编码相同,但一个没有跟踪码/ASN,另一个有,认为是不同物料,允许添加 |
| | | // 或者两个都没有物料编码且没有其他唯一标识,也允许添加(可能是不同物料) |
| | | return false; |
| | | }); |
| | | if (!exists) { |
| | | this.list.push(item); |
| | | addedCount++; |
| | | } else { |
| | | skippedCount++; |
| | | } |
| | | }); |
| | | // 如果所有物料都已存在,提示用户 |
| | | if (addedCount === 0 && skippedCount > 0) { |
| | | uni.showToast({ |
| | | title: "该物料已添加,请扫描其他物料", |
| | | icon: "none", |
| | | position: 'top', |
| | | duration: 1500 |
| | | }); |
| | | } else if (addedCount > 0) { |
| | | // 成功添加物料后,延迟清空物料编码输入框,方便连续扫描不同物料 |
| | | // 延迟300ms清空,让用户可以快速连续扫描不同的物料 |
| | | setTimeout(() => { |
| | | this.matnrCode = ''; |
| | | }, 300); |
| | | } |
| | | }, |
| | | showMsg(msg) { |
| | | setTimeout(function() { |