diff --git a/README.md b/README.md index daa48d3..061e501 100644 --- a/README.md +++ b/README.md @@ -56,4 +56,11 @@ To get more help on the Angular CLI use `ng help` or go check out the [Angular C # 09/18 1. /api/basic/enum 中 markType 和 venderType 重复 -2. /api/ingredient/select 需要 支持关键字 \ No newline at end of file +2. /api/ingredient/select 需要 支持关键字 + + +---------------- + +# 09/26 + +1. 食谱审核 列表需要 提交审核时间、提交人 字段 \ No newline at end of file diff --git a/projects/admin/src/app/app.module.ts b/projects/admin/src/app/app.module.ts index 0de5d61..2225a98 100644 --- a/projects/admin/src/app/app.module.ts +++ b/projects/admin/src/app/app.module.ts @@ -18,6 +18,7 @@ import { IngredientFormBasicComponent, UserListComponent, RolePermissionComponent, + IngredientStatusListComponent, } from "./components"; import { HomeComponent, @@ -69,6 +70,7 @@ registerLocaleData(zh); StandardListComponent, StandardFormComponent, StandardSettingComponent, + IngredientStatusListComponent, ], imports: [ BrowserModule, diff --git a/projects/admin/src/app/components/index.ts b/projects/admin/src/app/components/index.ts index 89e2ca5..539ddfc 100644 --- a/projects/admin/src/app/components/index.ts +++ b/projects/admin/src/app/components/index.ts @@ -7,3 +7,4 @@ export * from "./ingredient-form-basic/ingredient-form-basic.component"; export * from "./user-list/user-list.component"; export * from "./role-permission/role-permission.component"; +export * from "./ingredient-status-list/ingredient-status-list.component"; diff --git a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts b/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts index 1213efd..c74c139 100644 --- a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts +++ b/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts @@ -144,8 +144,8 @@ export class IngredientFormBasicComponent { ) .subscribe((res) => { this.msg.success(res.desc); - this.onSave.emit(); - this.router.navigate(["/ingredient/item/list"]); + this.onSave.emit({ meals: this.meals, menuId: res.body, peoples: this.currentPeoples }); + // this.router.navigate(["/ingredient/item/list"]); }); } } diff --git a/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.html b/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.html new file mode 100644 index 0000000..0f62147 --- /dev/null +++ b/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.html @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + {{data | date:'yyyy-MM-dd HH:mm:ss'}} + + + {{item}} + + + {{data}} 天 + + +
+ + + 全年 + + + + + {{monthText[item]}} + + +
+
+ + {{data}} + +
+
+
+ + + +
+ + + 驳回原因 + + + + + +
+
\ No newline at end of file diff --git a/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.less b/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.less new file mode 100644 index 0000000..e69de29 diff --git a/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.ts b/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.ts new file mode 100644 index 0000000..ab5128d --- /dev/null +++ b/projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.ts @@ -0,0 +1,139 @@ +import { Component, Input, OnInit, TemplateRef, ViewChild } from "@angular/core"; +import { FormControl, FormGroup } from "@angular/forms"; +import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; +import { AnyObject, 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 } 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; + + 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(""), + }); + + 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 }); + } + + 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(); + }, + }); + } + + 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(); + }, + }); + } +} diff --git a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html index 50bce09..3f77778 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html +++ b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html @@ -2,7 +2,7 @@
- +
diff --git a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts index 98921cb..7f3b98e 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts +++ b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts @@ -37,9 +37,9 @@ export class IngredientFormComponent implements OnInit { }); } - onStepChange() { + onStepChange(basicInfo: any) { this.step = 1; - console.log(456); + console.log(basicInfo); } shopDishForm() {} @@ -62,53 +62,3 @@ export class IngredientFormComponent implements OnInit { }); } } - -const data = { - menuId: [1, 2, 3], - dishs: [ - { - name: "番茄炒鸡蛋", - dishId: 1, - foods: [ - { - key: "001001", - isMain: false, - ingredient: [ - { name: "轻体力", value: 500 }, - { name: "重体力", value: 200 }, - ], - }, - { - key: "001002", - isMain: false, - ingredient: [ - { name: "轻体力", value: 100 }, - { name: "重体力", value: 200 }, - ], - }, - ], - }, - { - name: "另一个菜品", - dishId: 1, - foods: [ - { - key: "001001", - isMain: false, - ingredient: [ - { name: "轻体力", value: 500 }, - { name: "重体力", value: 200 }, - ], - }, - { - key: "001002", - isMain: false, - ingredient: [ - { name: "轻体力", value: 100 }, - { name: "重体力", value: 200 }, - ], - }, - ], - }, - ], -}; diff --git a/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html b/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html index fd7ef1e..bb53959 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html +++ b/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html @@ -17,14 +17,18 @@ - + - + + + + @@ -38,12 +42,19 @@ {{data | date:'yyyy-MM-dd HH:mm:ss'}} + + {{ tableOrg[data] ? tableOrg[data].name : '-'}} + + {{item}} {{data}} 天 + + {{statusTextMap[data]}} +
@@ -69,13 +80,15 @@ - - - - - + +
+ + + 发布日期 + + + + + +
\ No newline at end of file diff --git a/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts b/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts index 9e660b6..7b08fa2 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts +++ b/projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts @@ -1,9 +1,13 @@ import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core"; import { FormControl, FormGroup } from "@angular/forms"; import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; -import { AnyObject, TableListOption } from "@cdk/public-api"; +import { AnyObject, 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"; +import { MyResponse } from "@cdk/types"; @Component({ selector: "app-ingredient-list", @@ -11,9 +15,18 @@ import { ApiService } from "@cdk/services"; styleUrls: ["./ingredient-list.component.less"], }) export class IngredientListComponent { - constructor(private drawer: NzDrawerService, private api: ApiService) {} + constructor( + private drawer: NzDrawerService, + private api: ApiService, + private modal: NzModalService, + private msg: NzMessageService + ) {} - @ViewChild("foofFormFooterTpl") foofFormFooterTpl!: TemplateRef<{}>; + globalEnum = this.api.globalEnum; + + statusTextMap: Record = {}; + + @ViewChild("releaseStartTimeTpl") releaseStartTimeTpl!: TemplateRef<{}>; private drawerRef?: NzDrawerRef; @@ -25,6 +38,10 @@ export class IngredientListComponent { name: new FormControl(""), }); + startTime: Date | null = null; + + tableOrg: { [k: number]: OrgDTO } = {}; + monthText = { 1: "一月", 2: "二月", @@ -41,6 +58,12 @@ export class IngredientListComponent { } as any; ngOnInit(): void { + this.statusTextMap = this.globalEnum.menuStatus.reduce((a, c) => { + return { + ...a, + [String(c.label)]: c.value, + }; + }, {} as Record); this.initTableList(); } @@ -71,17 +94,31 @@ export class IngredientListComponent { { title: "审核", premissions: [], - onClick: this.deleteItem.bind(this), + onClick: this.shenhe.bind(this), + visible(v) { + // 0 提交审核 编辑 删除 + // 1 审核中 删除 + // 2 发布 编辑 删除 + // 3 提交审核 编辑 删除 + // 4 提交审核 编辑 删除 + return ["0", "3", "4"].includes(v.status); + }, }, { title: "发布", premissions: [], - onClick: this.deleteItem.bind(this), + onClick: this.release.bind(this), + visible(v) { + return ["2"].includes(v.status); + }, }, { title: "编辑", premissions: [], onClick: this.deleteItem.bind(this), + visible(v) { + return v.status !== "1"; + }, }, { title: "删除", @@ -92,7 +129,30 @@ export class IngredientListComponent { } fetchData(query: AnyObject, pager: AnyObject) { - return this.api.getMenuPage(pager, query); + return this.api.getMenuPage(pager, query).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) { @@ -100,7 +160,7 @@ export class IngredientListComponent { nzTitle: food ? "编辑菜品" : "新增菜品", nzWidth: 700, nzContent: DishFormComponent, - nzFooter: this.foofFormFooterTpl, + // nzFooter: this.foofFormFooterTpl, }); } @@ -108,5 +168,45 @@ export class IngredientListComponent { this.drawerRef?.close(); } - deleteItem() {} + shenhe({ id }: any) { + this.modal.confirm({ + nzTitle: "警告", + nzContent: `是否要将该食谱提交审核?`, + nzOnOk: async () => { + const res = await lastValueFrom(this.api.submitMenuForReview(id)); + this.msg.success(res.desc); + this.tableList.run(); + }, + }); + } + + release({ id, day }: any) { + this.modal.create({ + nzTitle: "发布食谱", + nzContent: this.releaseStartTimeTpl, + nzOnOk: async () => { + if (!this.startTime) { + 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; + }, + }); + } + + deleteItem({ id }: any) { + this.modal.confirm({ + nzTitle: "警告", + nzContent: `是否要删除该食谱?`, + nzOkDanger: true, + nzOnOk: async () => { + const res = await lastValueFrom(this.api.deleteMenu(id)); + this.msg.success(res.desc); + this.tableList.run(); + }, + }); + } } diff --git a/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.html b/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.html index b40215a..65c4ac2 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.html +++ b/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.html @@ -2,52 +2,16 @@ - +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{data}} - - - - - + + +
diff --git a/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.ts b/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.ts index 9ea1adf..9ddc166 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.ts +++ b/projects/admin/src/app/pages/ingredients/ingredient-review/ingredient-review.component.ts @@ -23,7 +23,7 @@ export class IngredientReviewComponent { private drawerRef?: NzDrawerRef; - status = 0; + statusIndex = 0; tempImg = "https://cdn.pixabay.com/photo/2023/08/08/18/01/butterfly-8177925_1280.jpg"; @@ -36,7 +36,7 @@ export class IngredientReviewComponent { }); ngOnInit(): void { - this.status = Number(this.route.snapshot.queryParamMap.get("status")) || 0; + this.statusIndex = Number(this.route.snapshot.queryParamMap.get("status")) || 0; this.initTableList(); } @@ -89,7 +89,7 @@ export class IngredientReviewComponent { deleteItem() {} onStatusChange(index: number) { - this.status = index; + this.statusIndex = index; this.router.navigate(["/ingredient/review"], { queryParams: { status: index, diff --git a/projects/cdk/src/services/api.service.ts b/projects/cdk/src/services/api.service.ts index 044ac9f..0abb602 100644 --- a/projects/cdk/src/services/api.service.ts +++ b/projects/cdk/src/services/api.service.ts @@ -1,6 +1,7 @@ import { HttpClient, HttpParams, HttpResponse } from "@angular/common/http"; import { Inject, Injectable, InjectionToken } from "@angular/core"; import { AnyObject, OptionItemInterface, PageResult, ResponseType } from "@cdk/types"; +import { format, addDays } from "date-fns"; import { Utils } from "@cdk/utils"; import { Observable, map, of, tap } from "rxjs"; import { @@ -72,6 +73,7 @@ export class ApiService { return { ...res.body, mealType: this._formatEnum(res.body.mealType), + menuStatus: this._formatEnum(res.body.menuStatus), }; }), tap((r) => { @@ -360,6 +362,11 @@ export class ApiService { return this.http.delete(`/api/dish`, { body: params }); } + getMenuStatusPage(p: {}, q: {}) { + const params = Utils.objectStringify({ ...p, ...q }); + return this.http.get>(`/api/menu/review?${params}`); + } + getMenuPage(p: {}, q: {}) { const params = Utils.objectStringify({ ...p, ...q }); return this.http.get>(`/api/menu?${params}`); @@ -375,4 +382,30 @@ export class ApiService { const method = v["id"] ? "post" : "put"; return this.http[method]("/api/menu", body); } + + // 提交审核 + submitMenuForReview(id: string | number) { + const params = Utils.objectToFormData({ id }); + return this.http.put(`/api/menu/review`, params); + } + + reviewMenu(id: number, pass: boolean, reason?: string) { + const params = Utils.objectToFormData({ id, pass, reason }); + return this.http.post(`/api/menu/review`, params); + } + + release(id: string | number, startTime: Date, amount: number) { + const endTime = addDays(startTime, amount); + const params = Utils.objectToFormData({ + id, + startTime: format(startTime, "yyyy-MM-dd"), + endTime: format(endTime, "yyyy-MM-dd"), + }); + return this.http.put(`/api/menu/release`, params); + } + + deleteMenu(id: string | number) { + const params = Utils.objectToFormData({ id }); + return this.http.delete(`/api/menu`, { body: params }); + } } diff --git a/projects/cdk/src/types/index.ts b/projects/cdk/src/types/index.ts index bfd3ed4..3cb9626 100644 --- a/projects/cdk/src/types/index.ts +++ b/projects/cdk/src/types/index.ts @@ -17,6 +17,7 @@ export interface ResponseType { desc: string; success: boolean; } +export type MyResponse = ResponseType; export interface TableListColumns { key: string;