|
|
|
import {
|
|
|
|
calc
|
|
|
|
} from '@/common/calc'
|
|
|
|
export function getDataSource(subList) {
|
|
|
|
let items = [];
|
|
|
|
subList.forEach(detail => {
|
|
|
|
var item = items.find(r =>
|
|
|
|
r.itemCode == detail.itemCode)
|
|
|
|
if (item == undefined) {
|
|
|
|
item = createItemInfo(detail);
|
|
|
|
let newDetail = createDetailInfo(detail); //
|
|
|
|
item.subList.push(newDetail);
|
|
|
|
items.push(item)
|
|
|
|
} else {
|
|
|
|
item.qty = calc.add(item.qty, detail.qty)
|
|
|
|
let newDetail = createDetailInfo(detail); //
|
|
|
|
item.subList.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,
|
|
|
|
subList: []
|
|
|
|
}
|
|
|
|
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.handleQty = new Decimal(0).toNumber();
|
|
|
|
item.qty = new Decimal(0).toNumber();
|
|
|
|
for (let detail of item.subList) {
|
|
|
|
if (detail != undefined && detail.scaned) {
|
|
|
|
item.handleQty = calc.add(item.handleQty,detail.handleQty);
|
|
|
|
item.qty = calc.add(item.qty,detail.qty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getScanCount(subList) {
|
|
|
|
let items = subList.filter(r => {
|
|
|
|
if (r.scaned) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let scanCount = items != null ? items.length : 0;
|
|
|
|
return scanCount;
|
|
|
|
}
|