export function getDataSource(details) { let items = []; details.forEach(detail => { var item = items.find(r => r.itemCode == detail.itemCode) if (item == undefined) { item = createItemInfo(detail); let newDetail = createDetailInfo(detail); // item.details.push(newDetail); items.push(item) } else { item.qty += detail.qty let newDetail = createDetailInfo(detail); // item.details.push(newDetail); } }) return items; } export function createItemInfo(detail) { let item = { itemCode: detail.itemCode, itemName: detail.itemName, stdPackQty: Number(detail.stdPackQty)||undefined, stdPackUnit: detail.stdPackUnit, qty: Number(detail.qty), handleQty: 0, uom: detail.uom, details: [] } return item; } export function createDetailInfo(data) { data.scaned = false; // data.record = {}; let detail = data; return detail; } //根据明细创建记录 export function createRecordInfo(detail, balance) { var record = {} // let record = JSON.parse(JSON.stringify(detail)); //克隆对象,深度克隆,防止双向绑定同一个变量 Object.assign(record, detail) detail.scaned = true; detail.balance = balance; detail.recommendInventoryStatus = detail.inventoryStatus; detail.inventoryStatus = balance.inventoryStatus; record.qty = Number(balance.qty); return record; } //计算实际数量 export function calcHandleQty(detailSource) { for (let item of detailSource) { item.handleTotalQty = 0; for (let detail of item.details) { if (detail != undefined && detail.scaned) { item.handleTotalQty += Number(detail.handleQty) } } } } export function getScanCount(detailList) { let items = detailList.filter(r => { if (r.scaned) { return r; } }) let scanCount = items != null ? items.length : 0; return scanCount; }