配餐项目前端文件
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.

178 lines
4.5 KiB

import { Component, Input, OnChanges, SimpleChanges, TemplateRef } from "@angular/core";
// import { MealDishInterface } from "../ingredient-meals/ingredient-meals.component";
import { NzModalService } from "ng-zorro-antd/modal";
import { Augmented, OptionItemInterface } from "@cdk/types";
import { NzMessageService } from "ng-zorro-antd/message";
import { forkJoin } from "rxjs";
import { ApiService } from "@cdk/services";
import { NzDrawerService } from "ng-zorro-antd/drawer";
import { IngredientAnalysisComponent } from "../ingredient-analysis/ingredient-analysis.component";
// export interface MenuObjectInterface {
// [Day: number]: {
// [MealIndex: number]: MealDishInterface[];
// };
// }
export type DishInterface = Augmented<{
2 years ago
dish: number;
day: number;
meal: string;
mark: string;
items: Array<
Augmented<{
key: string;
isMain: boolean;
value: Record<string, number>;
}>
>;
}>;
@Component({
selector: "app-ingredient-dish",
templateUrl: "./ingredient-dish.component.html",
styleUrls: ["./ingredient-dish.component.less"],
})
export class IngredientDishComponent implements OnChanges {
constructor(
private modal: NzModalService,
private msg: NzMessageService,
private api: ApiService,
private drawer: NzDrawerService
) {}
@Input() menuBaisc: any | null;
2 years ago
@Input() client = false;
@Input() menuDishFormServer: any | null;
expanded = new Set<number>();
days: number[] = [];
selectDay: OptionItemInterface[] = [];
mealCurrentIndex: Record<number, number> = {};
// d = {
// 1:{
// zaocan:[
// {dishId:1...}
// ]
// }
// }
// menuObject!: MenuObjectInterface;
mealDishList: DishInterface[] = [];
ngOnChanges(changes: SimpleChanges): void {
if (changes["menuBaisc"]?.currentValue) {
this.initMenuBasic();
}
if (changes["menuDishFormServer"]?.currentValue) {
this.initMenuDish();
}
}
initMenuDish() {
2 years ago
this.mealDishList = this.menuDishFormServer;
// const foodIds = new Set<number>();
// this.menuDishFormServer.forEach((i: any) => {
// 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.selectDay.push({
label: `${i + 1}`,
value: String(i + 1),
});
this.mealCurrentIndex[i] = 0;
// if (!this.menuObject) {
// this.menuObject = {};
// }
// this.menuObject[i + 1] = meals.reduce((a, c, idx) => {
// return {
// ...a,
// [idx]: [],
// };
// }, {} as Record<number, MealDishInterface[]>);
2 years ago
return i + 1;
});
}
}
expandChange(i: number) {
if (this.expanded.has(i)) {
this.expanded.delete(i);
} else {
this.expanded.add(i);
}
}
onSaveDish(v: DishInterface[], day: number, mealIndex: number) {
this.mealDishList = JSON.parse(JSON.stringify(v));
// this.menuObject[day][mealIndex] = JSON.parse(JSON.stringify(v));
}
reuse(day: number, nzContent: TemplateRef<{}>) {
const thisDayDishs = this.mealDishList.filter((f) => f.day === day);
console.log("dayDishs", day, this.mealDishList, thisDayDishs);
this.modal.create({
nzTitle: "请选择应用到的日期",
nzContent,
nzOnOk: () => {
this.selectDay.forEach((i) => {
if (i["checked"]) {
thisDayDishs.forEach((reused) => {
this.mealDishList.push(JSON.parse(JSON.stringify({ ...reused, day: Number(i.value) })));
});
}
i["checked"] = false;
});
this.mealDishList = JSON.parse(JSON.stringify(this.mealDishList));
this.msg.success("操作成功");
},
});
}
analysis(day: number) {
2 years ago
console.log("this.days", this.days);
this.drawer.create({
nzWidth: 620,
nzWrapClassName: "analysis-drawer",
nzContent: IngredientAnalysisComponent,
nzContentParams: {
menu: {
...this.menuBaisc,
days: this.days,
},
current: {
day,
},
},
});
}
}