From ec1b66c8f9302f9ef87736ea63c2f1f84519fa7f Mon Sep 17 00:00:00 2001 From: kkerwin Date: Wed, 27 Sep 2023 22:24:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9F=E8=B0=B1=20=E8=8F=9C=E5=93=81=20?= =?UTF-8?q?=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ingredient-form.component.html | 4 +- .../ingredient-form.component.ts | 22 +++++++-- .../ingredient-dish.component.html | 10 ++-- .../ingredient-dish.component.ts | 46 +++++++++++++++---- .../ingredient-meals.component.ts | 4 +- projects/cdk/src/services/api.service.ts | 8 ++++ 6 files changed, 75 insertions(+), 19 deletions(-) diff --git a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html index b5e6247..89e9750 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html +++ b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html @@ -40,7 +40,9 @@
- + +
\ No newline at end of file diff --git a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts index 6088200..551120d 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts +++ b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts @@ -32,6 +32,8 @@ export class IngredientFormComponent implements OnInit { menuItem: any = null; + menuDishFormServer: any = null; + ngOnInit(): void { this.step = this.id && this.id !== "create" ? 1 : 0; this.getDetail(); @@ -44,6 +46,10 @@ export class IngredientFormComponent implements OnInit { this.menuItem = res.body; } }); + this.api.getMenuDist(this.id).subscribe((res) => { + // console.log("res", res); + this.menuDishFormServer = res.body; + }); } } @@ -75,12 +81,18 @@ export class IngredientFormComponent implements OnInit { nzData: this.menuItem, nzWidth: 650, nzOnOk: () => { - // const { menuObject } = this.menuDish; + const { mealDishList } = this.menuDish; // const serverNeed = this.formatData(menuObject); - // this.api.saveMenuDist(serverNeed).subscribe((res) => { - // this.msg.success(res.desc); - // this.router.navigate(["/ingredient/item/list"]); - // }); + console.log("mealDishList", mealDishList); + this.api + .saveMenuDist({ + menuIds: this.menuItem.menuIds ?? [this.menuItem.id], + dishes: mealDishList, + }) + .subscribe((res) => { + this.msg.success(res.desc); + this.router.navigate(["/ingredient/item/list"]); + }); }, }); } diff --git a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html index 69944a8..3b98503 100644 --- a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html +++ b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html @@ -1,5 +1,6 @@ - + + - +
- + diff --git a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts index e342598..bceb7ef 100644 --- a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts +++ b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts @@ -3,6 +3,8 @@ import { Component, Input, OnChanges, SimpleChanges, TemplateRef } from "@angula 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"; // export interface MenuObjectInterface { // [Day: number]: { @@ -30,9 +32,11 @@ export type DishInterface = Augmented<{ styleUrls: ["./ingredient-dish.component.less"], }) 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(); @@ -54,15 +58,41 @@ export class IngredientDishComponent implements OnChanges { mealDishList: DishInterface[] = []; ngOnChanges(changes: SimpleChanges): void { - if (changes["menu"]?.currentValue) { - this.initMenu(); + if (changes["menuBaisc"]?.currentValue) { + this.initMenuBasic(); + } + if (changes["menuDishFormServer"]?.currentValue) { + this.initMenuDish(); } } - initMenu() { - if (this.menu) { - const meals = this.menu.meals as string[]; - const day = this.menu.day as number; + initMenuDish() { + const foodIds = new Set(); + 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}天`, diff --git a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts index c55931d..3d2d4e9 100644 --- a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts +++ b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts @@ -40,6 +40,8 @@ export class IngredientMealsComponent implements OnChanges, OnInit { @Input() peopleGroups: string[] = []; + @Input() meals: string[] = []; + @Input() mealDishs: DishInterface[] = []; @Output() onSaveDish = new EventEmitter(); @@ -101,7 +103,7 @@ export class IngredientMealsComponent implements OnChanges, OnInit { this.mealDishs.push({ day: this.day, mealIndex: this.mealIndex, - meal: "", + meal: this.meals[this.mealIndex], dishId: dish.id, dishName: dish.name, mark: dish.marks, diff --git a/projects/cdk/src/services/api.service.ts b/projects/cdk/src/services/api.service.ts index 1376dfa..56bf6cf 100644 --- a/projects/cdk/src/services/api.service.ts +++ b/projects/cdk/src/services/api.service.ts @@ -351,6 +351,10 @@ export class ApiService { ); } + getDishLabel(id: (string | number)[]) { + const query = Utils.objectStringify({ id }); + return this.http.get>(`/api/dish?${query}`); + } saveDish(v: AnyObject) { const body = Utils.objectToFormData(v); const method = v["id"] ? "post" : "put"; @@ -409,6 +413,10 @@ export class ApiService { return this.http.delete(`/api/menu`, { body: params }); } + getMenuDist(menuId: number | string) { + return this.http.get(`/api/menu/dish?menuId=${menuId}`); + } + saveMenuDist(d: {}) { return this.http.put(`/api/menu/dish/batch`, d); }