Browse Source

复制食谱

main
kely 2 years ago
parent
commit
c01f8b36f5
  1. 2
      projects/admin/src/app/pages/dish/dish.component.html
  2. 2
      projects/admin/src/app/pages/dish/dish.component.ts
  3. 198
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html
  4. 44
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts
  5. 2
      projects/admin/src/app/pages/standard/standard-setting/standard-setting.component.ts
  6. 5
      projects/cdk/src/services/api.service.ts
  7. 13
      projects/cdk/src/shared/components/org-select/org-select.component.html
  8. 55
      projects/cdk/src/shared/components/org-select/org-select.component.ts
  9. 52
      projects/client/src/app/components/app-layout/app-layout.component.html
  10. 2
      projects/client/src/app/pages/dish/dish.component.html
  11. 2
      projects/client/src/app/pages/dish/dish.component.ts
  12. 199
      projects/client/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts

2
projects/admin/src/app/pages/dish/dish.component.html

@ -64,7 +64,7 @@
{{ tableOrg[data] ? tableOrg[data].name : '-' }} {{ tableOrg[data] ? tableOrg[data].name : '-' }}
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'label'"> <ng-container *ngSwitchCase="'label'">
<nz-tag *ngFor="let item of data ?? []"> <nz-tag *ngFor="let item of data ?? []" nzColor="blue">
{{ item }} {{ item }}
</nz-tag> </nz-tag>
</ng-container> </ng-container>

2
projects/admin/src/app/pages/dish/dish.component.ts

@ -115,7 +115,7 @@ export class DishComponent {
{ key: 'icon', title: '菜品图片', width: '66px' }, { key: 'icon', title: '菜品图片', width: '66px' },
{ key: 'name', title: '菜品名称' }, { key: 'name', title: '菜品名称' },
{ key: 'marks', title: '菜品标签' }, { key: 'marks', title: '菜品标签' },
{ key: 'label', title: '三低菜品标识' }, { key: 'label', title: '三低标识' },
{ key: 'poly', title: '烹饪方式' }, { key: 'poly', title: '烹饪方式' },
{ key: 'ingredient', title: '食材及含量', width: '30%' }, { key: 'ingredient', title: '食材及含量', width: '30%' },
{ key: 'vender', title: '单位' }, { key: 'vender', title: '单位' },

198
projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html

@ -1,33 +1,38 @@
<app-page> <app-page>
<ng-template #pageExtraTpl> <ng-template #pageExtraTpl>
<nz-space> <nz-space>
<a *nzSpaceItem nz-button nzType="primary" target="_blank" <a
[routerLink]="['/','ingredient','item','form','create']"> *nzSpaceItem
<i nz-icon nzType="plus"></i> nz-button
创建食谱 nzType="primary"
</a> target="_blank"
</nz-space> [routerLink]="['/', 'ingredient', 'item', 'form', 'create']"
</ng-template> >
<div class="h-full overflow-hidden bg-white rounded-lg"> <i nz-icon nzType="plus"></i>
创建食谱
<nz-card [nzBordered]="false" nzTitle="食谱库"> </a>
<table-list [props]="tableList" </nz-space>
[search]="searchTpl" </ng-template>
[action]="pageExtraTpl" <div class="h-full overflow-hidden bg-white rounded-lg">
[formGroup]="queryForm" <nz-card [nzBordered]="false" nzTitle="食谱库">
[renderColumns]="renderColumnsTpl" <table-list
optionWidth="300px"> [props]="tableList"
[search]="searchTpl"
<ng-template #actionTpl> [action]="pageExtraTpl"
<button nz-button>批量删除</button> [formGroup]="queryForm"
</ng-template> [renderColumns]="renderColumnsTpl"
<ng-template #searchTpl> optionWidth="300px"
<nz-form-item class="w-60"> >
<nz-form-control> <ng-template #actionTpl>
<app-org-select formControlName="vender"></app-org-select> <button nz-button>批量删除</button>
</nz-form-control> </ng-template>
</nz-form-item> <ng-template #searchTpl>
<!-- <nz-form-item class="w-40"> <nz-form-item class="w-60">
<nz-form-control>
<app-org-select formControlName="vender"></app-org-select>
</nz-form-control>
</nz-form-item>
<!-- <nz-form-item class="w-40">
<nz-form-control> <nz-form-control>
<nz-select nzPlaceHolder="状态" formControlName="status" [nzAllowClear]="true"> <nz-select nzPlaceHolder="状态" formControlName="status" [nzAllowClear]="true">
<nz-option *ngFor="let item of globalEnum.menuStatus" [nzValue]="item.label" <nz-option *ngFor="let item of globalEnum.menuStatus" [nzValue]="item.label"
@ -36,75 +41,72 @@
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
</nz-form-item> --> </nz-form-item> -->
<nz-form-item> <nz-form-item>
<nz-form-control> <nz-form-control>
<input nz-input placeholder="请输入食谱名称" formControlName="name" /> <input nz-input placeholder="请输入食谱名称" formControlName="name" />
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
</ng-template> </ng-template>
<ng-template #renderColumnsTpl let-data let-key="key" let-row="row"> <ng-template #renderColumnsTpl let-data let-key="key" let-row="row">
<ng-container [ngSwitch]="key"> <ng-container [ngSwitch]="key">
<ng-container *ngSwitchCase="'modify'"> <ng-container *ngSwitchCase="'modify'">
{{data | date:'yyyy-MM-dd HH:mm:ss'}} {{ data | date : 'yyyy-MM-dd HH:mm:ss' }}
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'vender'"> <ng-container *ngSwitchCase="'vender'">
{{ tableOrg[data] ? tableOrg[data].name : '-'}} {{ tableOrg[data] ? tableOrg[data].name : '-' }}
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'meals'"> <ng-container *ngSwitchCase="'meals'">
<nz-tag *ngFor="let item of data">{{item}}</nz-tag> <nz-tag *ngFor="let item of data">{{ item }}</nz-tag>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'day'"> <ng-container *ngSwitchCase="'day'"> 周{{ data }} </ng-container>
周{{data}} <ng-container *ngSwitchCase="'status'">
</ng-container> {{ statusTextMap[data] }}
<ng-container *ngSwitchCase="'status'"> </ng-container>
{{statusTextMap[data]}} <ng-container *ngSwitchCase="'month'">
</ng-container> <div class="flex flex-wrap">
<ng-container *ngSwitchCase="'month'"> <ng-container *ngIf="data.length === 12">
<div class="flex flex-wrap"> <nz-tag> 全年 </nz-tag>
<ng-container *ngIf="data.length === 12"> </ng-container>
<nz-tag> <ng-container *ngIf="data.length !== 12">
全年 <nz-tag *ngFor="let item of data" class="mb-1">
</nz-tag> {{ item }}
</ng-container> </nz-tag>
<ng-container *ngIf="data.length !== 12"> </ng-container>
<nz-tag *ngFor="let item of data" class="mb-1"> </div>
{{item}} </ng-container>
</nz-tag> <ng-container *ngSwitchDefault>
</ng-container> {{ data }}
</div> </ng-container>
</ng-container> </ng-container>
<ng-container *ngSwitchDefault> </ng-template>
{{data}} </table-list>
</ng-container> </nz-card>
</ng-container> </div>
</ng-template>
</table-list>
</nz-card>
</div>
</app-page> </app-page>
<ng-template #releaseStartTimeTpl> <ng-template #releaseStartTimeTpl>
<div nz-form> <div nz-form>
<nz-alert nzType="warning" <nz-alert nzType="warning" nzMessage="注意" [nzDescription]="warnTpl">
nzMessage="注意" <ng-template #warnTpl>
[nzDescription]="warnTpl"> <div>1、请在发布前确认配餐内容是否正确,发布即视为已完成食谱审核;</div>
<ng-template #warnTpl> <div>2、已发布的食谱无法修改,如需调整,需取消发布后进行编辑</div>
<div> </ng-template>
1、请在发布前确认配餐内容是否正确,发布即视为已完成食谱审核; </nz-alert>
</div> <nz-form-item class="mt-4">
<div> <nz-form-label nzSpan="6" [nzRequired]="true"> 发布日期 </nz-form-label>
2、已发布的食谱无法修改,如需调整,需取消发布后进行编辑 <nz-form-control nzSpan="12">
</div> <nz-date-picker class="w-full" nzPlaceHolder="请选择发布日期" [(ngModel)]="startTime"></nz-date-picker>
</ng-template> </nz-form-control>
</nz-alert> </nz-form-item>
<nz-form-item class="mt-4"> </div>
<nz-form-label nzSpan="6" [nzRequired]="true"> </ng-template>
发布日期 <ng-template #copyTpl>
</nz-form-label> <form nz-form [formGroup]="copyForm" nzLayout="vertical">
<nz-form-control nzSpan="12"> <nz-form-item class="mt-4">
<nz-date-picker class="w-full" nzPlaceHolder="请选择发布日期" [(ngModel)]="startTime"></nz-date-picker> <nz-form-label [nzRequired]="true">单位</nz-form-label>
</nz-form-control> <nz-form-control>
</nz-form-item> <app-org-select mode="multiple" formControlName="vendors"></app-org-select>
</div> </nz-form-control>
</ng-template> </nz-form-item>
</form>
</ng-template>

44
projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts

@ -1,7 +1,7 @@
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core' import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms' import { FormControl, FormGroup } from '@angular/forms'
import { NzDrawerRef, NzDrawerService } from 'ng-zorro-antd/drawer' import { NzDrawerRef, NzDrawerService } from 'ng-zorro-antd/drawer'
import { AnyObject, OrgDTO, TableListOption } from '@cdk/public-api' import { AnyObject, OrgDTO, TableListOption, Utils } from '@cdk/public-api'
import { ApiService } from '@cdk/services' import { ApiService } from '@cdk/services'
import { NzModalService } from 'ng-zorro-antd/modal' import { NzModalService } from 'ng-zorro-antd/modal'
import { lastValueFrom, tap } from 'rxjs' import { lastValueFrom, tap } from 'rxjs'
@ -29,6 +29,8 @@ export class IngredientListComponent {
@ViewChild('releaseStartTimeTpl') releaseStartTimeTpl!: TemplateRef<{}> @ViewChild('releaseStartTimeTpl') releaseStartTimeTpl!: TemplateRef<{}>
@ViewChild('copyTpl') copyTpl!: TemplateRef<{}>
private drawerRef?: NzDrawerRef private drawerRef?: NzDrawerRef
public tableList = new TableListOption(this.fetchData.bind(this), { public tableList = new TableListOption(this.fetchData.bind(this), {
@ -41,6 +43,10 @@ export class IngredientListComponent {
status: new FormControl(''), status: new FormControl(''),
}) })
public copyForm = new FormGroup({
vendors: new FormControl([]),
})
startTime: Date | null = null startTime: Date | null = null
tableOrg: { [k: number]: OrgDTO } = {} tableOrg: { [k: number]: OrgDTO } = {}
@ -92,7 +98,6 @@ export class IngredientListComponent {
{ {
title: '导出', title: '导出',
premissions: [], premissions: [],
onClick: this.export.bind(this), onClick: this.export.bind(this),
}, },
// { // {
@ -124,11 +129,11 @@ export class IngredientListComponent {
// return [2].includes(v.status); // return [2].includes(v.status);
// }, // },
// }, // },
// { {
// title: '复制', title: '复制',
// premissions: [], premissions: [],
// onClick: this.copy.bind(this), onClick: this.copy.bind(this),
// }, },
{ {
title: '编辑', title: '编辑',
premissions: [], premissions: [],
@ -192,20 +197,19 @@ export class IngredientListComponent {
} }
copy(v: AnyObject) { copy(v: AnyObject) {
this.modal.confirm({ this.modal.create({
nzTitle: '警告', nzTitle: '复制食谱',
nzContent: '是否要复制该食谱?', nzContent: this.copyTpl,
nzOnOk: async () => { nzOnOk: async () => {
const res = await lastValueFrom( if (Utils.validateFormGroup(this.copyForm)) {
this.api.saveMenu({ const copyName = v['name'] + '【复制】'
name: v['name'] + '【复制】', const vendors = this.copyForm.value.vendors?.join(',')
nutrient: v['nutrient'], const res = await lastValueFrom(this.api.copyMenu(v['id'], copyName, vendors))
vendors: v['vendors'], this.msg.success(res.desc)
month: v, this.tableList.run()
}), return true
) }
this.msg.success(res.desc) return false
this.tableList.run()
}, },
}) })
} }

2
projects/admin/src/app/pages/standard/standard-setting/standard-setting.component.ts

@ -122,7 +122,7 @@ export class StandardSettingComponent implements AfterViewInit, OnDestroy {
if (!data?.ingredient) { if (!data?.ingredient) {
return [] return []
} }
console.log('data', data) this.expand(0)
const sorts = data.crows ?? Object.keys(data.ingredient) const sorts = data.crows ?? Object.keys(data.ingredient)
return sorts.map((peopleName: string) => { return sorts.map((peopleName: string) => {
const v: any = data.ingredient[peopleName] const v: any = data.ingredient[peopleName]

5
projects/cdk/src/services/api.service.ts

@ -558,6 +558,11 @@ export class ApiService {
return this.http.get<ResponseType>(`/api/menu/analysis?${params}`) return this.http.get<ResponseType>(`/api/menu/analysis?${params}`)
} }
copyMenu(id: string, name: string, vendors: string = '') {
const params = Utils.objectToHttpParams({ id, name, vendors })
return this.http.put<ResponseType>(` /api/menu/copy`, params)
}
getAnalysisEnergy(id: string, day?: number, crow?: string) { getAnalysisEnergy(id: string, day?: number, crow?: string) {
const params = Utils.objectStringify({ id, day, crow }) const params = Utils.objectStringify({ id, day, crow })
return this.http.get<ResponseType>(`/api/menu/analysis/energy?${params}`) return this.http.get<ResponseType>(`/api/menu/analysis/energy?${params}`)

13
projects/cdk/src/shared/components/org-select/org-select.component.html

@ -1,10 +1,3 @@
<nz-select <nz-select nzPlaceHolder="请选择单位" [nzMode]="mode" [(ngModel)]="value" (ngModelChange)="onSelectChange($event)">
<nz-option *ngFor="let o of listOfOption" [nzLabel]="o.label" [nzValue]="o.value"> </nz-option>
nzPlaceHolder="请选择单位" </nz-select>
[(ngModel)]="value"
(ngModelChange)="onSelectChange($event)">
<nz-option *ngFor="let o of listOfOption" [nzLabel]="o.label"
[nzValue]="o.value">
</nz-option>
</nz-select>

55
projects/cdk/src/shared/components/org-select/org-select.component.ts

@ -1,13 +1,14 @@
import { Component, OnInit } from "@angular/core"; import { Component, Input, OnInit } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms"; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
import { ApiService } from "@cdk/services"; import { ApiService } from '@cdk/services'
import { OptionItemInterface } from "@cdk/types"; import { OptionItemInterface } from '@cdk/types'
import { Subject, debounceTime, distinctUntilChanged, filter, switchMap, takeUntil } from "rxjs"; import { NzSelectModeType } from 'ng-zorro-antd/select'
import { Subject, debounceTime, distinctUntilChanged, filter, switchMap, takeUntil } from 'rxjs'
@Component({ @Component({
selector: "app-org-select", selector: 'app-org-select',
templateUrl: "./org-select.component.html", templateUrl: './org-select.component.html',
styleUrls: ["./org-select.component.less"], styleUrls: ['./org-select.component.less'],
providers: [ providers: [
{ {
provide: NG_VALUE_ACCESSOR, provide: NG_VALUE_ACCESSOR,
@ -19,55 +20,57 @@ import { Subject, debounceTime, distinctUntilChanged, filter, switchMap, takeUnt
export class OrgSelectComponent implements OnInit, ControlValueAccessor { export class OrgSelectComponent implements OnInit, ControlValueAccessor {
constructor(private api: ApiService) {} constructor(private api: ApiService) {}
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>()
private orgSearch$ = new Subject<string>(); private orgSearch$ = new Subject<string>()
nzFilterOption = (): boolean => true; @Input() mode: NzSelectModeType = 'default'
value?: string | string[]; nzFilterOption = (): boolean => true
listOfOption: OptionItemInterface[] = []; value?: string | string[]
listOfOption: OptionItemInterface[] = []
ngOnInit(): void { ngOnInit(): void {
this.api.getOrgList().subscribe((data) => { this.api.getOrgList().subscribe((data) => {
const listOfOption: Array<OptionItemInterface> = []; const listOfOption: Array<OptionItemInterface> = []
data.forEach((item) => { data.forEach((item) => {
listOfOption.push({ listOfOption.push({
value: String(item.id), value: String(item.id),
label: item.name, label: item.name,
}); })
}); })
this.listOfOption = listOfOption; this.listOfOption = listOfOption
}); })
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.destroy$.next(); this.destroy$.next()
this.destroy$.complete(); this.destroy$.complete()
} }
onSelectChange(v: any) { onSelectChange(v: any) {
this.onChange(v); this.onChange(v)
} }
searchOrg = (k: string) => { searchOrg = (k: string) => {
this.orgSearch$.next(k); this.orgSearch$.next(k)
}; }
onChange(v: number[]) {} onChange(v: number[]) {}
ontouch(v: any) {} ontouch(v: any) {}
writeValue(v?: string[] | string): void { writeValue(v?: string[] | string): void {
this.value = v; this.value = v
} }
registerOnChange(fn: any): void { registerOnChange(fn: any): void {
this.onChange = fn; this.onChange = fn
} }
registerOnTouched(fn: any): void { registerOnTouched(fn: any): void {
this.ontouch = fn; this.ontouch = fn
} }
} }

52
projects/client/src/app/components/app-layout/app-layout.component.html

@ -7,10 +7,7 @@
<nz-header class="app-header"> <nz-header class="app-header">
<div class="flex items-center justify-between h-full"> <div class="flex items-center justify-between h-full">
<div class="logo flex items-center h-full"> <div class="logo flex items-center h-full">
<img <img class="block h-[40px] mr-1" src="../assets/images/jl-logo.png" />
class="block h-[40px] mr-1"
src="../assets/images/jl-logo.png"
/>
<span class="text-lg text-white font-bold"> <span class="text-lg text-white font-bold">
{{ appName }} {{ appName }}
</span> </span>
@ -26,31 +23,16 @@
{{ account.name }} {{ account.name }}
</button> </button>
<nz-dropdown-menu #menu="nzDropdownMenu"> <nz-dropdown-menu #menu="nzDropdownMenu">
<ul <ul nz-menu nzSelectable>
nz-menu <li nz-menu-item (click)="logout()">退出登录</li>
nzSelectable
>
<li
nz-menu-item
(click)="logout()"
>
退出登录
</li>
</ul> </ul>
</nz-dropdown-menu> </nz-dropdown-menu>
</div> </div>
</div> </div>
</nz-header> </nz-header>
<nz-layout class="app-layout-main"> <nz-layout class="app-layout-main">
<nz-sider <nz-sider nzWidth="200px" class="sider-menu" nzTheme="light">
nzWidth="200px" <ul nz-menu nzTheme="light" nzMode="inline">
class="sider-menu"
nzTheme="light"
>
<ul
nz-menu
nzMode="inline"
>
<li <li
nz-menu-item nz-menu-item
class="k-icon" class="k-icon"
@ -58,11 +40,7 @@
nzMatchRouter nzMatchRouter
*ngxPermissionsOnly="['18']" *ngxPermissionsOnly="['18']"
> >
<span <span nz-icon nzType="question-circle" nzTheme="outline"></span>
nz-icon
nzType="question-circle"
nzTheme="outline"
></span>
<span>使用流程</span> <span>使用流程</span>
</li> </li>
<li <li
@ -72,11 +50,7 @@
nzMatchRouter nzMatchRouter
*ngxPermissionsOnly="['19', '20']" *ngxPermissionsOnly="['19', '20']"
> >
<span <span nz-icon nzType="fund" nzTheme="outline"></span>
nz-icon
nzType="fund"
nzTheme="outline"
></span>
<span>大屏显示</span> <span>大屏显示</span>
</li> </li>
<!-- <li nz-menu-item [routerLink]="['/','meal-setting']" nzMatchRouter <!-- <li nz-menu-item [routerLink]="['/','meal-setting']" nzMatchRouter
@ -91,11 +65,7 @@
nzMatchRouter nzMatchRouter
*ngxPermissionsOnly="['23', '24']" *ngxPermissionsOnly="['23', '24']"
> >
<span <span nz-icon nzType="k-icon:carrot" nzTheme="outline"></span>
nz-icon
nzType="k-icon:carrot"
nzTheme="outline"
></span>
<span>食材管理</span> <span>食材管理</span>
</li> </li>
<li <li
@ -105,11 +75,7 @@
nzMatchRouter nzMatchRouter
*ngxPermissionsOnly="['25', '26']" *ngxPermissionsOnly="['25', '26']"
> >
<span <span nz-icon nzType="k-icon:food" nzTheme="outline"></span>
nz-icon
nzType="k-icon:food"
nzTheme="outline"
></span>
<span>菜品管理</span> <span>菜品管理</span>
</li> </li>

2
projects/client/src/app/pages/dish/dish.component.html

@ -73,7 +73,7 @@
{{ tableOrg[data] ? tableOrg[data].name : '-' }} {{ tableOrg[data] ? tableOrg[data].name : '-' }}
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'label'"> <ng-container *ngSwitchCase="'label'">
<nz-tag *ngFor="let item of data ?? []"> <nz-tag *ngFor="let item of data ?? []" nzColor="blue">
{{ item }} {{ item }}
</nz-tag> </nz-tag>
</ng-container> </ng-container>

2
projects/client/src/app/pages/dish/dish.component.ts

@ -93,7 +93,7 @@ export class DishComponent {
{ key: 'icon', title: '菜品图片', width: '66px' }, { key: 'icon', title: '菜品图片', width: '66px' },
{ key: 'name', title: '菜品名称' }, { key: 'name', title: '菜品名称' },
{ key: 'marks', title: '菜品标签' }, { key: 'marks', title: '菜品标签' },
{ key: 'label', title: '三低菜品标识' }, { key: 'label', title: '三低标识' },
{ key: 'poly', title: '烹饪方式' }, { key: 'poly', title: '烹饪方式' },
{ key: 'ingredient', title: '食材及含量', width: '30%' }, { key: 'ingredient', title: '食材及含量', width: '30%' },
]) ])

199
projects/client/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts

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

Loading…
Cancel
Save