|
@ -9,6 +9,12 @@ 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, map, switchMap } from "rxjs"; |
|
|
import { Subject, debounceTime, distinctUntilChanged, filter, finalize, map, switchMap } from "rxjs"; |
|
|
|
|
|
|
|
|
|
|
|
interface CheckboxItem { |
|
|
|
|
|
value: number | string; |
|
|
|
|
|
label: string; |
|
|
|
|
|
checked?: boolean; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: "app-standard-form", |
|
|
selector: "app-standard-form", |
|
|
templateUrl: "./standard-form.component.html", |
|
|
templateUrl: "./standard-form.component.html", |
|
@ -43,11 +49,11 @@ export class StandardFormComponent { |
|
|
|
|
|
|
|
|
state: any; |
|
|
state: any; |
|
|
|
|
|
|
|
|
// nzPopoverVisible = false;
|
|
|
vendors: OrgDTO[] = []; |
|
|
|
|
|
|
|
|
// vendors: OptionItemInterface[] = [];
|
|
|
// nzPopoverVisible = false;
|
|
|
|
|
|
|
|
|
listOfOption: Array<{ value: number | string; text: string }> = []; |
|
|
listOfOption: (OrgDTO & CheckboxItem)[] = []; |
|
|
|
|
|
|
|
|
nzFilterOption = (): boolean => true; |
|
|
nzFilterOption = (): boolean => true; |
|
|
|
|
|
|
|
@ -55,27 +61,32 @@ export class StandardFormComponent { |
|
|
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()]), |
|
|
vendors: this.fb.control([], [FormValidators.required()]), |
|
|
// vendors: this.fb.control([], [FormValidators.required()]),
|
|
|
overflow: this.fb.control("0", [FormValidators.required()]), |
|
|
overflow: this.fb.control("0", [FormValidators.required()]), |
|
|
}); |
|
|
}); |
|
|
if (this.state) { |
|
|
if (this.state) { |
|
|
this.formGroup.patchValue(this.state); |
|
|
this.formGroup.patchValue(this.state); |
|
|
if (Array.isArray(this.state.vendors)) { |
|
|
// if (Array.isArray(this.state.vendors)) {
|
|
|
this.api.getOrgList({ vendors: this.state.vendors }).subscribe((data) => { |
|
|
// this.api.getOrgList({ vendors: this.state.vendors }).subscribe((data) => {
|
|
|
const listOfOption: Array<{ value: number; text: string }> = []; |
|
|
// const listOfOption: Array<{ value: number; label: string }> = [];
|
|
|
data.forEach((item) => { |
|
|
// data.forEach((item) => {
|
|
|
listOfOption.push({ |
|
|
// listOfOption.push({
|
|
|
value: item.id, |
|
|
// value: item.id,
|
|
|
text: item.name, |
|
|
// label: item.name,
|
|
|
}); |
|
|
// });
|
|
|
}); |
|
|
// });
|
|
|
this.listOfOption = listOfOption; |
|
|
// this.listOfOption = listOfOption;
|
|
|
this.formGroup.patchValue(this.state); |
|
|
// this.formGroup.patchValue(this.state);
|
|
|
}); |
|
|
// });
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
} |
|
|
this.api.getOrgList().subscribe((res) => { |
|
|
this.api.getOrgList().subscribe((res) => { |
|
|
this.listOfOption = res; |
|
|
this.listOfOption = res as unknown as (OrgDTO & CheckboxItem)[]; |
|
|
|
|
|
if (Array.isArray(this.state?.vendors)) { |
|
|
|
|
|
this.listOfOption = this.listOfOption.map((i) => { |
|
|
|
|
|
return { ...i, checked: this.state.vendors.includes(i.id) }; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
// this.orgSearch$
|
|
|
// this.orgSearch$
|
|
|
// .pipe(
|
|
|
// .pipe(
|
|
@ -124,6 +135,7 @@ export class StandardFormComponent { |
|
|
foodCategoryWeek: this.state?.foodCategoryWeek, |
|
|
foodCategoryWeek: this.state?.foodCategoryWeek, |
|
|
ingredient: this.state?.ingredient, |
|
|
ingredient: this.state?.ingredient, |
|
|
...this.formGroup.value, |
|
|
...this.formGroup.value, |
|
|
|
|
|
vendors: this.listOfOption.filter((f) => f.checked).map((i) => i.id), |
|
|
}) |
|
|
}) |
|
|
.pipe( |
|
|
.pipe( |
|
|
finalize(() => { |
|
|
finalize(() => { |
|
|