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 32dd623..4decd66 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 @@ -105,7 +105,7 @@ 单位 - + 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 293b346..2c6c853 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 @@ -51,6 +51,8 @@ export class IngredientListComponent { tableOrg: { [k: number]: OrgDTO } = {} + allStandard: any[] = [] + monthText = { 1: '一月', 2: '二月', @@ -74,6 +76,9 @@ export class IngredientListComponent { } }, {} as Record) this.initTableList() + this.api.getStandard().subscribe((res) => { + this.allStandard = res + }) } initTableList() { @@ -196,7 +201,31 @@ export class IngredientListComponent { this.drawerRef?.close() } + /** + * 先通过食谱中的 nutrient 在 所有标准中找到对应的标准 A + * 然后在 标准A中找到所有当前标准适用的 单位id vendors + * 然后再 所有单位中根据 vendors filter + * @param orgIds + * @returns + */ + orgListWhenCopyNeed(nutrient: number) { + const standard = this.allStandard.find((sd) => sd.id === nutrient) + if (!standard) { + this.msg.error('没有找到适用当前食谱的标准') + return + } + const vendors = standard['vendors'] ?? [] + this.orgIds = vendors.map((i: any) => String(i)) + } + + orgIds: string[] = [] + copy(v: AnyObject) { + this.orgListWhenCopyNeed(v['nutrient']) + if (this.orgIds.length === 0) { + this.msg.error('没有符合当前营养标准的单位') + return + } this.modal.create({ nzTitle: '复制食谱', nzContent: this.copyTpl, diff --git a/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html index a9346ad..b3da54a 100644 --- a/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html +++ b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html @@ -1,90 +1,75 @@
- - - 食谱名称 - - - - - - - - 标准 - - - - - - - - - - - 适用单位 - - - - - - - - - 适用月份 - - - - - - - - 天数 - - + + 食谱名称 + + + + + + 标准 + + + + + + + + 适用单位 + + + + + + + 适用月份 + + + + + + 天数 + + + + + + 餐次 + + + + + - + 人群显示 + + + + + - [(ngModel)]="weekday" - [ngModelOptions]="{standalone: true}"> + - - - - - - 餐次 - - - - - - - - - - - 人群显示 - - - - - - - - - - - - - - - - - - - - - + + +
- - \ No newline at end of file + + diff --git a/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts index a24afbd..2f8c7fb 100644 --- a/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts +++ b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts @@ -1,37 +1,37 @@ -import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from "@angular/core"; -import { FormArray, FormBuilder, FormGroup } from "@angular/forms"; -import { ActivatedRoute, Router } from "@angular/router"; -import { OrgDTO } from "@cdk/dtos"; -import { ApiService } from "@cdk/services"; -import { AnyObject, OptionItemInterface } from "@cdk/types"; -import { Utils } from "@cdk/utils"; -import { FormValidators } from "@cdk/validators"; -import { NzMessageService } from "ng-zorro-antd/message"; -import { Subject, debounceTime, distinctUntilChanged, filter, finalize, switchMap, takeUntil } from "rxjs"; +import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core' +import { FormArray, FormBuilder, FormGroup } from '@angular/forms' +import { ActivatedRoute, Router } from '@angular/router' +import { OrgDTO } from '@cdk/dtos' +import { ApiService } from '@cdk/services' +import { AnyObject, OptionItemInterface } from '@cdk/types' +import { Utils } from '@cdk/utils' +import { FormValidators } from '@cdk/validators' +import { NzMessageService } from 'ng-zorro-antd/message' +import { Subject, debounceTime, distinctUntilChanged, filter, finalize, switchMap, takeUntil } from 'rxjs' export const weekday = [ - { label: "周一", value: 1, checked: false }, - { label: "周二", value: 2, checked: false }, - { label: "周三", value: 3, checked: false }, - { label: "周四", value: 4, checked: false }, - { label: "周五", value: 5, checked: false }, - { label: "周六", value: 6 }, - { label: "周日", value: 7 }, -]; + { label: '周一', value: 1, checked: false }, + { label: '周二', value: 2, checked: false }, + { label: '周三', value: 3, checked: false }, + { label: '周四', value: 4, checked: false }, + { label: '周五', value: 5, checked: false }, + { label: '周六', value: 6 }, + { label: '周日', value: 7 }, +] export const weekdayMap: Record = { - 1: "周一", - 2: "周二", - 3: "周三", - 4: "周四", - 5: "周五", - 6: "周六", - 7: "周日", -}; + 1: '周一', + 2: '周二', + 3: '周三', + 4: '周四', + 5: '周五', + 6: '周六', + 7: '周日', +} @Component({ - selector: "app-ingredient-form-basic", - templateUrl: "./ingredient-form-basic.component.html", - styleUrls: ["./ingredient-form-basic.component.less"], + selector: 'app-ingredient-form-basic', + templateUrl: './ingredient-form-basic.component.html', + styleUrls: ['./ingredient-form-basic.component.less'], }) export class IngredientFormBasicComponent implements OnChanges { constructor( @@ -39,46 +39,48 @@ export class IngredientFormBasicComponent implements OnChanges { private msg: NzMessageService, private api: ApiService, private router: Router, - private route: ActivatedRoute + private route: ActivatedRoute, ) {} - @Input() menu: any | null; + @Input() menu: any | null + + @Input() client: boolean = false - @Input() client: boolean = false; + @Output() onSave = new EventEmitter() - @Output() onSave = new EventEmitter(); + private standardSearch$ = new Subject<{ id?: string; name?: string }>() - private standardSearch$ = new Subject<{ id?: string; name?: string }>(); + private destroy$ = new Subject() - private destroy$ = new Subject(); + formGroup!: FormGroup - formGroup!: FormGroup; + weekday = weekday - weekday = weekday; + meals = this.api.globalEnum.mealType - meals = this.api.globalEnum.mealType; + standardOfOption: Array = [] - standardOfOption: Array = []; + searchedStandard: Array = [] - searchedStandard: Array = []; + allOrgs: OptionItemInterface[] = [] - currentOrgs: OptionItemInterface[] = []; + currentOrgs: OptionItemInterface[] = [] - currentPeoples: OptionItemInterface[] = []; + currentPeoples: OptionItemInterface[] = [] - submitLoading = false; + submitLoading = false - nzFilterOption = (): boolean => true; + nzFilterOption = (): boolean => true ngOnInit(): void { this.formGroup = this.fb.group({ - id: this.fb.control("", []), - name: this.fb.control("", [FormValidators.required()]), - nutrient: this.fb.control("", [FormValidators.required()]), + id: this.fb.control('', []), + name: this.fb.control('', [FormValidators.required()]), + nutrient: this.fb.control('', [FormValidators.required()]), // day: this.fb.control([], [FormValidators.required()]), vendors: this.fb.control([], this.client ? [] : [FormValidators.required()]), month: this.fb.control([], [FormValidators.required()]), - }); + }) // this.standardSearch$ // .pipe( // filter((f) => !!f), @@ -109,124 +111,126 @@ export class IngredientFormBasicComponent implements OnChanges { // this.standardOfOption = listOfOption; // }); this.api.getStandard().subscribe((res) => { - this.standardOfOption = res; + this.standardOfOption = res if (this.menu) { - this.onStandardChange(String(this.menu.nutrient)); - this.setValues(); + this.onStandardChange(String(this.menu.nutrient)) + this.setValues() } - }); + }) + + this.api.getOrgList().subscribe((res) => { + this.allOrgs = res.map((i) => ({ + ...i, + value: String(i.id), + label: i.name, + })) + }) } ngOnChanges(changes: SimpleChanges): void {} setValues() { - let weekday = []; + let weekday = [] // console.log("this.menu", this.menu); if (this.menu) { - this.standardSearch$.next({ id: this.menu.nutrient }); - this.meals = this.meals.map((i) => (this.menu.meals.includes(i.value) ? { ...i, checked: true } : i)); - weekday = this.weekday.map((i) => (this.menu.day.includes(i.value) ? { ...i, checked: true } : i)); + this.standardSearch$.next({ id: this.menu.nutrient }) + this.meals = this.meals.map((i) => (this.menu.meals.includes(i.value) ? { ...i, checked: true } : i)) + weekday = this.weekday.map((i) => (this.menu.day.includes(i.value) ? { ...i, checked: true } : i)) this.formGroup.patchValue({ ...this.menu, nutrient: String(this.menu.nutrient), vendors: [String(this.menu.vender)], - }); + }) } else { - weekday = this.weekday.map((i) => ({ ...i, checked: i.value <= 5 })); + weekday = this.weekday.map((i) => ({ ...i, checked: i.value <= 5 })) } - this.weekday = weekday; + this.weekday = weekday } ngOnDestroy(): void { - this.destroy$.next(); - this.destroy$.complete(); + this.destroy$.next() + this.destroy$.complete() } ageChange() {} searchStandard(k: string) { if (k) { - this.standardSearch$.next({ name: k }); + this.standardSearch$.next({ name: k }) } } - onStandardChange(v: any) { - const currentStandard = this.standardOfOption.find((f) => f.value === v); + onStandardChange(v: string) { + const currentStandard = this.standardOfOption.find((f) => f.value === v) this.formGroup.patchValue({ vendors: [], - }); + }) if (currentStandard) { - this.currentPeoples = Object.entries(currentStandard["ingredient"] ?? {}).map(([k, v]) => { + this.currentPeoples = Object.entries(currentStandard['ingredient'] ?? {}).map(([k, v]) => { return { label: k, value: k, checked: this.menu?.crows?.includes(k), ...(v as any), - }; - }); + } + }) if (this.client) { - return; + return } - this.api.getOrgList({ vendors: currentStandard["vendors"] }).subscribe((res) => { - this.currentOrgs = res.map((i) => ({ - ...i, - value: String(i.id), - label: i.name, - })); - }); + this.currentOrgs = this.allOrgs.filter((f) => currentStandard['vendors'].includes(f['id'])) } } checkboxToValue(data: any[]) { return data .reduce((a, c) => { - return c["checked"] ? a.concat(c.value) : a; + return c['checked'] ? a.concat(c.value) : a }, [] as string[]) - .join(","); + .join(',') } onSubmit() { if (Utils.validateFormGroup(this.formGroup)) { - if (!this.meals.some((s) => s["checked"])) { - this.msg.error("请选择餐次"); - return; + if (!this.meals.some((s) => s['checked'])) { + this.msg.error('请选择餐次') + return } - if (!this.weekday.some((s) => s["checked"])) { - this.msg.error("请选择天数"); - return; + if (!this.weekday.some((s) => s['checked'])) { + this.msg.error('请选择天数') + return } - if (!this.currentPeoples.some((s) => s["checked"])) { - this.msg.error("请选择人群显示"); - return; + if (!this.currentPeoples.some((s) => s['checked'])) { + this.msg.error('请选择人群显示') + return } - this.submitLoading = true; + this.submitLoading = true this.api .saveMenu({ ...this.formGroup.value, crows: this.checkboxToValue(this.currentPeoples), - month: this.formGroup.value.month.join(","), - vendors: this.formGroup.value.vendors.join(","), + month: this.formGroup.value.month.join(','), + vendors: this.formGroup.value.vendors.join(','), meals: this.checkboxToValue(this.meals), day: this.checkboxToValue(this.weekday), }) .pipe( finalize(() => { - this.submitLoading = false; - }) + this.submitLoading = false + }), ) .subscribe((res) => { - this.msg.success(res.desc); + this.msg.success(res.desc) - let id = this.menu?.id; + let id = this.menu?.id if (Array.isArray(res.body)) { - id = res.body.join(","); - this.router.navigate(["/ingredient/item/form/", id]); + id = res.body.join(',') + this.router.navigate(['/ingredient/item/form/', id]) } - this.onSave.emit(id); - }); + this.onSave.emit(id) + }) } } } diff --git a/projects/cdk/src/shared/components/org-select/org-select.component.html b/projects/cdk/src/shared/components/org-select/org-select.component.html index 55b46c4..c2095eb 100644 --- a/projects/cdk/src/shared/components/org-select/org-select.component.html +++ b/projects/cdk/src/shared/components/org-select/org-select.component.html @@ -1,3 +1,10 @@ - + + + + + + + + diff --git a/projects/cdk/src/shared/components/org-select/org-select.component.ts b/projects/cdk/src/shared/components/org-select/org-select.component.ts index 80358bd..78c97dd 100644 --- a/projects/cdk/src/shared/components/org-select/org-select.component.ts +++ b/projects/cdk/src/shared/components/org-select/org-select.component.ts @@ -26,6 +26,8 @@ export class OrgSelectComponent implements OnInit, ControlValueAccessor { @Input() mode: NzSelectModeType = 'default' + @Input() ids?: string[] + nzFilterOption = (): boolean => true value?: string | string[]