Надеюсь помог)
get palletTasks(): Array<Object>{
return this.scannedWare ?
(this._palletTasks.filter(a => a['positions'].some(b => b['wares'].some(c => c['code'] === this.scannedWare['data']['code']))) ) :
(this._palletTasks || []);
}
get replenishment_guid(): string {
return this._replenishment_guid;
}
set palletTasks(data: Array<Object>) {
this.selected = 0;
const pallets: Object = {};
data.forEach(dataValue => {
dataValue['wares'].forEach(waresValue => {
if (!pallets[waresValue['object']['palletBarcode']]) {
pallets[waresValue['object']['palletBarcode']] = {
positions: {},
object: waresValue['object'],
task: waresValue['task']['guid'],
rest: 0,
replenish: 0,
selected: waresValue['object']['select'],
};
if (waresValue['object']['select']) {
this.selected++;
}
}
pallets[waresValue['object']['palletBarcode']]['positions'][dataValue['sale']['positionBarcode']] = {
...dataValue['sale'],
wares: waresValue['wares'].sort((a, b) => b['emergency'] ? 1 : -1)
};
waresValue['wares'].forEach((waresItem) => {
pallets[waresValue['object']['palletBarcode']]['rest'] += waresItem['rest'];
pallets[waresValue['object']['palletBarcode']]['replenish'] += waresItem['replenish'];
});
});
});
this._palletTasks = Object.keys(pallets).map((palletKey) => {
let wares_count = 0;
let wares_emergency = 0;
pallets[palletKey]['positions'] = Object.keys(pallets[palletKey]['positions']).map((positionKey) => {
wares_count += pallets[palletKey]['positions'][positionKey]['wares'].length;
wares_emergency += pallets[palletKey]['positions'][positionKey]['wares'].reduce(
(acc, cur) => acc + (cur['emergency'] ? 1 : 0), 0);
return pallets[palletKey]['positions'][positionKey];
});
pallets[palletKey]['count'] = wares_count;
pallets[palletKey]['emergency_count'] = wares_emergency;
return pallets[palletKey];
}).sort((a, b) => b['emergency_count'] - a['emergency_count']);
this.dictPallets = pallets;
this._replenishment_guid = data[0]['wares'][0]['replenishment']['guid'];
}
ngOnInit() {
this.parent.backButton = '/';
this.parent.header = 'Пополнение: ' + this.localService.direction.name;
this.rbs.setDownloadScreen();
this.localService.getData().subscribe(
(res: Object) => this.handleGetData(res),
(err: any) => this.handleMessage(err)
);
}
@ResponseHandle()
private handleGetData(ans: Object): void {
if (ans['rows'].length > 0) {
this.palletTasks = ans['rows'];
this.rbs.finalScreen();
} else {
this.handleMessage('Задачи отсутсвуют');
this.parent.back();
}
}