Browse Source

复制过滤单位

main
kely 1 year ago
parent
commit
db11e661b9
  1. 2
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html
  2. 29
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts
  3. 176
      projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html
  4. 200
      projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts
  5. 9
      projects/cdk/src/shared/components/org-select/org-select.component.html
  6. 2
      projects/cdk/src/shared/components/org-select/org-select.component.ts

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

@ -105,7 +105,7 @@
<nz-form-item class="mt-4"> <nz-form-item class="mt-4">
<nz-form-label [nzRequired]="true">单位</nz-form-label> <nz-form-label [nzRequired]="true">单位</nz-form-label>
<nz-form-control> <nz-form-control>
<app-org-select mode="multiple" formControlName="vendors"></app-org-select> <app-org-select [ids]="orgIds" mode="multiple" formControlName="vendors"></app-org-select>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
</form> </form>

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

@ -51,6 +51,8 @@ export class IngredientListComponent {
tableOrg: { [k: number]: OrgDTO } = {} tableOrg: { [k: number]: OrgDTO } = {}
allStandard: any[] = []
monthText = { monthText = {
1: '一月', 1: '一月',
2: '二月', 2: '二月',
@ -74,6 +76,9 @@ export class IngredientListComponent {
} }
}, {} as Record<string, string>) }, {} as Record<string, string>)
this.initTableList() this.initTableList()
this.api.getStandard().subscribe((res) => {
this.allStandard = res
})
} }
initTableList() { initTableList() {
@ -196,7 +201,31 @@ export class IngredientListComponent {
this.drawerRef?.close() 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) { copy(v: AnyObject) {
this.orgListWhenCopyNeed(v['nutrient'])
if (this.orgIds.length === 0) {
this.msg.error('没有符合当前营养标准的单位')
return
}
this.modal.create({ this.modal.create({
nzTitle: '复制食谱', nzTitle: '复制食谱',
nzContent: this.copyTpl, nzContent: this.copyTpl,

176
projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html

@ -1,90 +1,75 @@
<form nz-form [formGroup]="formGroup" nzLayout="vertical"> <form nz-form [formGroup]="formGroup" nzLayout="vertical">
<nz-form-item> <nz-form-item>
<nz-form-label nzRequired nzSpan="6"> <nz-form-label nzRequired nzSpan="6"> 食谱名称 </nz-form-label>
食谱名称 <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
</nz-form-label> <input nz-input placeholder="请输入食谱名称" formControlName="name" />
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> </nz-form-control>
<input nz-input placeholder="请输入食谱名称" formControlName="name" /> </nz-form-item>
</nz-form-control> <nz-form-item>
</nz-form-item> <nz-form-label nzRequired nzSpan="6"> 标准 </nz-form-label>
<nz-form-item> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<nz-form-label nzRequired nzSpan="6"> <nz-select
标准 [nzDisabled]="menu"
</nz-form-label> nzPlaceHolder="请选择标准"
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> formControlName="nutrient"
<nz-select (ngModelChange)="onStandardChange($event)"
[nzDisabled]="menu" >
nzPlaceHolder="请选择标准" <nz-option *ngFor="let o of standardOfOption" [nzLabel]="o.label" [nzValue]="o.value"> </nz-option>
formControlName="nutrient" </nz-select>
(ngModelChange)="onStandardChange($event)"> </nz-form-control>
<nz-option *ngFor="let o of standardOfOption" </nz-form-item>
[nzLabel]="o.label" <nz-form-item *ngIf="!client">
[nzValue]="o.value"> <nz-form-label nzRequired nzSpan="6"> 适用单位 </nz-form-label>
</nz-option> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
</nz-select> <nz-select
</nz-form-control> nzMode="multiple"
</nz-form-item> [nzDisabled]="menu"
<nz-form-item *ngIf="!client"> formControlName="vendors"
<nz-form-label nzRequired nzSpan="6"> nzPlaceHolder="请选择单位"
适用单位 [nzOptions]="currentOrgs"
</nz-form-label> >
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> </nz-select>
<nz-select nzMode="multiple" [nzDisabled]="menu" formControlName="vendors" nzPlaceHolder="请选择单位" </nz-form-control>
[nzOptions]="currentOrgs"> </nz-form-item>
</nz-select> <nz-form-item class="block">
</nz-form-control> <nz-form-label nzRequired nzSpan="6"> 适用月份 </nz-form-label>
</nz-form-item> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<nz-form-item class="block"> <app-month-select formControlName="month"></app-month-select>
<nz-form-label nzRequired nzSpan="6"> </nz-form-control>
适用月份 </nz-form-item>
</nz-form-label> <nz-form-item>
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> <nz-form-label nzRequired nzSpan="6"> 天数 </nz-form-label>
<app-month-select formControlName="month"></app-month-select> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
</nz-form-control> <nz-checkbox-group [(ngModel)]="weekday" [ngModelOptions]="{ standalone: true }"> </nz-checkbox-group>
</nz-form-item> </nz-form-control>
<nz-form-item> </nz-form-item>
<nz-form-label nzRequired nzSpan="6"> <nz-form-item class="block">
天数 <nz-form-label nzRequired nzSpan="6"> 餐次 </nz-form-label>
</nz-form-label> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> <nz-checkbox-group
class="flex flex-wrap checkbox-wrap"
[(ngModel)]="meals"
[ngModelOptions]="{ standalone: true }"
>
</nz-checkbox-group>
</nz-form-control>
</nz-form-item>
<nz-checkbox-group <nz-form-item class="block" *ngIf="currentPeoples.length">
<nz-form-label nzRequired nzSpan="6"> 人群显示 </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl">
<nz-checkbox-group
[(ngModel)]="currentPeoples"
[ngModelOptions]="{ standalone: true }"
class="flex flex-wrap checkbox-wrap"
>
</nz-checkbox-group>
</nz-form-control>
</nz-form-item>
[(ngModel)]="weekday" <nz-divider></nz-divider>
[ngModelOptions]="{standalone: true}">
</nz-checkbox-group> <!-- <nz-form-item>
</nz-form-control>
</nz-form-item>
<nz-form-item class="block">
<nz-form-label nzRequired nzSpan="6">
餐次
</nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<nz-checkbox-group
class="flex flex-wrap checkbox-wrap"
[(ngModel)]="meals"
[ngModelOptions]="{standalone: true}">
</nz-checkbox-group>
</nz-form-control>
</nz-form-item>
<nz-form-item class="block" *ngIf="currentPeoples.length">
<nz-form-label nzRequired nzSpan="6">
人群显示
</nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl">
<nz-checkbox-group [(ngModel)]="currentPeoples"
[ngModelOptions]="{standalone: true}"
class="flex flex-wrap checkbox-wrap">
</nz-checkbox-group>
</nz-form-control>
</nz-form-item>
<nz-divider></nz-divider>
<!-- <nz-form-item>
<nz-form-label nzRequired nzSpan="6"> <nz-form-label nzRequired nzSpan="6">
批量修改重量 批量修改重量
</nz-form-label> </nz-form-label>
@ -92,22 +77,17 @@
<nz-switch></nz-switch> <nz-switch></nz-switch>
</nz-form-control> </nz-form-control>
</nz-form-item> --> </nz-form-item> -->
<nz-form-item> <nz-form-item>
<nz-form-control>
<nz-form-control> <nz-space>
<nz-space> <button *nzSpaceItem nz-button nzType="primary" (click)="onSubmit()">确定</button>
<button *nzSpaceItem nz-button nzType="primary" (click)="onSubmit()"> <!-- <button *nzSpaceItem nz-button>
确定
</button>
<!-- <button *nzSpaceItem nz-button>
取消 取消
</button> --> </button> -->
</nz-space> </nz-space>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
</form> </form>
<ng-template #formControlErrorTpl let-control> <ng-template #formControlErrorTpl let-control>
<form-error-tips [control]="control"></form-error-tips> <form-error-tips [control]="control"></form-error-tips>
</ng-template> </ng-template>

200
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 { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'
import { FormArray, FormBuilder, FormGroup } from "@angular/forms"; import { FormArray, FormBuilder, FormGroup } from '@angular/forms'
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from '@angular/router'
import { OrgDTO } from "@cdk/dtos"; import { OrgDTO } from '@cdk/dtos'
import { ApiService } from "@cdk/services"; import { ApiService } from '@cdk/services'
import { AnyObject, OptionItemInterface } from "@cdk/types"; import { AnyObject, OptionItemInterface } from '@cdk/types'
import { Utils } from "@cdk/utils"; import { Utils } from '@cdk/utils'
import { FormValidators } from "@cdk/validators"; import { FormValidators } from '@cdk/validators'
import { NzMessageService } from "ng-zorro-antd/message"; import { NzMessageService } from 'ng-zorro-antd/message'
import { Subject, debounceTime, distinctUntilChanged, filter, finalize, switchMap, takeUntil } from "rxjs"; import { Subject, debounceTime, distinctUntilChanged, filter, finalize, switchMap, takeUntil } from 'rxjs'
export const weekday = [ export const weekday = [
{ label: "周一", value: 1, checked: false }, { label: '周一', value: 1, checked: false },
{ label: "周二", value: 2, checked: false }, { label: '周二', value: 2, checked: false },
{ label: "周三", value: 3, checked: false }, { label: '周三', value: 3, checked: false },
{ label: "周四", value: 4, checked: false }, { label: '周四', value: 4, checked: false },
{ label: "周五", value: 5, checked: false }, { label: '周五', value: 5, checked: false },
{ label: "周六", value: 6 }, { label: '周六', value: 6 },
{ label: "周日", value: 7 }, { label: '周日', value: 7 },
]; ]
export const weekdayMap: Record<number, string> = { export const weekdayMap: Record<number, string> = {
1: "周一", 1: '周一',
2: "周二", 2: '周二',
3: "周三", 3: '周三',
4: "周四", 4: '周四',
5: "周五", 5: '周五',
6: "周六", 6: '周六',
7: "周日", 7: '周日',
}; }
@Component({ @Component({
selector: "app-ingredient-form-basic", selector: 'app-ingredient-form-basic',
templateUrl: "./ingredient-form-basic.component.html", templateUrl: './ingredient-form-basic.component.html',
styleUrls: ["./ingredient-form-basic.component.less"], styleUrls: ['./ingredient-form-basic.component.less'],
}) })
export class IngredientFormBasicComponent implements OnChanges { export class IngredientFormBasicComponent implements OnChanges {
constructor( constructor(
@ -39,46 +39,48 @@ export class IngredientFormBasicComponent implements OnChanges {
private msg: NzMessageService, private msg: NzMessageService,
private api: ApiService, private api: ApiService,
private router: Router, 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<void>()
private destroy$ = new Subject<void>(); formGroup!: FormGroup
formGroup!: FormGroup; weekday = weekday
weekday = weekday; meals = this.api.globalEnum.mealType
meals = this.api.globalEnum.mealType; standardOfOption: Array<OptionItemInterface> = []
standardOfOption: Array<OptionItemInterface> = []; searchedStandard: Array<OptionItemInterface> = []
searchedStandard: Array<OptionItemInterface> = []; allOrgs: OptionItemInterface[] = []
currentOrgs: OptionItemInterface[] = []; currentOrgs: OptionItemInterface[] = []
currentPeoples: OptionItemInterface[] = []; currentPeoples: OptionItemInterface[] = []
submitLoading = false; submitLoading = false
nzFilterOption = (): boolean => true; nzFilterOption = (): boolean => true
ngOnInit(): void { ngOnInit(): void {
this.formGroup = this.fb.group({ this.formGroup = this.fb.group({
id: this.fb.control("", []), id: this.fb.control('', []),
name: this.fb.control("", [FormValidators.required()]), name: this.fb.control('', [FormValidators.required()]),
nutrient: this.fb.control("", [FormValidators.required()]), nutrient: this.fb.control('', [FormValidators.required()]),
// day: this.fb.control([], [FormValidators.required()]), // day: this.fb.control([], [FormValidators.required()]),
vendors: this.fb.control([], this.client ? [] : [FormValidators.required()]), vendors: this.fb.control([], this.client ? [] : [FormValidators.required()]),
month: this.fb.control([], [FormValidators.required()]), month: this.fb.control([], [FormValidators.required()]),
}); })
// this.standardSearch$ // this.standardSearch$
// .pipe( // .pipe(
// filter((f) => !!f), // filter((f) => !!f),
@ -109,124 +111,126 @@ export class IngredientFormBasicComponent implements OnChanges {
// this.standardOfOption = listOfOption; // this.standardOfOption = listOfOption;
// }); // });
this.api.getStandard().subscribe((res) => { this.api.getStandard().subscribe((res) => {
this.standardOfOption = res; this.standardOfOption = res
if (this.menu) { if (this.menu) {
this.onStandardChange(String(this.menu.nutrient)); this.onStandardChange(String(this.menu.nutrient))
this.setValues(); this.setValues()
} }
}); })
this.api.getOrgList().subscribe((res) => {
this.allOrgs = res.map((i) => ({
...i,
value: String(i.id),
label: i.name,
}))
})
} }
ngOnChanges(changes: SimpleChanges): void {} ngOnChanges(changes: SimpleChanges): void {}
setValues() { setValues() {
let weekday = []; let weekday = []
// console.log("this.menu", this.menu); // console.log("this.menu", this.menu);
if (this.menu) { if (this.menu) {
this.standardSearch$.next({ id: this.menu.nutrient }); this.standardSearch$.next({ id: this.menu.nutrient })
this.meals = this.meals.map((i) => (this.menu.meals.includes(i.value) ? { ...i, checked: true } : i)); 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)); weekday = this.weekday.map((i) => (this.menu.day.includes(i.value) ? { ...i, checked: true } : i))
this.formGroup.patchValue({ this.formGroup.patchValue({
...this.menu, ...this.menu,
nutrient: String(this.menu.nutrient), nutrient: String(this.menu.nutrient),
vendors: [String(this.menu.vender)], vendors: [String(this.menu.vender)],
}); })
} else { } 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 { ngOnDestroy(): void {
this.destroy$.next(); this.destroy$.next()
this.destroy$.complete(); this.destroy$.complete()
} }
ageChange() {} ageChange() {}
searchStandard(k: string) { searchStandard(k: string) {
if (k) { if (k) {
this.standardSearch$.next({ name: k }); this.standardSearch$.next({ name: k })
} }
} }
onStandardChange(v: any) { onStandardChange(v: string) {
const currentStandard = this.standardOfOption.find((f) => f.value === v); const currentStandard = this.standardOfOption.find((f) => f.value === v)
this.formGroup.patchValue({ this.formGroup.patchValue({
vendors: [], vendors: [],
}); })
if (currentStandard) { if (currentStandard) {
this.currentPeoples = Object.entries(currentStandard["ingredient"] ?? {}).map(([k, v]) => { this.currentPeoples = Object.entries(currentStandard['ingredient'] ?? {}).map(([k, v]) => {
return { return {
label: k, label: k,
value: k, value: k,
checked: this.menu?.crows?.includes(k), checked: this.menu?.crows?.includes(k),
...(v as any), ...(v as any),
}; }
}); })
if (this.client) { if (this.client) {
return; return
} }
this.api.getOrgList({ vendors: currentStandard["vendors"] }).subscribe((res) => { this.currentOrgs = this.allOrgs.filter((f) => currentStandard['vendors'].includes(f['id']))
this.currentOrgs = res.map((i) => ({
...i,
value: String(i.id),
label: i.name,
}));
});
} }
} }
checkboxToValue(data: any[]) { checkboxToValue(data: any[]) {
return data return data
.reduce((a, c) => { .reduce((a, c) => {
return c["checked"] ? a.concat(c.value) : a; return c['checked'] ? a.concat(c.value) : a
}, [] as string[]) }, [] as string[])
.join(","); .join(',')
} }
onSubmit() { onSubmit() {
if (Utils.validateFormGroup(this.formGroup)) { if (Utils.validateFormGroup(this.formGroup)) {
if (!this.meals.some((s) => s["checked"])) { if (!this.meals.some((s) => s['checked'])) {
this.msg.error("请选择餐次"); this.msg.error('请选择餐次')
return; return
} }
if (!this.weekday.some((s) => s["checked"])) { if (!this.weekday.some((s) => s['checked'])) {
this.msg.error("请选择天数"); this.msg.error('请选择天数')
return; return
} }
if (!this.currentPeoples.some((s) => s["checked"])) { if (!this.currentPeoples.some((s) => s['checked'])) {
this.msg.error("请选择人群显示"); this.msg.error('请选择人群显示')
return; return
} }
this.submitLoading = true; this.submitLoading = true
this.api this.api
.saveMenu({ .saveMenu({
...this.formGroup.value, ...this.formGroup.value,
crows: this.checkboxToValue(this.currentPeoples), crows: this.checkboxToValue(this.currentPeoples),
month: this.formGroup.value.month.join(","), month: this.formGroup.value.month.join(','),
vendors: this.formGroup.value.vendors.join(","), vendors: this.formGroup.value.vendors.join(','),
meals: this.checkboxToValue(this.meals), meals: this.checkboxToValue(this.meals),
day: this.checkboxToValue(this.weekday), day: this.checkboxToValue(this.weekday),
}) })
.pipe( .pipe(
finalize(() => { finalize(() => {
this.submitLoading = false; this.submitLoading = false
}) }),
) )
.subscribe((res) => { .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)) { if (Array.isArray(res.body)) {
id = res.body.join(","); id = res.body.join(',')
this.router.navigate(["/ingredient/item/form/", id]); this.router.navigate(['/ingredient/item/form/', id])
} }
this.onSave.emit(id); this.onSave.emit(id)
}); })
} }
} }
} }

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

@ -1,3 +1,10 @@
<nz-select nzPlaceHolder="请选择单位" [nzMode]="mode" [(ngModel)]="value" (ngModelChange)="onSelectChange($event)"> <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> <ng-container *ngFor="let o of listOfOption">
<ng-container *ngIf="ids">
<nz-option *ngIf="ids.includes(o.value)" [nzLabel]="o.label" [nzValue]="o.value"> </nz-option>
</ng-container>
<ng-container *ngIf="!ids">
<nz-option [nzLabel]="o.label" [nzValue]="o.value"> </nz-option>
</ng-container>
</ng-container>
</nz-select> </nz-select>

2
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() mode: NzSelectModeType = 'default'
@Input() ids?: string[]
nzFilterOption = (): boolean => true nzFilterOption = (): boolean => true
value?: string | string[] value?: string | string[]

Loading…
Cancel
Save