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.
120 lines
2.9 KiB
120 lines
2.9 KiB
|
2 years ago
|
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";
|
||
|
|
|
||
|
|
// export interface MenuObjectInterface {
|
||
|
|
// [Day: number]: {
|
||
|
|
// [MealIndex: number]: MealDishInterface[];
|
||
|
|
// };
|
||
|
|
// }
|
||
|
|
|
||
|
|
export type DishInterface = Augmented<{
|
||
|
|
dishId: 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) {}
|
||
|
|
|
||
|
|
@Input() menu: 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["menu"]?.currentValue) {
|
||
|
|
this.initMenu();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
initMenu() {
|
||
|
|
if (this.menu) {
|
||
|
|
const meals = this.menu.meals as string[];
|
||
|
|
const day = this.menu.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[]>);
|
||
|
|
return i;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
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("操作成功");
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|