Browse Source

食谱 菜品 回显

main
kkerwin 2 years ago
parent
commit
ec1b66c8f9
  1. 4
      projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html
  2. 22
      projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts
  3. 10
      projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html
  4. 46
      projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts
  5. 4
      projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts
  6. 8
      projects/cdk/src/services/api.service.ts

4
projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html

@ -40,7 +40,9 @@
</nz-card>
<div class="p-4">
<app-ingredient-dish #menuDish [menu]="menuItem"></app-ingredient-dish>
<app-ingredient-dish #menuDish [menuBaisc]="menuItem"
[menuDishFormServer]="menuDishFormServer">
</app-ingredient-dish>
</div>
</ng-container>
</app-page>

22
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"]);
});
},
});
}

10
projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html

@ -1,5 +1,6 @@
<nz-spin [nzSpinning]="!menu">
<nz-spin [nzSpinning]="!menuBaisc">
<ng-container>
<!-- {{ menuObject | json }} -->
<nz-card
*ngFor="let day of days"
@ -31,16 +32,17 @@
<ng-container *ngIf="expanded.has(day)">
<nz-card-tab>
<nz-tabset nzSize="large" [(nzSelectedIndex)]="mealCurrentIndex[day]">
<nz-tab [nzTitle]="meal" *ngFor="let meal of menu.meals; let idx = index">
<nz-tab [nzTitle]="meal" *ngFor="let meal of menuBaisc.meals; let idx = index">
</nz-tab>
</nz-tabset>
</nz-card-tab>
<div class="p-4">
<ng-container *ngFor="let meal of menu.meals; let mealIndex = index ">
<ng-container *ngFor="let meal of menuBaisc.meals; let mealIndex = index ">
<app-ingredient-meals *ngIf="mealCurrentIndex[day] === mealIndex"
[day]="day + 1"
[mealIndex]="mealIndex"
[peopleGroups]="menu.crows"
[meals]="menuBaisc.meals"
[peopleGroups]="menuBaisc.crows"
[mealDishs]="mealDishList"
(onSaveDish)="onSaveDish($event,day+1,mealIndex)">
<!-- (onSaveDish)="onSaveDish($event,day+1,mealIndex)" -->

46
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<number>();
@ -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<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}`,

4
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<DishInterface[]>();
@ -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,

8
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<ResponseType<any[]>>(`/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<ResponseType>(`/api/menu`, { body: params });
}
getMenuDist(menuId: number | string) {
return this.http.get<ResponseType>(`/api/menu/dish?menuId=${menuId}`);
}
saveMenuDist(d: {}) {
return this.http.put<ResponseType>(`/api/menu/dish/batch`, d);
}

Loading…
Cancel
Save