|
|
|
import { Component, EventEmitter, Input, OnInit, Output, TemplateRef, ViewChild } from "@angular/core";
|
|
|
|
import { FormControl, FormGroup } from "@angular/forms";
|
|
|
|
import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer";
|
|
|
|
import { AnyObject, MyResponse, OrgDTO, TableListOption } from "@cdk/public-api";
|
|
|
|
import { DishFormComponent } from "@admin/app/components";
|
|
|
|
import { ApiService } from "@cdk/services";
|
|
|
|
import { NzModalService } from "ng-zorro-antd/modal";
|
|
|
|
import { lastValueFrom, tap } from "rxjs";
|
|
|
|
import { NzMessageService } from "ng-zorro-antd/message";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-ingredient-status-list",
|
|
|
|
templateUrl: "./ingredient-status-list.component.html",
|
|
|
|
styleUrls: ["./ingredient-status-list.component.less"],
|
|
|
|
})
|
|
|
|
export class IngredientStatusListComponent {
|
|
|
|
constructor(
|
|
|
|
private drawer: NzDrawerService,
|
|
|
|
private api: ApiService,
|
|
|
|
private modal: NzModalService,
|
|
|
|
private msg: NzMessageService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
@Input() status!: number;
|
|
|
|
|
|
|
|
@Output() onReload = new EventEmitter();
|
|
|
|
|
|
|
|
reason = "";
|
|
|
|
|
|
|
|
@ViewChild("reviewFailMenuTpl") reviewFailMenuTpl!: TemplateRef<{}>;
|
|
|
|
|
|
|
|
private drawerRef?: NzDrawerRef;
|
|
|
|
|
|
|
|
public tableList = new TableListOption(this.fetchData.bind(this), {
|
|
|
|
frontPagination: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
public queryForm = new FormGroup({
|
|
|
|
name: new FormControl(""),
|
|
|
|
vender: new FormControl(""),
|
|
|
|
});
|
|
|
|
|
|
|
|
tableOrg: { [k: number]: OrgDTO } = {};
|
|
|
|
|
|
|
|
monthText = {
|
|
|
|
1: "一月",
|
|
|
|
2: "二月",
|
|
|
|
3: "三月",
|
|
|
|
4: "四月",
|
|
|
|
5: "五月",
|
|
|
|
6: "六月",
|
|
|
|
7: "七月",
|
|
|
|
8: "八月",
|
|
|
|
9: "九月",
|
|
|
|
10: "十月",
|
|
|
|
11: "十一月",
|
|
|
|
12: "十二月",
|
|
|
|
} as any;
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.initTableList();
|
|
|
|
}
|
|
|
|
|
|
|
|
initTableList() {
|
|
|
|
this.tableList.scroll = { x: null };
|
|
|
|
this.tableList = this.tableList.setColumns([
|
|
|
|
{ key: "name", title: "食谱名称" },
|
|
|
|
{ key: "vender", title: "单位" },
|
|
|
|
|
|
|
|
{ key: "modify", title: "提交审核时间" },
|
|
|
|
{ key: "modify", title: "提交人" },
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.tableList = this.tableList.setOptions([
|
|
|
|
{
|
|
|
|
title: "详情",
|
|
|
|
premissions: [],
|
|
|
|
onClick: this.showFoodForm.bind(this),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "导出",
|
|
|
|
premissions: [],
|
|
|
|
onClick: this.showFoodForm.bind(this),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "通过",
|
|
|
|
premissions: [],
|
|
|
|
onClick: this.reviewSuccessMenu.bind(this),
|
|
|
|
visible: () => {
|
|
|
|
return this.status === 1;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "驳回",
|
|
|
|
premissions: [],
|
|
|
|
onClick: this.reviewFailMenu.bind(this),
|
|
|
|
visible: () => {
|
|
|
|
return this.status === 1;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData(query: AnyObject, pager: AnyObject) {
|
|
|
|
return this.api.getMenuStatusPage(pager, { ...query, status: this.status }).pipe(
|
|
|
|
tap((res) => {
|
|
|
|
this.getTableColumData(res);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getTableColumData(res: MyResponse) {
|
|
|
|
if (Array.isArray(res.body.content)) {
|
|
|
|
const vendors = res.body.content.map((i: any) => i.vender);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
showFoodForm(food?: any) {
|
|
|
|
this.drawerRef = this.drawer.create({
|
|
|
|
nzTitle: food ? "编辑菜品" : "新增菜品",
|
|
|
|
nzWidth: 700,
|
|
|
|
nzContent: DishFormComponent,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelFoodForm() {
|
|
|
|
this.drawerRef?.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
reviewSuccessMenu({ id }: any) {
|
|
|
|
this.modal.confirm({
|
|
|
|
nzTitle: "警告",
|
|
|
|
nzContent: `是否要通过审核该食谱?`,
|
|
|
|
nzOkDanger: true,
|
|
|
|
nzOnOk: async () => {
|
|
|
|
const res = await lastValueFrom(this.api.reviewMenu(id, true));
|
|
|
|
this.msg.success(res.desc);
|
|
|
|
this.tableList.run();
|
|
|
|
this.onReload.emit();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
reviewFailMenu({ id }: any) {
|
|
|
|
this.modal.create({
|
|
|
|
nzTitle: "审核驳回",
|
|
|
|
nzContent: this.reviewFailMenuTpl,
|
|
|
|
nzOnOk: async () => {
|
|
|
|
const res = await lastValueFrom(this.api.reviewMenu(id, false, this.reason));
|
|
|
|
this.msg.success(res.desc);
|
|
|
|
this.tableList.run();
|
|
|
|
this.onReload.emit();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|