You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { Component, Input, OnInit } from "@angular/core";
|
|
|
|
import { ApiService } from "@cdk/services";
|
|
|
|
|
|
|
|
export interface FoodInDishInterface {
|
|
|
|
foodName: string;
|
|
|
|
key: string;
|
|
|
|
isMain: boolean;
|
|
|
|
groupValues: Array<{
|
|
|
|
peopleName: string;
|
|
|
|
value: number;
|
|
|
|
}>;
|
|
|
|
value: Record<string, number>;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-add-dish-to-ingredient",
|
|
|
|
templateUrl: "./add-dish-to-ingredient.component.html",
|
|
|
|
styleUrls: ["./add-dish-to-ingredient.component.less"],
|
|
|
|
})
|
|
|
|
export class AddDishToIngredientComponent implements OnInit {
|
|
|
|
constructor(private api: ApiService) {}
|
|
|
|
|
|
|
|
@Input() peopleGroups: string[] = [];
|
|
|
|
|
|
|
|
globalEnum = this.api.globalEnum;
|
|
|
|
|
|
|
|
dish: any = null;
|
|
|
|
|
|
|
|
mark: string = "";
|
|
|
|
|
|
|
|
foods: FoodInDishInterface[] = [];
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
console.log("this.peopleGroups", this.peopleGroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDishChange(dish: any) {
|
|
|
|
if (dish) {
|
|
|
|
this.mark = dish.marks;
|
|
|
|
this.getFoodNameByKeys(dish.ingredient);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getFoodNameByKeys(foods: any[]) {
|
|
|
|
const keys = foods.map((i) => i.key);
|
|
|
|
this.api.getFoodList({ keys }).subscribe((res) => {
|
|
|
|
this.foods = res.body.map((i) => {
|
|
|
|
return {
|
|
|
|
foodName: i.name,
|
|
|
|
key: i.key,
|
|
|
|
isMain: foods.find((f) => f.key === i.key)?.isMain ?? false,
|
|
|
|
groupValues: this.peopleGroups.map((p) => {
|
|
|
|
return {
|
|
|
|
peopleName: p,
|
|
|
|
value: 0,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
value: {},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|