|
@ -3,6 +3,8 @@ import { Component, Input, OnChanges, SimpleChanges, TemplateRef } from "@angula |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
import { Augmented, OptionItemInterface } from "@cdk/types"; |
|
|
import { Augmented, OptionItemInterface } from "@cdk/types"; |
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
|
|
|
import { forkJoin } from "rxjs"; |
|
|
|
|
|
import { ApiService } from "@cdk/services"; |
|
|
|
|
|
|
|
|
// export interface MenuObjectInterface {
|
|
|
// export interface MenuObjectInterface {
|
|
|
// [Day: number]: {
|
|
|
// [Day: number]: {
|
|
@ -30,9 +32,11 @@ export type DishInterface = Augmented<{ |
|
|
styleUrls: ["./ingredient-dish.component.less"], |
|
|
styleUrls: ["./ingredient-dish.component.less"], |
|
|
}) |
|
|
}) |
|
|
export class IngredientDishComponent implements OnChanges { |
|
|
export class IngredientDishComponent implements OnChanges { |
|
|
constructor(private modal: NzModalService, private msg: NzMessageService) {} |
|
|
constructor(private modal: NzModalService, private msg: NzMessageService, private api: ApiService) {} |
|
|
|
|
|
|
|
|
@Input() menu: any | null; |
|
|
@Input() menuBaisc: any | null; |
|
|
|
|
|
|
|
|
|
|
|
@Input() menuDishFormServer: any | null; |
|
|
|
|
|
|
|
|
expanded = new Set<number>(); |
|
|
expanded = new Set<number>(); |
|
|
|
|
|
|
|
@ -54,15 +58,41 @@ export class IngredientDishComponent implements OnChanges { |
|
|
mealDishList: DishInterface[] = []; |
|
|
mealDishList: DishInterface[] = []; |
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
if (changes["menu"]?.currentValue) { |
|
|
if (changes["menuBaisc"]?.currentValue) { |
|
|
this.initMenu(); |
|
|
this.initMenuBasic(); |
|
|
|
|
|
} |
|
|
|
|
|
if (changes["menuDishFormServer"]?.currentValue) { |
|
|
|
|
|
this.initMenuDish(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
initMenu() { |
|
|
initMenuDish() { |
|
|
if (this.menu) { |
|
|
const foodIds = new Set<number>(); |
|
|
const meals = this.menu.meals as string[]; |
|
|
this.menuDishFormServer.forEach((i: any) => { |
|
|
const day = this.menu.day as number; |
|
|
i.ingredient.map((food: any) => { |
|
|
|
|
|
foodIds.add(food.key); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
forkJoin([this.api.getFoodList({ keys: Array.from(foodIds) })]).subscribe(([res]) => { |
|
|
|
|
|
this.mealDishList = this.menuDishFormServer.map((i: any) => { |
|
|
|
|
|
return { |
|
|
|
|
|
...i, |
|
|
|
|
|
dishName: i.name, |
|
|
|
|
|
mealIndex: this.menuBaisc.meals.findIndex((m: string) => m === i.meal), |
|
|
|
|
|
items: i.ingredient.map((food: any) => { |
|
|
|
|
|
const fd = res.body.find((f) => f.key === food.key); |
|
|
|
|
|
food.foodName = fd.name; |
|
|
|
|
|
return food; |
|
|
|
|
|
}), |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
initMenuBasic() { |
|
|
|
|
|
if (this.menuBaisc) { |
|
|
|
|
|
const meals = this.menuBaisc.meals as string[]; |
|
|
|
|
|
const day = this.menuBaisc.day as number; |
|
|
this.days = Array.from({ length: day }, (_, i) => { |
|
|
this.days = Array.from({ length: day }, (_, i) => { |
|
|
this.selectDay.push({ |
|
|
this.selectDay.push({ |
|
|
label: `第${i + 1}天`, |
|
|
label: `第${i + 1}天`, |
|
|