Browse Source

[修正] 数量根据id去重

master
徐振升 4 years ago
parent
commit
a81ea6cd4a
  1. 33
      src/app/canvas-share-data.service.ts

33
src/app/canvas-share-data.service.ts

@ -162,41 +162,52 @@ export class CanvasShareDataService {
}
public getCarTypesAndCount(): Map<string, number> {
let cars = new Map<string, number>();
let ids = new Array();
this.planSelectData.forEach(element => {
if (element != null) {
let data = JSON.parse(element.data);
console.log(data.DefinedIncrement);
console.log(data.Increment);
console.log(data.Stock);
Object.keys(data.DefinedIncrement).forEach(key => {
let name = data.DefinedIncrement[key].Name;
let id = data.DefinedIncrement[key].Id;
if (this.types.includes(name)) {
if (cars.get(name) === undefined) {
cars.set(name, 1);
cars.set(name, 1);
ids.push(id);
} else {
cars.set(name, cars.get(name) + 1);
if (!ids.includes(id)) {
cars.set(name, cars.get(name) + 1);
ids.push(id);
}
}
}
});
Object.keys(data.Increment).forEach(key => {
let name = data.Increment[key].Name;
let id = data.Increment[key].Id;
if (this.types.includes(name)) {
if (cars.get(name) === undefined) {
cars.set(name, 1);
cars.set(name, 1);
ids.push(id);
} else {
cars.set(name, cars.get(name) + 1);
if (!ids.includes(id)) {
cars.set(name, cars.get(name) + 1);
ids.push(id);
}
}
}
});
Object.keys(data.Stock).forEach(key => {
let name = data.Stock[key].Name;
let id = data.Stock[key].Id;
if (this.types.includes(name)) {
if (cars.get(name) === undefined) {
cars.set(name, 1);
cars.set(name, 1);
ids.push(id);
} else {
cars.set(name, cars.get(name) + 1);
if (!ids.includes(id)) {
cars.set(name, cars.get(name) + 1);
ids.push(id);
}
}
}
});

Loading…
Cancel
Save