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-label [nzRequired]="true">单位</nz-form-label>
<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-item>
</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 } = {}
allStandard: any[] = []
monthText = {
1: '一月',
2: '二月',
@ -74,6 +76,9 @@ export class IngredientListComponent {
}
}, {} as Record<string, string>)
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,

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

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

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-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>

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() ids?: string[]
nzFilterOption = (): boolean => true
value?: string | string[]

Loading…
Cancel
Save