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> </nz-card>
<div class="p-4"> <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> </div>
</ng-container> </ng-container>
</app-page> </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; menuItem: any = null;
menuDishFormServer: any = null;
ngOnInit(): void { ngOnInit(): void {
this.step = this.id && this.id !== "create" ? 1 : 0; this.step = this.id && this.id !== "create" ? 1 : 0;
this.getDetail(); this.getDetail();
@ -44,6 +46,10 @@ export class IngredientFormComponent implements OnInit {
this.menuItem = res.body; 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, nzData: this.menuItem,
nzWidth: 650, nzWidth: 650,
nzOnOk: () => { nzOnOk: () => {
// const { menuObject } = this.menuDish; const { mealDishList } = this.menuDish;
// const serverNeed = this.formatData(menuObject); // const serverNeed = this.formatData(menuObject);
// this.api.saveMenuDist(serverNeed).subscribe((res) => { console.log("mealDishList", mealDishList);
// this.msg.success(res.desc); this.api
// this.router.navigate(["/ingredient/item/list"]); .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> <ng-container>
<!-- {{ menuObject | json }} --> <!-- {{ menuObject | json }} -->
<nz-card <nz-card
*ngFor="let day of days" *ngFor="let day of days"
@ -31,16 +32,17 @@
<ng-container *ngIf="expanded.has(day)"> <ng-container *ngIf="expanded.has(day)">
<nz-card-tab> <nz-card-tab>
<nz-tabset nzSize="large" [(nzSelectedIndex)]="mealCurrentIndex[day]"> <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-tab>
</nz-tabset> </nz-tabset>
</nz-card-tab> </nz-card-tab>
<div class="p-4"> <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" <app-ingredient-meals *ngIf="mealCurrentIndex[day] === mealIndex"
[day]="day + 1" [day]="day + 1"
[mealIndex]="mealIndex" [mealIndex]="mealIndex"
[peopleGroups]="menu.crows" [meals]="menuBaisc.meals"
[peopleGroups]="menuBaisc.crows"
[mealDishs]="mealDishList" [mealDishs]="mealDishList"
(onSaveDish)="onSaveDish($event,day+1,mealIndex)"> (onSaveDish)="onSaveDish($event,day+1,mealIndex)">
<!-- (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 { 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}`,

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() peopleGroups: string[] = [];
@Input() meals: string[] = [];
@Input() mealDishs: DishInterface[] = []; @Input() mealDishs: DishInterface[] = [];
@Output() onSaveDish = new EventEmitter<DishInterface[]>(); @Output() onSaveDish = new EventEmitter<DishInterface[]>();
@ -101,7 +103,7 @@ export class IngredientMealsComponent implements OnChanges, OnInit {
this.mealDishs.push({ this.mealDishs.push({
day: this.day, day: this.day,
mealIndex: this.mealIndex, mealIndex: this.mealIndex,
meal: "", meal: this.meals[this.mealIndex],
dishId: dish.id, dishId: dish.id,
dishName: dish.name, dishName: dish.name,
mark: dish.marks, 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) { saveDish(v: AnyObject) {
const body = Utils.objectToFormData(v); const body = Utils.objectToFormData(v);
const method = v["id"] ? "post" : "put"; const method = v["id"] ? "post" : "put";
@ -409,6 +413,10 @@ export class ApiService {
return this.http.delete<ResponseType>(`/api/menu`, { body: params }); 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: {}) { saveMenuDist(d: {}) {
return this.http.put<ResponseType>(`/api/menu/dish/batch`, d); return this.http.put<ResponseType>(`/api/menu/dish/batch`, d);
} }

Loading…
Cancel
Save