|
@ -1,19 +1,19 @@ |
|
|
import { Component, OnInit, ViewChild } from "@angular/core"; |
|
|
import { Component, OnInit, ViewChild } from '@angular/core' |
|
|
import { ActivatedRoute, Router } from "@angular/router"; |
|
|
import { ActivatedRoute, Router } from '@angular/router' |
|
|
import { ConfirmIngredientComponent } from "@cdk/ingredient/confirm-ingredient/confirm-ingredient.component"; |
|
|
import { ConfirmIngredientComponent } from '@cdk/ingredient/confirm-ingredient/confirm-ingredient.component' |
|
|
import { IngredientAnalysisComponent } from "@cdk/ingredient/ingredient-analysis/ingredient-analysis.component"; |
|
|
import { IngredientAnalysisComponent } from '@cdk/ingredient/ingredient-analysis/ingredient-analysis.component' |
|
|
import { DishInterface, IngredientDishComponent } from "@cdk/ingredient/ingredient-dish/ingredient-dish.component"; |
|
|
import { DishInterface, IngredientDishComponent } from '@cdk/ingredient/ingredient-dish/ingredient-dish.component' |
|
|
import { ApiService } from "@cdk/services"; |
|
|
import { ApiService } from '@cdk/services' |
|
|
import { OptionItemInterface } from "@cdk/types"; |
|
|
import { OptionItemInterface } from '@cdk/types' |
|
|
import { NzDrawerService } from "ng-zorro-antd/drawer"; |
|
|
import { NzDrawerService } from 'ng-zorro-antd/drawer' |
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
import { NzMessageService } from 'ng-zorro-antd/message' |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
import { NzModalService } from 'ng-zorro-antd/modal' |
|
|
import { forkJoin } from "rxjs"; |
|
|
import { forkJoin, lastValueFrom } from 'rxjs' |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: "app-ingredient-form", |
|
|
selector: 'app-ingredient-form', |
|
|
templateUrl: "./ingredient-form.component.html", |
|
|
templateUrl: './ingredient-form.component.html', |
|
|
styleUrls: ["./ingredient-form.component.less"], |
|
|
styleUrls: ['./ingredient-form.component.less'], |
|
|
}) |
|
|
}) |
|
|
export class IngredientFormComponent implements OnInit { |
|
|
export class IngredientFormComponent implements OnInit { |
|
|
constructor( |
|
|
constructor( |
|
@ -22,58 +22,58 @@ export class IngredientFormComponent implements OnInit { |
|
|
private router: Router, |
|
|
private router: Router, |
|
|
private route: ActivatedRoute, |
|
|
private route: ActivatedRoute, |
|
|
private api: ApiService, |
|
|
private api: ApiService, |
|
|
private drawer: NzDrawerService |
|
|
private drawer: NzDrawerService, |
|
|
) { |
|
|
) { |
|
|
this.id = this.route.snapshot.paramMap.get("id"); |
|
|
this.id = this.route.snapshot.paramMap.get('id') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ViewChild("menuDish") menuDish!: IngredientDishComponent; |
|
|
@ViewChild('menuDish') menuDish!: IngredientDishComponent |
|
|
|
|
|
|
|
|
step = 0; |
|
|
step = 0 |
|
|
|
|
|
|
|
|
id: string | null = ""; |
|
|
id: string | null = '' |
|
|
|
|
|
|
|
|
menuItem: any = null; |
|
|
menuItem: any = null |
|
|
|
|
|
|
|
|
menuDishFormServer: 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() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getDetail() { |
|
|
getDetail() { |
|
|
if (this.id && this.id !== "create") { |
|
|
if (this.id && this.id !== 'create') { |
|
|
this.api.getMenuItem(this.id).subscribe((res) => { |
|
|
this.api.getMenuItem(this.id).subscribe((res) => { |
|
|
if (res.body) { |
|
|
if (res.body) { |
|
|
this.menuItem = res.body; |
|
|
this.menuItem = res.body |
|
|
} |
|
|
} |
|
|
}); |
|
|
}) |
|
|
this.api.getMenuDist(this.id).subscribe((res) => { |
|
|
this.api.getMenuDist(this.id).subscribe((res) => { |
|
|
if (Array.isArray(res.body)) { |
|
|
if (Array.isArray(res.body)) { |
|
|
res.body.forEach((d) => { |
|
|
res.body.forEach((d) => { |
|
|
d.ingredient.forEach((f: any) => { |
|
|
d.ingredient.forEach((f: any) => { |
|
|
f["groupValues"] = Object.entries(f.value).map(([peopleName, value]) => { |
|
|
f['groupValues'] = Object.entries(f.value).map(([peopleName, value]) => { |
|
|
return { |
|
|
return { |
|
|
peopleName, |
|
|
peopleName, |
|
|
value, |
|
|
value, |
|
|
}; |
|
|
} |
|
|
}); |
|
|
}) |
|
|
}); |
|
|
}) |
|
|
}); |
|
|
}) |
|
|
this.initMenuDish(res.body); |
|
|
this.initMenuDish(res.body) |
|
|
} |
|
|
} |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
initMenuDish(menuDishFormServer: any[]) { |
|
|
initMenuDish(menuDishFormServer: any[]) { |
|
|
const foodIds = new Set<number>(); |
|
|
const foodIds = new Set<number>() |
|
|
menuDishFormServer.forEach((i: any) => { |
|
|
menuDishFormServer.forEach((i: any) => { |
|
|
i.ingredient.map((food: any) => { |
|
|
i.ingredient.map((food: any) => { |
|
|
foodIds.add(food.key); |
|
|
foodIds.add(food.key) |
|
|
}); |
|
|
}) |
|
|
}); |
|
|
}) |
|
|
forkJoin([this.api.getFoodList({ keys: Array.from(foodIds) })]).subscribe(([res]) => { |
|
|
forkJoin([this.api.getFoodList({ keys: Array.from(foodIds) })]).subscribe(([res]) => { |
|
|
this.menuDishFormServer = menuDishFormServer.map((i: any) => { |
|
|
this.menuDishFormServer = menuDishFormServer.map((i: any) => { |
|
|
return { |
|
|
return { |
|
@ -81,35 +81,35 @@ export class IngredientFormComponent implements OnInit { |
|
|
dishName: i.name, |
|
|
dishName: i.name, |
|
|
mealIndex: this.menuItem.meals.findIndex((m: string) => m === i.meal), |
|
|
mealIndex: this.menuItem.meals.findIndex((m: string) => m === i.meal), |
|
|
items: i.ingredient.map((food: any) => { |
|
|
items: i.ingredient.map((food: any) => { |
|
|
const fd = res.body.find((f) => f.key === food.key); |
|
|
const fd = res.body.find((f) => f.key === food.key) |
|
|
food.foodName = fd.name; |
|
|
food.foodName = fd.name |
|
|
return food; |
|
|
return food |
|
|
}), |
|
|
}), |
|
|
}; |
|
|
} |
|
|
}); |
|
|
}) |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onStepChange(idStr: string) { |
|
|
onStepChange(idStr: string) { |
|
|
this.step = 1; |
|
|
this.step = 1 |
|
|
this.id = idStr; |
|
|
this.id = idStr |
|
|
this.getDetail(); |
|
|
this.getDetail() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createNewMenu() { |
|
|
createNewMenu() { |
|
|
this.modal.confirm({ |
|
|
this.modal.confirm({ |
|
|
nzTitle: "警告", |
|
|
nzTitle: '警告', |
|
|
nzContent: "新建食谱将清空本次所有的配餐数据,确认要清空吗?", |
|
|
nzContent: '新建食谱将清空本次所有的配餐数据,确认要清空吗?', |
|
|
nzOnOk: () => { |
|
|
nzOnOk: () => { |
|
|
this.menuDish.mealDishList = []; |
|
|
this.menuDish.mealDishList = [] |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
analysis() { |
|
|
analysis() { |
|
|
this.drawer.create({ |
|
|
this.drawer.create({ |
|
|
nzWidth: 720, |
|
|
nzWidth: 720, |
|
|
nzWrapClassName: "analysis-drawer", |
|
|
nzWrapClassName: 'analysis-drawer', |
|
|
nzContent: IngredientAnalysisComponent, |
|
|
nzContent: IngredientAnalysisComponent, |
|
|
nzContentParams: { |
|
|
nzContentParams: { |
|
|
menu: { |
|
|
menu: { |
|
@ -118,60 +118,59 @@ export class IngredientFormComponent implements OnInit { |
|
|
}, |
|
|
}, |
|
|
current: {}, |
|
|
current: {}, |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
previewMenu() { |
|
|
previewMenu() { |
|
|
const { mealDishList } = this.menuDish; |
|
|
const { mealDishList } = this.menuDish |
|
|
const snapshot = Date.now().toString(); |
|
|
const snapshot = Date.now().toString() |
|
|
sessionStorage.setItem( |
|
|
sessionStorage.setItem( |
|
|
snapshot, |
|
|
snapshot, |
|
|
JSON.stringify({ |
|
|
JSON.stringify({ |
|
|
basic: this.menuItem, |
|
|
basic: this.menuItem, |
|
|
dishs: this.formatData(mealDishList), |
|
|
dishs: this.formatData(mealDishList), |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
window.open(`/ingredient/preview?snapshot=${snapshot}`); |
|
|
window.open(`/ingredient/preview?snapshot=${snapshot}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
confirmSave() { |
|
|
confirmSave() { |
|
|
this.modal.create({ |
|
|
this.modal.create({ |
|
|
nzTitle: "确认食谱信息", |
|
|
nzTitle: '确认食谱信息', |
|
|
nzContent: ConfirmIngredientComponent, |
|
|
nzContent: ConfirmIngredientComponent, |
|
|
nzData: this.menuItem, |
|
|
nzData: this.menuItem, |
|
|
nzWidth: 650, |
|
|
nzWidth: 650, |
|
|
nzOnOk: () => { |
|
|
nzOnOk: async () => { |
|
|
const { mealDishList } = this.menuDish; |
|
|
const { mealDishList } = this.menuDish |
|
|
|
|
|
const res = await lastValueFrom( |
|
|
this.api |
|
|
this.api.saveMenuDist({ |
|
|
.saveMenuDist({ |
|
|
menuIds: this.id?.split(','), |
|
|
menuIds: this.id?.split(","), |
|
|
|
|
|
dishes: this.formatData(mealDishList), |
|
|
dishes: this.formatData(mealDishList), |
|
|
}) |
|
|
}), |
|
|
.subscribe((res) => { |
|
|
) |
|
|
this.msg.success(res.desc); |
|
|
|
|
|
this.router.navigate(["/ingredient/item/list"]); |
|
|
this.msg.success(res.desc) |
|
|
}); |
|
|
this.router.navigate(['/ingredient/item/list']) |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
formatData(d: DishInterface[]) { |
|
|
formatData(d: DishInterface[]) { |
|
|
const data: DishInterface[] = JSON.parse(JSON.stringify(d)); |
|
|
const data: DishInterface[] = JSON.parse(JSON.stringify(d)) |
|
|
data.forEach((dish) => { |
|
|
data.forEach((dish) => { |
|
|
dish["dishId"] = dish.dish; |
|
|
dish['dishId'] = dish.dish |
|
|
dish.items = dish.items.map((i) => { |
|
|
dish.items = dish.items.map((i) => { |
|
|
return { |
|
|
return { |
|
|
...i, |
|
|
...i, |
|
|
value: (i["groupValues"] as any[]).reduce((a, c) => { |
|
|
value: (i['groupValues'] as any[]).reduce((a, c) => { |
|
|
return { |
|
|
return { |
|
|
...a, |
|
|
...a, |
|
|
[c.peopleName]: c.value, |
|
|
[c.peopleName]: c.value, |
|
|
}; |
|
|
} |
|
|
}, {} as Record<string, number>), |
|
|
}, {} as Record<string, number>), |
|
|
}; |
|
|
} |
|
|
}); |
|
|
}) |
|
|
}); |
|
|
}) |
|
|
return data; |
|
|
return data |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|