|
@ -7,6 +7,7 @@ import { ApiService } from "@cdk/services"; |
|
|
import { Subject, debounceTime, distinctUntilChanged, filter, lastValueFrom, switchMap, takeUntil, tap } from "rxjs"; |
|
|
import { Subject, debounceTime, distinctUntilChanged, filter, lastValueFrom, switchMap, takeUntil, tap } from "rxjs"; |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
|
|
|
import { ResponseType } from "@cdk/types"; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: "app-dish", |
|
|
selector: "app-dish", |
|
@ -46,6 +47,8 @@ export class DishComponent { |
|
|
|
|
|
|
|
|
tableOrg: { [k: number]: OrgDTO } = {}; |
|
|
tableOrg: { [k: number]: OrgDTO } = {}; |
|
|
|
|
|
|
|
|
|
|
|
tableFoods: { [k: string]: any } = {}; |
|
|
|
|
|
|
|
|
listOfOption: Array<{ value: number; text: string }> = []; |
|
|
listOfOption: Array<{ value: number; text: string }> = []; |
|
|
|
|
|
|
|
|
nzFilterOption = (): boolean => true; |
|
|
nzFilterOption = (): boolean => true; |
|
@ -119,22 +122,48 @@ export class DishComponent { |
|
|
fetchData(query: AnyObject, pager: AnyObject) { |
|
|
fetchData(query: AnyObject, pager: AnyObject) { |
|
|
return this.api.getDishPage(pager, query).pipe( |
|
|
return this.api.getDishPage(pager, query).pipe( |
|
|
tap((res) => { |
|
|
tap((res) => { |
|
|
if (Array.isArray(res.body.content)) { |
|
|
this.getTableColumData(res); |
|
|
this.api.getOrgList({ vendors: res.body.content.map((i) => i.vender) }).subscribe((org) => { |
|
|
|
|
|
if (Array.isArray(org.body)) { |
|
|
|
|
|
this.tableOrg = org.body.reduce((a, c) => { |
|
|
|
|
|
return { |
|
|
|
|
|
...a, |
|
|
|
|
|
[c.id]: c, |
|
|
|
|
|
}; |
|
|
|
|
|
}, {} as AnyObject); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getTableColumData(res: ResponseType) { |
|
|
|
|
|
if (Array.isArray(res.body.content)) { |
|
|
|
|
|
const vendors = res.body.content.map((i: any) => i.vender); |
|
|
|
|
|
const foodKeys = new Set( |
|
|
|
|
|
res.body.content.reduce((a: string[], c: any) => { |
|
|
|
|
|
return a.concat(Object.keys(c.ingredient ?? {})); |
|
|
|
|
|
}, [] as string[]) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (vendors.length > 0) { |
|
|
|
|
|
this.api.getOrgList({ vendors }).subscribe((org) => { |
|
|
|
|
|
if (Array.isArray(org.body)) { |
|
|
|
|
|
this.tableOrg = org.body.reduce((a, c) => { |
|
|
|
|
|
return { |
|
|
|
|
|
...a, |
|
|
|
|
|
[c.id]: c, |
|
|
|
|
|
}; |
|
|
|
|
|
}, {} as AnyObject); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
if (foodKeys.size > 0) { |
|
|
|
|
|
this.api.getFoodList({ keys: Array.from(foodKeys) }).subscribe((foods) => { |
|
|
|
|
|
if (Array.isArray(foods.body)) { |
|
|
|
|
|
this.tableFoods = foods.body.reduce((a, c) => { |
|
|
|
|
|
return { |
|
|
|
|
|
...a, |
|
|
|
|
|
[c.key]: c, |
|
|
|
|
|
}; |
|
|
|
|
|
}, {} as AnyObject); |
|
|
|
|
|
console.log("this.tableFoods", this.tableFoods); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
showFoodForm(data?: any) { |
|
|
showFoodForm(data?: any) { |
|
|
this.drawerRef = this.drawer.create({ |
|
|
this.drawerRef = this.drawer.create({ |
|
|
nzTitle: data ? "编辑菜品" : "新增菜品", |
|
|
nzTitle: data ? "编辑菜品" : "新增菜品", |
|
@ -143,6 +172,7 @@ export class DishComponent { |
|
|
nzContentParams: { |
|
|
nzContentParams: { |
|
|
data, |
|
|
data, |
|
|
orgs: Object.values(this.tableOrg), |
|
|
orgs: Object.values(this.tableOrg), |
|
|
|
|
|
foods: Object.values(this.tableFoods), |
|
|
}, |
|
|
}, |
|
|
nzFooter: this.formFooterTpl, |
|
|
nzFooter: this.formFooterTpl, |
|
|
}); |
|
|
}); |
|
|