barcodeCombine.js 963 B

12345678910111213141516171819
  1. import { barcodeToUpperCase } from '@/utils/dataType'
  2. /** 组合商品:匹配ASN明细中条码,附加 matchedJson */
  3. export function receivingBarcodeCombine(asnDetailList, combineSkuMap) {
  4. if (!combineSkuMap || !Array.isArray(asnDetailList) || !asnDetailList.length) return []
  5. const mapUpper = Object.fromEntries(
  6. Object.entries(combineSkuMap).filter(([barcode]) => barcode).map(([barcode, config]) => [barcodeToUpperCase(barcode), config])
  7. )
  8. return asnDetailList
  9. .map((item) => {
  10. const barcodes = [item.barcode, item.barcode2, item.sku].filter(Boolean)
  11. const matchedBar = barcodes.find((bar) => mapUpper[barcodeToUpperCase(bar)])
  12. if (!matchedBar) return null
  13. const matched = mapUpper[barcodeToUpperCase(matchedBar)]
  14. const remaining = (item.expectedQuantity || 0) - (item.receivedQuantity || 0)
  15. return remaining >= matched.quantity ? { ...item, matchedJson: matched } : null
  16. })
  17. .filter(Boolean)
  18. }