|
|
@ -1,18 +1,18 @@ |
|
|
|
import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core"; |
|
|
|
import { FormControl, FormGroup } from "@angular/forms"; |
|
|
|
import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; |
|
|
|
import { AnyObject, OrgDTO, TableListOption } from "@cdk/public-api"; |
|
|
|
import { ApiService } from "@cdk/services"; |
|
|
|
import { NzModalService } from "ng-zorro-antd/modal"; |
|
|
|
import { lastValueFrom, tap } from "rxjs"; |
|
|
|
import { NzMessageService } from "ng-zorro-antd/message"; |
|
|
|
import { MyResponse } from "@cdk/types"; |
|
|
|
import { Router } from "@angular/router"; |
|
|
|
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core' |
|
|
|
import { FormControl, FormGroup } from '@angular/forms' |
|
|
|
import { NzDrawerRef, NzDrawerService } from 'ng-zorro-antd/drawer' |
|
|
|
import { AnyObject, OrgDTO, TableListOption } from '@cdk/public-api' |
|
|
|
import { ApiService } from '@cdk/services' |
|
|
|
import { NzModalService } from 'ng-zorro-antd/modal' |
|
|
|
import { lastValueFrom, tap } from 'rxjs' |
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message' |
|
|
|
import { MyResponse } from '@cdk/types' |
|
|
|
import { Router } from '@angular/router' |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: "app-ingredient-list", |
|
|
|
templateUrl: "./ingredient-list.component.html", |
|
|
|
styleUrls: ["./ingredient-list.component.less"], |
|
|
|
selector: 'app-ingredient-list', |
|
|
|
templateUrl: './ingredient-list.component.html', |
|
|
|
styleUrls: ['./ingredient-list.component.less'], |
|
|
|
}) |
|
|
|
export class IngredientListComponent { |
|
|
|
constructor( |
|
|
@ -20,77 +20,77 @@ export class IngredientListComponent { |
|
|
|
private api: ApiService, |
|
|
|
private modal: NzModalService, |
|
|
|
private msg: NzMessageService, |
|
|
|
private router: Router |
|
|
|
private router: Router, |
|
|
|
) {} |
|
|
|
|
|
|
|
globalEnum = this.api.globalEnum; |
|
|
|
globalEnum = this.api.globalEnum |
|
|
|
|
|
|
|
statusTextMap: Record<string, string> = {}; |
|
|
|
statusTextMap: Record<string, string> = {} |
|
|
|
|
|
|
|
@ViewChild("releaseStartTimeTpl") releaseStartTimeTpl!: TemplateRef<{}>; |
|
|
|
@ViewChild('releaseStartTimeTpl') releaseStartTimeTpl!: TemplateRef<{}> |
|
|
|
|
|
|
|
private drawerRef?: NzDrawerRef; |
|
|
|
private drawerRef?: NzDrawerRef |
|
|
|
|
|
|
|
public tableList = new TableListOption(this.fetchData.bind(this), { |
|
|
|
frontPagination: false, |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
public queryForm = new FormGroup({ |
|
|
|
name: new FormControl(""), |
|
|
|
vender: new FormControl(""), |
|
|
|
status: new FormControl(""), |
|
|
|
}); |
|
|
|
name: new FormControl(''), |
|
|
|
vender: new FormControl(''), |
|
|
|
status: new FormControl(''), |
|
|
|
}) |
|
|
|
|
|
|
|
startTime: Date | null = null; |
|
|
|
startTime: Date | null = null |
|
|
|
|
|
|
|
tableOrg: { [k: number]: OrgDTO } = {}; |
|
|
|
tableOrg: { [k: number]: OrgDTO } = {} |
|
|
|
|
|
|
|
monthText = { |
|
|
|
1: "一月", |
|
|
|
2: "二月", |
|
|
|
3: "三月", |
|
|
|
4: "四月", |
|
|
|
5: "五月", |
|
|
|
6: "六月", |
|
|
|
7: "七月", |
|
|
|
8: "八月", |
|
|
|
9: "九月", |
|
|
|
10: "十月", |
|
|
|
11: "十一月", |
|
|
|
12: "十二月", |
|
|
|
} as any; |
|
|
|
1: '一月', |
|
|
|
2: '二月', |
|
|
|
3: '三月', |
|
|
|
4: '四月', |
|
|
|
5: '五月', |
|
|
|
6: '六月', |
|
|
|
7: '七月', |
|
|
|
8: '八月', |
|
|
|
9: '九月', |
|
|
|
10: '十月', |
|
|
|
11: '十一月', |
|
|
|
12: '十二月', |
|
|
|
} as any |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
this.statusTextMap = this.globalEnum.menuStatus.reduce((a, c) => { |
|
|
|
return { |
|
|
|
...a, |
|
|
|
[String(c.label)]: c.value, |
|
|
|
}; |
|
|
|
}, {} as Record<string, string>); |
|
|
|
this.initTableList(); |
|
|
|
} |
|
|
|
}, {} as Record<string, string>) |
|
|
|
this.initTableList() |
|
|
|
} |
|
|
|
|
|
|
|
initTableList() { |
|
|
|
this.tableList.scroll = { x: "900px" }; |
|
|
|
this.tableList.scroll = { x: '900px' } |
|
|
|
this.tableList = this.tableList.setColumns([ |
|
|
|
{ key: "name", title: "食谱名称", width: "200px" }, |
|
|
|
{ key: "vender", title: "单位", width: "200px" }, |
|
|
|
{ key: "meals", title: "包含餐次", width: "180px" }, |
|
|
|
{ key: "month", title: "适用月份" }, |
|
|
|
{ key: "day", title: "周期" }, |
|
|
|
{ key: "status", title: "状态", width: "120px" }, |
|
|
|
{ key: "modify", title: "更新时间", width: "170px" }, |
|
|
|
{ key: "operate", title: "创建人", width: "160px" }, |
|
|
|
]); |
|
|
|
{ key: 'name', title: '食谱名称', width: '200px' }, |
|
|
|
{ key: 'vender', title: '单位', width: '200px' }, |
|
|
|
{ key: 'meals', title: '包含餐次', width: '180px' }, |
|
|
|
{ key: 'month', title: '适用月份' }, |
|
|
|
{ key: 'day', title: '周期' }, |
|
|
|
{ key: 'status', title: '状态', width: '120px' }, |
|
|
|
{ key: 'modify', title: '更新时间', width: '170px' }, |
|
|
|
{ key: 'operate', title: '创建人', width: '160px' }, |
|
|
|
]) |
|
|
|
|
|
|
|
this.tableList = this.tableList.setOptions([ |
|
|
|
{ |
|
|
|
title: "详情", |
|
|
|
title: '详情', |
|
|
|
premissions: [], |
|
|
|
onClick: this.preview.bind(this), |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: "导出", |
|
|
|
title: '导出', |
|
|
|
premissions: [], |
|
|
|
|
|
|
|
onClick: this.export.bind(this), |
|
|
@ -109,11 +109,11 @@ export class IngredientListComponent { |
|
|
|
// },
|
|
|
|
// },
|
|
|
|
{ |
|
|
|
title: "发布", |
|
|
|
title: '发布', |
|
|
|
premissions: [], |
|
|
|
onClick: this.release.bind(this), |
|
|
|
visible(v) { |
|
|
|
return [0, 2].includes(v.status); |
|
|
|
return [0, 2].includes(v.status) |
|
|
|
}, |
|
|
|
}, |
|
|
|
// {
|
|
|
@ -124,35 +124,40 @@ export class IngredientListComponent { |
|
|
|
// return [2].includes(v.status);
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// title: '复制',
|
|
|
|
// premissions: [],
|
|
|
|
// onClick: this.copy.bind(this),
|
|
|
|
// },
|
|
|
|
{ |
|
|
|
title: "编辑", |
|
|
|
title: '编辑', |
|
|
|
premissions: [], |
|
|
|
onClick: (v) => { |
|
|
|
this.router.navigate([`/ingredient/item/form/${v["id"]}`]); |
|
|
|
this.router.navigate([`/ingredient/item/form/${v['id']}`]) |
|
|
|
}, |
|
|
|
visible(v) { |
|
|
|
return [0, 3, 4].includes(v.status); |
|
|
|
return [0, 3, 4].includes(v.status) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: "删除", |
|
|
|
title: '删除', |
|
|
|
premissions: [], |
|
|
|
onClick: this.deleteItem.bind(this), |
|
|
|
}, |
|
|
|
]); |
|
|
|
]) |
|
|
|
} |
|
|
|
|
|
|
|
fetchData(query: AnyObject, pager: AnyObject) { |
|
|
|
return this.api.getMenuPage(pager, query).pipe( |
|
|
|
tap((res) => { |
|
|
|
this.getTableColumData(res); |
|
|
|
}) |
|
|
|
); |
|
|
|
this.getTableColumData(res) |
|
|
|
}), |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
getTableColumData(res: MyResponse) { |
|
|
|
if (Array.isArray(res.body.content)) { |
|
|
|
const vendors = res.body.content.map((i: any) => i.vender); |
|
|
|
const vendors = res.body.content.map((i: any) => i.vender) |
|
|
|
|
|
|
|
if (vendors.length > 0) { |
|
|
|
this.api.getOrgList({ vendors }).subscribe((org) => { |
|
|
@ -161,83 +166,102 @@ export class IngredientListComponent { |
|
|
|
return { |
|
|
|
...a, |
|
|
|
[c.id]: c, |
|
|
|
}; |
|
|
|
}, {} as AnyObject); |
|
|
|
} |
|
|
|
}, {} as AnyObject) |
|
|
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
preview({ id }: any) { |
|
|
|
window.open(`/ingredient/preview?id=${id}`); |
|
|
|
window.open(`/ingredient/preview?id=${id}`) |
|
|
|
} |
|
|
|
|
|
|
|
export({ id }: any) { |
|
|
|
this.msg.loading("导出中..."); |
|
|
|
this.msg.loading('导出中...') |
|
|
|
this.api.exportMenu(id).subscribe(() => { |
|
|
|
setTimeout(() => { |
|
|
|
this.msg.remove(); |
|
|
|
}, 1500); |
|
|
|
}); |
|
|
|
this.msg.remove() |
|
|
|
}, 1500) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
cancelFoodForm() { |
|
|
|
this.drawerRef?.close(); |
|
|
|
this.drawerRef?.close() |
|
|
|
} |
|
|
|
|
|
|
|
copy(v: AnyObject) { |
|
|
|
this.modal.confirm({ |
|
|
|
nzTitle: '警告', |
|
|
|
nzContent: '是否要复制该食谱?', |
|
|
|
nzOnOk: async () => { |
|
|
|
const res = await lastValueFrom( |
|
|
|
this.api.saveMenu({ |
|
|
|
name: v['name'] + '【复制】', |
|
|
|
nutrient: v['nutrient'], |
|
|
|
vendors: v['vendors'], |
|
|
|
month: v, |
|
|
|
}), |
|
|
|
) |
|
|
|
this.msg.success(res.desc) |
|
|
|
this.tableList.run() |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
shenhe({ id }: any) { |
|
|
|
this.modal.confirm({ |
|
|
|
nzTitle: "警告", |
|
|
|
nzTitle: '警告', |
|
|
|
nzContent: `是否要将该食谱提交审核?`, |
|
|
|
nzOnOk: async () => { |
|
|
|
const res = await lastValueFrom(this.api.submitMenuForReview(id)); |
|
|
|
this.msg.success(res.desc); |
|
|
|
this.tableList.run(); |
|
|
|
const res = await lastValueFrom(this.api.submitMenuForReview(id)) |
|
|
|
this.msg.success(res.desc) |
|
|
|
this.tableList.run() |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
release({ id, day }: any) { |
|
|
|
this.modal.create({ |
|
|
|
nzTitle: "发布食谱", |
|
|
|
nzTitle: '发布食谱', |
|
|
|
nzContent: this.releaseStartTimeTpl, |
|
|
|
nzOnOk: async () => { |
|
|
|
if (!this.startTime) { |
|
|
|
this.msg.error("请选择发布日期"); |
|
|
|
return false; |
|
|
|
this.msg.error('请选择发布日期') |
|
|
|
return false |
|
|
|
} |
|
|
|
const res = await lastValueFrom(this.api.release(id, this.startTime, day)); |
|
|
|
this.msg.success(res.desc); |
|
|
|
this.tableList.run(); |
|
|
|
return true; |
|
|
|
const res = await lastValueFrom(this.api.release(id, this.startTime, day)) |
|
|
|
this.msg.success(res.desc) |
|
|
|
this.tableList.run() |
|
|
|
return true |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
deleteItem({ id }: any) { |
|
|
|
this.modal.confirm({ |
|
|
|
nzTitle: "警告", |
|
|
|
nzTitle: '警告', |
|
|
|
nzContent: `是否要删除该食谱?`, |
|
|
|
nzOkDanger: true, |
|
|
|
nzOnOk: async () => { |
|
|
|
const res = await lastValueFrom(this.api.deleteMenu(id)); |
|
|
|
this.msg.success(res.desc); |
|
|
|
this.tableList.run(); |
|
|
|
const res = await lastValueFrom(this.api.deleteMenu(id)) |
|
|
|
this.msg.success(res.desc) |
|
|
|
this.tableList.run() |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
disableMenu({ id }: any) { |
|
|
|
this.modal.confirm({ |
|
|
|
nzTitle: "警告", |
|
|
|
nzTitle: '警告', |
|
|
|
nzContent: `是否要禁用该食谱?`, |
|
|
|
nzOkDanger: true, |
|
|
|
nzOnOk: async () => { |
|
|
|
const res = await lastValueFrom(this.api.disableMenu(id)); |
|
|
|
this.msg.success(res.desc); |
|
|
|
this.tableList.run(); |
|
|
|
const res = await lastValueFrom(this.api.disableMenu(id)) |
|
|
|
this.msg.success(res.desc) |
|
|
|
this.tableList.run() |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|