|
@ -3,12 +3,31 @@ 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 { 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 = [ |
|
|
|
|
|
{ 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: "周日", |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: "app-ingredient-form-basic", |
|
|
selector: "app-ingredient-form-basic", |
|
|
templateUrl: "./ingredient-form-basic.component.html", |
|
|
templateUrl: "./ingredient-form-basic.component.html", |
|
@ -35,6 +54,8 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
|
|
|
|
|
|
formGroup!: FormGroup; |
|
|
formGroup!: FormGroup; |
|
|
|
|
|
|
|
|
|
|
|
weekday = weekday; |
|
|
|
|
|
|
|
|
meals = this.api.globalEnum.mealType; |
|
|
meals = this.api.globalEnum.mealType; |
|
|
|
|
|
|
|
|
standardOfOption: Array<OptionItemInterface> = []; |
|
|
standardOfOption: Array<OptionItemInterface> = []; |
|
@ -54,7 +75,7 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
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(1, [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()]), |
|
|
}); |
|
|
}); |
|
@ -85,7 +106,6 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
this.onStandardChange(this.menu.nutrient); |
|
|
this.onStandardChange(this.menu.nutrient); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.standardOfOption = listOfOption; |
|
|
this.standardOfOption = listOfOption; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -95,15 +115,19 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
ngOnChanges(changes: SimpleChanges): void {} |
|
|
ngOnChanges(changes: SimpleChanges): void {} |
|
|
|
|
|
|
|
|
setValues() { |
|
|
setValues() { |
|
|
|
|
|
let weekday = []; |
|
|
if (this.menu) { |
|
|
if (this.menu) { |
|
|
console.log("this.formGroup", this.formGroup, 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)); |
|
|
this.formGroup.patchValue({ |
|
|
this.formGroup.patchValue({ |
|
|
...this.menu, |
|
|
...this.menu, |
|
|
vendors: [String(this.menu.vender)], |
|
|
vendors: [String(this.menu.vender)], |
|
|
}); |
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
weekday = this.weekday.map((i) => ({ ...i, checked: i.value <= 5 })); |
|
|
} |
|
|
} |
|
|
|
|
|
this.weekday = weekday; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
ngOnDestroy(): void { |
|
@ -134,7 +158,7 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
this.api.getOrgList({ vendors: currentStandard["vendors"] }).subscribe((res) => { |
|
|
this.api.getOrgList({ vendors: currentStandard["vendors"] }).subscribe((res) => { |
|
|
this.currentOrgs = res.body.map((i) => ({ |
|
|
this.currentOrgs = res.map((i) => ({ |
|
|
...i, |
|
|
...i, |
|
|
value: String(i.id), |
|
|
value: String(i.id), |
|
|
label: i.name, |
|
|
label: i.name, |
|
@ -143,32 +167,38 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkboxToValue(data: any[]) { |
|
|
|
|
|
return data |
|
|
|
|
|
.reduce((a, c) => { |
|
|
|
|
|
return c["checked"] ? a.concat(c.value) : a; |
|
|
|
|
|
}, [] as string[]) |
|
|
|
|
|
.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"])) { |
|
|
|
|
|
this.msg.error("请选择天数"); |
|
|
|
|
|
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.currentPeoples |
|
|
crows: this.checkboxToValue(this.currentPeoples), |
|
|
.reduce((a, c) => { |
|
|
|
|
|
return c["checked"] ? a.concat(c.value) : a; |
|
|
|
|
|
}, [] as string[]) |
|
|
|
|
|
.join(","), |
|
|
|
|
|
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.meals |
|
|
meals: this.checkboxToValue(this.meals), |
|
|
.reduce((a, c) => { |
|
|
day: this.checkboxToValue(this.weekday), |
|
|
return c["checked"] ? a.concat(c.value) : a; |
|
|
|
|
|
}, [] as string[]) |
|
|
|
|
|
.join(","), |
|
|
|
|
|
}) |
|
|
}) |
|
|
.pipe( |
|
|
.pipe( |
|
|
finalize(() => { |
|
|
finalize(() => { |
|
@ -177,17 +207,15 @@ export class IngredientFormBasicComponent implements OnChanges { |
|
|
) |
|
|
) |
|
|
.subscribe((res) => { |
|
|
.subscribe((res) => { |
|
|
this.msg.success(res.desc); |
|
|
this.msg.success(res.desc); |
|
|
this.router.navigate([], { |
|
|
|
|
|
relativeTo: this.route, |
|
|
let id = this.menu?.id; |
|
|
queryParams: { newId: res.body }, |
|
|
|
|
|
queryParamsHandling: "merge", |
|
|
if (Array.isArray(res.body)) { |
|
|
}); |
|
|
id = res.body.join(","); |
|
|
this.onSave.emit({ |
|
|
this.router.navigate(["/ingredient/item/form/", id]); |
|
|
...this.formGroup.value, |
|
|
} |
|
|
meals: this.meals, |
|
|
|
|
|
menuId: res.body, |
|
|
this.onSave.emit(id); |
|
|
peoples: this.currentPeoples, |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|