配餐项目前端文件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.1 KiB

2 years ago
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";
2 years ago
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";
2 years ago
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;
2 years ago
@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(""),
2 years ago
vender: new FormControl(""),
});
2 years ago
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: "提交审核时间" },
2 years ago
{ key: "operate", title: "提交人" },
]);
this.tableList = this.tableList.setOptions([
{
title: "详情",
premissions: [],
2 years ago
onClick: this.preview.bind(this),
},
{
title: "导出",
premissions: [],
2 years ago
onClick: this.export.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;
},
},
]);
}
2 years ago
preview({ id }: any) {
window.open(`/ingredient/preview?id=${id}`);
}
export({ id }: any) {
this.msg.loading("导出中...");
this.api.exportMenu(id).subscribe(() => {
setTimeout(() => {
this.msg.remove();
}, 1500);
});
}
fetchData(query: AnyObject, pager: AnyObject) {
2 years ago
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)) {
this.tableOrg = org.reduce((a, c) => {
2 years ago
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();
2 years ago
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();
2 years ago
this.onReload.emit();
},
});
}
}