From 166d2c1091ef85a476015166b2a9183ceb712663 Mon Sep 17 00:00:00 2001 From: kkerwin Date: Sun, 10 Dec 2023 22:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E6=A0=87=E5=87=86&=E5=A4=A7?= =?UTF-8?q?=E5=B1=8F=E4=BF=AE=E6=94=B9&=E9=A3=9F=E8=B0=B1=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ingredient-list.component.ts | 216 ++++++++++-------- .../standard-list/standard-list.component.ts | 23 ++ .../ingredient-dish.component.ts | 6 +- .../ingredient-meals.component.html | 26 +-- .../ingredient-meals.component.ts | 2 +- projects/cdk/src/services/api.service.ts | 10 +- .../pages/data-vis/data-vis.component.html | 19 +- .../pages/data-vis/data-vis.component.less | 6 + .../app/pages/data-vis/data-vis.component.ts | 96 ++++++-- 9 files changed, 265 insertions(+), 139 deletions(-) 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 943c07d..19bf189 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,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 = {}; + statusTextMap: Record = {} - @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); - this.initTableList(); + } + }, {} as Record) + 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() }, - }); + }) } } diff --git a/projects/admin/src/app/pages/standard/standard-list/standard-list.component.ts b/projects/admin/src/app/pages/standard/standard-list/standard-list.component.ts index 55a7439..d0f9e43 100644 --- a/projects/admin/src/app/pages/standard/standard-list/standard-list.component.ts +++ b/projects/admin/src/app/pages/standard/standard-list/standard-list.component.ts @@ -51,6 +51,11 @@ export class StandardListComponent { premissions: [], onClick: this.toSetting.bind(this), }, + { + title: '复制', + premissions: [], + onClick: this.copy.bind(this), + }, { title: '编辑', premissions: [], @@ -68,6 +73,24 @@ export class StandardListComponent { return this.api.getStandardPage(pager, query) } + copy(standard: AnyObject) { + this.modal.confirm({ + nzTitle: '警告', + nzContent: '是否要复制该标准?', + nzOnOk: async () => { + const res = await lastValueFrom( + this.api.saveStandard({ + ...standard, + name: standard['name'] + '【复制】', + id: null, + }), + ) + this.msg.success(res.desc) + this.tableList.run() + }, + }) + } + toEdit(d: AnyObject) { // this.standard.settingData$.next(d) this.router.navigate([`/standard/form/${d['id']}`], { diff --git a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts index 958562e..a7a75c6 100644 --- a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts +++ b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts @@ -107,14 +107,16 @@ export class IngredientDishComponent implements OnChanges { const meals = this.menuBaisc.meals as string[] console.log('this.menuBaisc', this.menuBaisc) const day = this.menuBaisc.day as number[] - this.days = day.map((i) => { + this.days = day.map((i, idx) => { const d = weekdayMap[i] this.selectDay.push({ label: d, value: String(i), }) this.mealCurrentIndex[i] = 0 - this.expanded.add(i) + if (idx === 0) { + this.expanded.add(i) + } // if (!this.menuObject) { // this.menuObject = {}; // } diff --git a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html index f7b9ab1..f6c1d57 100644 --- a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html +++ b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html @@ -17,20 +17,16 @@ --> -   - +   + 重量/克 - + - 菜品 - 食材 + 菜品 + 食材 {{ p }} @@ -39,16 +35,16 @@ - + - -
+ +
{{ dish['dishName'] }}
- + {{ lb }}
@@ -65,7 +61,7 @@ -->
- +
{{ food['foodName'] }} @@ -89,7 +85,7 @@ - 本餐生重总量 + 本餐生重总量 {{ $any(totalObj[p])?.toFixed(2) }} diff --git a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts index c632543..dc62c7a 100644 --- a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts +++ b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts @@ -126,7 +126,7 @@ export class IngredientMealsComponent implements OnChanges, OnInit { const { dish, foods } = this.drawerRef.getContentComponent() as AddDishToIngredientComponent this.mealDishs.push({ - dishLabel: dish.dishLabel, + label: dish.dishLabel, day: this.day, mealIndex: this.mealIndex, meal: this.meals[this.mealIndex], diff --git a/projects/cdk/src/services/api.service.ts b/projects/cdk/src/services/api.service.ts index 3a2a87e..54fe21c 100644 --- a/projects/cdk/src/services/api.service.ts +++ b/projects/cdk/src/services/api.service.ts @@ -578,12 +578,16 @@ export class ApiService { return this.http.get(`/api/menu/analysis/types?${params}`) } - getCurrentDayDataVisList() { + getCurrentWeekdays() { return this.http.get(`/api/menu/display`) } - getMenuDataVis(menuId: number) { + getMenusByDay(day: number) { + return this.http.get(`/api/menu/display?day=${day}`) + } + + getMenuDataVis(menuId: number, day: number) { // return this.http.get(`/api/menu/dish`); - return this.http.get(`/api/menu/display?menuId=${menuId}`) + return this.http.get(`/api/menu/display?menuId=${menuId}&day=${day}`) } } diff --git a/projects/client/src/app/pages/data-vis/data-vis.component.html b/projects/client/src/app/pages/data-vis/data-vis.component.html index 56af7d0..a06a322 100644 --- a/projects/client/src/app/pages/data-vis/data-vis.component.html +++ b/projects/client/src/app/pages/data-vis/data-vis.component.html @@ -4,7 +4,18 @@

{{ orgName }}食谱营养报告

-
{{ showTime }}
+
+ + + + + {{ showTime }} + +