From 4e80addeece6eb3878747cee9561738e1faa83d2 Mon Sep 17 00:00:00 2001 From: kely Date: Wed, 27 Sep 2023 17:50:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9F=E8=B0=B1=20=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?=E8=8F=9C=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular.json | 3 +- projects/admin/src/app/app.module.ts | 2 - .../dish-form/dish-form.component.html | 2 +- .../dish-form/dish-form.component.ts | 34 +-- projects/admin/src/app/components/index.ts | 2 - .../src/app/pages/dish/dish.component.html | 2 +- .../src/app/pages/dish/dish.component.ts | 33 ++- .../ingredient-form.component.html | 46 +-- .../ingredient-form.component.ts | 92 ++++-- .../ingredient-list.component.html | 2 +- .../ingredient-list.component.ts | 17 +- .../standard-form/standard-form.component.ts | 12 +- .../add-dish-to-ingredient.component.html | 115 +++----- .../add-dish-to-ingredient.component.ts | 61 +++- .../confirm-ingredient.component.html | 36 +-- .../confirm-ingredient.component.ts | 59 +--- .../ingredient-dish.component.html | 60 ++++ .../ingredient-dish.component.less | 25 ++ .../ingredient-dish.component.ts | 119 ++++++++ .../ingredient-form-basic.component.html | 17 +- .../ingredient-form-basic.component.less | 0 .../ingredient-form-basic.component.ts | 57 +++- .../ingredient-meals.component.html | 279 ++++-------------- .../ingredient-meals.component.less | 6 + .../ingredient-meals.component.ts | 125 +++++++- .../cdk/src/ingredient/ingredient.module.ts | 18 +- projects/cdk/src/services/api.service.ts | 10 +- .../dish-select/dish-select.component.html | 22 ++ .../dish-select/dish-select.component.less | 0 .../dish-select/dish-select.component.ts | 97 ++++++ projects/cdk/src/shared/components/index.ts | 2 + .../month-select/month-select.component.ts | 1 + .../org-select/org-select.component.html | 13 + .../org-select/org-select.component.less | 0 .../org-select/org-select.component.ts | 81 +++++ projects/cdk/src/shared/ng-zorro.ts | 2 + projects/cdk/src/shared/shared.module.ts | 13 +- 37 files changed, 935 insertions(+), 530 deletions(-) create mode 100644 projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html create mode 100644 projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.less create mode 100644 projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts rename projects/{admin/src/app/components => cdk/src/ingredient}/ingredient-form-basic/ingredient-form-basic.component.html (87%) rename projects/{admin/src/app/components => cdk/src/ingredient}/ingredient-form-basic/ingredient-form-basic.component.less (100%) rename projects/{admin/src/app/components => cdk/src/ingredient}/ingredient-form-basic/ingredient-form-basic.component.ts (71%) create mode 100644 projects/cdk/src/shared/components/dish-select/dish-select.component.html create mode 100644 projects/cdk/src/shared/components/dish-select/dish-select.component.less create mode 100644 projects/cdk/src/shared/components/dish-select/dish-select.component.ts create mode 100644 projects/cdk/src/shared/components/org-select/org-select.component.html create mode 100644 projects/cdk/src/shared/components/org-select/org-select.component.less create mode 100644 projects/cdk/src/shared/components/org-select/org-select.component.ts diff --git a/angular.json b/angular.json index 57327a0..1fabe61 100644 --- a/angular.json +++ b/angular.json @@ -2,7 +2,8 @@ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "cli": { - "packageManager": "pnpm" + "packageManager": "pnpm", + "analytics": false }, "newProjectRoot": "projects", "projects": { diff --git a/projects/admin/src/app/app.module.ts b/projects/admin/src/app/app.module.ts index 2225a98..8a5b372 100644 --- a/projects/admin/src/app/app.module.ts +++ b/projects/admin/src/app/app.module.ts @@ -15,7 +15,6 @@ import { AppLayoutComponent, FoodFormComponent, DishFormComponent, - IngredientFormBasicComponent, UserListComponent, RolePermissionComponent, IngredientStatusListComponent, @@ -49,7 +48,6 @@ registerLocaleData(zh); AppLayoutComponent, FoodFormComponent, DishFormComponent, - IngredientFormBasicComponent, UserListComponent, RolePermissionComponent, diff --git a/projects/admin/src/app/components/dish-form/dish-form.component.html b/projects/admin/src/app/components/dish-form/dish-form.component.html index 15394e8..6bebea9 100644 --- a/projects/admin/src/app/components/dish-form/dish-form.component.html +++ b/projects/admin/src/app/components/dish-form/dish-form.component.html @@ -45,7 +45,7 @@ - + 适用月份 diff --git a/projects/admin/src/app/components/dish-form/dish-form.component.ts b/projects/admin/src/app/components/dish-form/dish-form.component.ts index 5126834..259cedd 100644 --- a/projects/admin/src/app/components/dish-form/dish-form.component.ts +++ b/projects/admin/src/app/components/dish-form/dish-form.component.ts @@ -42,25 +42,6 @@ export class DishFormComponent { globalEnum = this.api.globalEnum; - allMonth = [ - { value: 1, label: "一月", checked: false }, - { value: 2, label: "二月", checked: false }, - { value: 3, label: "三月", checked: false }, - { value: 4, label: "四月", checked: false }, - { value: 5, label: "五月", checked: false }, - { value: 6, label: "六月", checked: false }, - { value: 7, label: "七月", checked: false }, - { value: 8, label: "八月", checked: false }, - { value: 9, label: "九月", checked: false }, - { value: 10, label: "十月", checked: false }, - { value: 11, label: "十一月", checked: false }, - { value: 12, label: "十二月", checked: false }, - ]; - - allMonthChecked = false; - - indeterminate = false; - uploadLoading = false; addFoodVisible = false; @@ -124,9 +105,9 @@ export class DishFormComponent { this.orgListOfOption = this.orgs.map((i) => ({ text: i.name, value: i.id })); if (this.data) { - this.allMonth = this.allMonth.map((i) => - (this.data.month ?? []).includes(i.value) ? { ...i, checked: true } : i - ); + // this.allMonth = this.allMonth.map((i) => + // (this.data.month ?? []).includes(i.value) ? { ...i, checked: true } : i + // ); this.foods.forEach((f) => { const item = { text: f.name, value: f.key }; this.foodListOfOption.push(item); @@ -164,14 +145,7 @@ export class DishFormComponent { value: num, }); } - const month = this.allMonth - .reduce((a: any, c: any) => { - if (c.checked) { - return a.concat(Number(c.value)); - } - return a; - }, [] as number[]) - .join(","); + const month = value.month.join(","); const vendors = value.vendors?.join(",") ?? ""; values = { ...value, diff --git a/projects/admin/src/app/components/index.ts b/projects/admin/src/app/components/index.ts index 539ddfc..405ecf5 100644 --- a/projects/admin/src/app/components/index.ts +++ b/projects/admin/src/app/components/index.ts @@ -3,8 +3,6 @@ export * from "./app-layout/app-layout.component"; export * from "./food-form/food-form.component"; export * from "./dish-form/dish-form.component"; -export * from "./ingredient-form-basic/ingredient-form-basic.component"; - export * from "./user-list/user-list.component"; export * from "./role-permission/role-permission.component"; export * from "./ingredient-status-list/ingredient-status-list.component"; diff --git a/projects/admin/src/app/pages/dish/dish.component.html b/projects/admin/src/app/pages/dish/dish.component.html index 4545e81..9ef59ac 100644 --- a/projects/admin/src/app/pages/dish/dish.component.html +++ b/projects/admin/src/app/pages/dish/dish.component.html @@ -83,7 +83,7 @@ - diff --git a/projects/admin/src/app/pages/dish/dish.component.ts b/projects/admin/src/app/pages/dish/dish.component.ts index f21e49c..ea434dd 100644 --- a/projects/admin/src/app/pages/dish/dish.component.ts +++ b/projects/admin/src/app/pages/dish/dish.component.ts @@ -4,7 +4,17 @@ import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; import { AnyObject, OrgDTO, TableListOption } from "@cdk/public-api"; import { DishFormComponent } from "@admin/app/components"; import { ApiService } from "@cdk/services"; -import { Subject, debounceTime, distinctUntilChanged, filter, lastValueFrom, switchMap, takeUntil, tap } from "rxjs"; +import { + Subject, + debounceTime, + distinctUntilChanged, + filter, + finalize, + lastValueFrom, + switchMap, + takeUntil, + tap, +} from "rxjs"; import { NzModalService } from "ng-zorro-antd/modal"; import { NzMessageService } from "ng-zorro-antd/message"; import { ResponseType } from "@cdk/types"; @@ -28,6 +38,8 @@ export class DishComponent { private destroy$ = new Subject(); + private orgSearch$ = new Subject(); + public globalEnum = this.api.globalEnum; public tableList = new TableListOption(this.fetchData.bind(this), { @@ -41,8 +53,6 @@ export class DishComponent { vendors: new FormControl(""), }); - private orgSearch$ = new Subject(); - public selectedIds: string[] = []; tableOrg: { [k: number]: OrgDTO } = {}; @@ -188,11 +198,18 @@ export class DishComponent { const val = com.getValues(); if (val) { this.submitLoading = true; - this.api.saveDish(val).subscribe((res) => { - this.msg.success(res.desc); - this.tableList.run(); - this.cancelForm(); - }); + this.api + .saveDish(val) + .pipe( + finalize(() => { + this.submitLoading = false; + }) + ) + .subscribe((res) => { + this.msg.success(res.desc); + this.tableList.run(); + this.cancelForm(); + }); } } } diff --git a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html index 3f77778..b5e6247 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html +++ b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html @@ -2,11 +2,12 @@
- +
+
@@ -31,52 +32,15 @@ -
- - -
- - - 第{{i}}天 - -
-
- - - - - - - - - - - - - -
- -
-
- +
\ No newline at end of file diff --git a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts index 7f3b98e..6088200 100644 --- a/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts +++ b/projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts @@ -1,8 +1,10 @@ -import { IngredientFormBasicComponent } from "@admin/app/components"; -import { Component, OnInit } from "@angular/core"; +import { Component, OnInit, ViewChild } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { ConfirmIngredientComponent } from "@cdk/ingredient/confirm-ingredient/confirm-ingredient.component"; +import { IngredientDishComponent } from "@cdk/ingredient/ingredient-dish/ingredient-dish.component"; +import { MealDishInterface } from "@cdk/ingredient/ingredient-meals/ingredient-meals.component"; import { ApiService } from "@cdk/services"; +import { OptionItemInterface } from "@cdk/types"; import { NzMessageService } from "ng-zorro-antd/message"; import { NzModalService } from "ng-zorro-antd/modal"; @@ -20,45 +22,99 @@ export class IngredientFormComponent implements OnInit { private api: ApiService ) { this.id = this.route.snapshot.paramMap.get("id"); - console.log("this.id", this.id); } + @ViewChild("menuDish") menuDish!: IngredientDishComponent; + step = 0; id: string | null = ""; - expanded = new Set(); - - ingredients = Array.from({ length: 7 }, (_, i) => 1 + i); + menuItem: any = null; ngOnInit(): void { - this.api.getMenuItem().subscribe((res) => { - console.log("res", res); - }); + this.step = this.id && this.id !== "create" ? 1 : 0; + this.getDetail(); + } + + getDetail() { + if (this.id && this.id !== "create") { + this.api.getMenuItem(this.id).subscribe((res) => { + if (res.body) { + this.menuItem = res.body; + } + }); + } } onStepChange(basicInfo: any) { this.step = 1; - console.log(basicInfo); + this.menuItem = { + ...basicInfo, + menuIds: basicInfo.menuId, + meals: basicInfo.meals.reduce( + (a: string[], c: OptionItemInterface) => (c["checked"] ? a.concat(c.value) : a), + [] as string[] + ), + crows: basicInfo.peoples.reduce( + (a: string[], c: OptionItemInterface) => (c["checked"] ? a.concat(c.value) : a), + [] as string[] + ), + }; } shopDishForm() {} cancelForm() {} - expandChange(i: number) { - if (this.expanded.has(i)) { - this.expanded.delete(i); - } else { - this.expanded.add(i); - } - } - confirmSave() { + // console.log("this.menuItem", this.menuItem); this.modal.create({ nzTitle: "确认食谱信息", nzContent: ConfirmIngredientComponent, + nzData: this.menuItem, nzWidth: 650, + nzOnOk: () => { + // const { menuObject } = this.menuDish; + // const serverNeed = this.formatData(menuObject); + // this.api.saveMenuDist(serverNeed).subscribe((res) => { + // this.msg.success(res.desc); + // this.router.navigate(["/ingredient/item/list"]); + // }); + }, }); } + + formatData(menuObject: any) { + let dishes: any[] = []; + Object.entries(menuObject).forEach(([day, v]) => { + Object.entries(v as Record).forEach(([mealIndex, dishList]) => { + dishList.forEach((dish) => { + dishes.push({ + ...dish, + day: Number(day), + meal: this.menuItem.meals[mealIndex], + items: dish.foods.map((food) => { + return { + ...food, + value: food.groupValues.reduce((a, c) => { + return { + ...a, + [c.peopleName]: c.value, + }; + }, {} as Record), + }; + }), + }); + }); + }); + }); + + const toServer = { + menuIds: this.menuItem.menuIds ?? [this.menuItem.id], + dishes, + }; + + return toServer; + } } 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 bb53959..08bc67b 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 @@ -19,7 +19,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 7b08fa2..e0a8b7e 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 @@ -8,6 +8,7 @@ import { NzModalService } from "ng-zorro-antd/modal"; import { lastValueFrom, tap } from "rxjs"; import { NzMessageService } from "ng-zorro-antd/message"; import { MyResponse } from "@cdk/types"; +import { Router } from "@angular/router"; @Component({ selector: "app-ingredient-list", @@ -19,7 +20,8 @@ export class IngredientListComponent { private drawer: NzDrawerService, private api: ApiService, private modal: NzModalService, - private msg: NzMessageService + private msg: NzMessageService, + private router: Router ) {} globalEnum = this.api.globalEnum; @@ -36,6 +38,8 @@ export class IngredientListComponent { public queryForm = new FormGroup({ name: new FormControl(""), + vender: new FormControl(""), + status: new FormControl(""), }); startTime: Date | null = null; @@ -89,6 +93,7 @@ export class IngredientListComponent { { title: "导出", premissions: [], + onClick: this.showFoodForm.bind(this), }, { @@ -101,7 +106,7 @@ export class IngredientListComponent { // 2 发布 编辑 删除 // 3 提交审核 编辑 删除 // 4 提交审核 编辑 删除 - return ["0", "3", "4"].includes(v.status); + return [0, 3, 4].includes(v.status); }, }, { @@ -109,15 +114,17 @@ export class IngredientListComponent { premissions: [], onClick: this.release.bind(this), visible(v) { - return ["2"].includes(v.status); + return [2].includes(v.status); }, }, { title: "编辑", premissions: [], - onClick: this.deleteItem.bind(this), + onClick: (v) => { + this.router.navigate([`/ingredient/item/form/${v["id"]}`]); + }, visible(v) { - return v.status !== "1"; + return v.status !== 1; }, }, { diff --git a/projects/admin/src/app/pages/standard/standard-form/standard-form.component.ts b/projects/admin/src/app/pages/standard/standard-form/standard-form.component.ts index 4c47043..b401274 100644 --- a/projects/admin/src/app/pages/standard/standard-form/standard-form.component.ts +++ b/projects/admin/src/app/pages/standard/standard-form/standard-form.component.ts @@ -115,9 +115,13 @@ export class StandardFormComponent { onSubmit(gotoSetting?: boolean) { if (Utils.validateFormGroup(this.formGroup)) { this.submitLoading = true; - const { foodCategoryDay, foodCategoryWeek, ingredient } = this.state; this.api - .saveStandard({ foodCategoryDay, foodCategoryWeek, ingredient, ...this.formGroup.value }) + .saveStandard({ + foodCategoryDay: this.state?.foodCategoryDay, + foodCategoryWeek: this.state?.foodCategoryWeek, + ingredient: this.state?.ingredient, + ...this.formGroup.value, + }) .pipe( finalize(() => { this.submitLoading = false; @@ -126,7 +130,9 @@ export class StandardFormComponent { .subscribe((res) => { this.msg.success(res.desc); const redirectTo = gotoSetting ? ["/", "standard", "setting", res.body.id] : ["/standard/list"]; - this.router.navigate(redirectTo); + this.router.navigate(redirectTo, { + state: res.body, + }); }); } } diff --git a/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.html b/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.html index 6a7bf0f..3f2203c 100644 --- a/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.html +++ b/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.html @@ -1,24 +1,28 @@ -
+
-
+
菜品名称 - + +
-
+
菜品标签 - + + +
- + + +
- + - + 食材 - + 是否主料 - - 轻体力1 + + {{p}} - - 轻体力2 - - + - + - 味精 + {{item.foodName}} - + + - - + + + + - - - - - + + +
- \ No newline at end of file +
\ No newline at end of file diff --git a/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.ts b/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.ts index bac1a93..b6fd8bb 100644 --- a/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.ts +++ b/projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.ts @@ -1,8 +1,63 @@ -import { Component } from "@angular/core"; +import { Component, Input, OnInit } from "@angular/core"; +import { ApiService } from "@cdk/services"; + +export interface FoodInDishInterface { + foodName: string; + key: string; + isMain: boolean; + groupValues: Array<{ + peopleName: string; + value: number; + }>; + value: Record; +} @Component({ - selector: "lib-add-dish-to-ingredient", + selector: "app-add-dish-to-ingredient", templateUrl: "./add-dish-to-ingredient.component.html", styleUrls: ["./add-dish-to-ingredient.component.less"], }) -export class AddDishToIngredientComponent {} +export class AddDishToIngredientComponent implements OnInit { + constructor(private api: ApiService) {} + + @Input() peopleGroups: string[] = []; + + globalEnum = this.api.globalEnum; + + dish: any = null; + + mark: string = ""; + + foods: FoodInDishInterface[] = []; + + ngOnInit(): void { + console.log("this.peopleGroups", this.peopleGroups); + } + + onDishChange(dish: any) { + if (dish) { + this.mark = dish.marks; + this.getFoodNameByKeys(dish.ingredient); + } + } + + getFoodNameByKeys(foods: any[]) { + const keys = foods.map((i) => i.key); + this.api.getFoodList({ keys }).subscribe((res) => { + this.foods = res.body.map((i) => { + return { + foodName: i.name, + key: i.key, + isMain: foods.find((f) => f.key === i.key)?.isMain ?? false, + groupValues: this.peopleGroups.map((p) => { + return { + peopleName: p, + value: 0, + }; + }), + value: {}, + }; + }); + }); + } +} diff --git a/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.html b/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.html index 93ff90d..5a38bba 100644 --- a/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.html +++ b/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.html @@ -1,10 +1,10 @@ -
+
天数 - 7天 + {{data.day}}天 @@ -13,9 +13,7 @@ - 早餐 - 午餐 - 晚餐 + {{m}} @@ -24,30 +22,16 @@ 食谱名称 - + {{data.name}} + - + +
\ No newline at end of file diff --git a/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.ts b/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.ts index caafbd3..1e56fa9 100644 --- a/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.ts +++ b/projects/cdk/src/ingredient/confirm-ingredient/confirm-ingredient.component.ts @@ -1,7 +1,8 @@ -import { Component } from "@angular/core"; +import { Component, inject } from "@angular/core"; import { FormBuilder, FormGroup } from "@angular/forms"; import { FormValidators } from "@cdk/public-api"; import { NzMessageService } from "ng-zorro-antd/message"; +import { NZ_MODAL_DATA } from "ng-zorro-antd/modal"; @Component({ selector: "lib-confirm-ingredient", @@ -11,61 +12,11 @@ import { NzMessageService } from "ng-zorro-antd/message"; export class ConfirmIngredientComponent { constructor(private fb: FormBuilder, private msg: NzMessageService) {} - formGroup!: FormGroup; - - allMonth = [ - { value: "1", label: "一月", checked: false }, - { value: "2", label: "二月", checked: false }, - { value: "3", label: "三月", checked: false }, - { value: "4", label: "四月", checked: false }, - { value: "5", label: "五月", checked: false }, - { value: "6", label: "六月", checked: false }, - { value: "7", label: "七月", checked: false }, - { value: "8", label: "八月", checked: false }, - { value: "9", label: "九月", checked: false }, - { value: "10", label: "十月", checked: false }, - { value: "11", label: "十一月", checked: false }, - { value: "12", label: "十二月", checked: false }, - ]; - - allMonthChecked = false; + data = inject(NZ_MODAL_DATA); - indeterminate = false; + formGroup!: FormGroup; ngOnInit(): void { - this.formGroup = this.fb.group({ - id: this.fb.control("", [FormValidators.required()]), - - name: this.fb.control("", [FormValidators.required()]), - - month: this.fb.control([], [FormValidators.required()]), - }); - } - - updateAllMonthChecked() { - this.indeterminate = false; - if (this.allMonthChecked) { - this.allMonth = this.allMonth.map((item) => ({ - ...item, - checked: true, - })); - } else { - this.allMonth = this.allMonth.map((item) => ({ - ...item, - checked: false, - })); - } - } - - monthChecked() { - if (this.allMonth.every((item) => !item.checked)) { - this.allMonthChecked = false; - this.indeterminate = false; - } else if (this.allMonth.every((item) => item.checked)) { - this.allMonthChecked = true; - this.indeterminate = false; - } else { - this.indeterminate = true; - } + console.log("data", this.data); } } diff --git a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html new file mode 100644 index 0000000..69944a8 --- /dev/null +++ b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html @@ -0,0 +1,60 @@ + + + + + +
+ + + 第 {{day + 1}} 天 + +
+
+ + + + + + + + + + + + + +
+ + + + + +
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.less b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.less new file mode 100644 index 0000000..a184201 --- /dev/null +++ b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.less @@ -0,0 +1,25 @@ +.day-item { + ::ng-deep { + .ant-card-head-title { + overflow: visible; + } + } + + &.expanded { + .expanded-icon { + transform: rotate(90deg); + } + } +} + +.select-day { + display: flex; + flex-wrap: wrap; + + ::ng-deep { + >label { + margin: 0 0 12px 0; + flex-basis: 25%; + } + } +} \ No newline at end of file diff --git a/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts new file mode 100644 index 0000000..e342598 --- /dev/null +++ b/projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts @@ -0,0 +1,119 @@ +import { Component, Input, OnChanges, SimpleChanges, TemplateRef } from "@angular/core"; +// import { MealDishInterface } from "../ingredient-meals/ingredient-meals.component"; +import { NzModalService } from "ng-zorro-antd/modal"; +import { Augmented, OptionItemInterface } from "@cdk/types"; +import { NzMessageService } from "ng-zorro-antd/message"; + +// export interface MenuObjectInterface { +// [Day: number]: { +// [MealIndex: number]: MealDishInterface[]; +// }; +// } + +export type DishInterface = Augmented<{ + dishId: number; + day: number; + meal: string; + mark: string; + items: Array< + Augmented<{ + key: string; + isMain: boolean; + value: Record; + }> + >; +}>; + +@Component({ + selector: "app-ingredient-dish", + templateUrl: "./ingredient-dish.component.html", + styleUrls: ["./ingredient-dish.component.less"], +}) +export class IngredientDishComponent implements OnChanges { + constructor(private modal: NzModalService, private msg: NzMessageService) {} + + @Input() menu: any | null; + + expanded = new Set(); + + days: number[] = []; + + selectDay: OptionItemInterface[] = []; + + mealCurrentIndex: Record = {}; + + // d = { + // 1:{ + // zaocan:[ + // {dishId:1...} + // ] + // } + // } + // menuObject!: MenuObjectInterface; + + mealDishList: DishInterface[] = []; + + ngOnChanges(changes: SimpleChanges): void { + if (changes["menu"]?.currentValue) { + this.initMenu(); + } + } + + initMenu() { + if (this.menu) { + const meals = this.menu.meals as string[]; + const day = this.menu.day as number; + this.days = Array.from({ length: day }, (_, i) => { + this.selectDay.push({ + label: `第${i + 1}天`, + value: String(i + 1), + }); + this.mealCurrentIndex[i] = 0; + // if (!this.menuObject) { + // this.menuObject = {}; + // } + // this.menuObject[i + 1] = meals.reduce((a, c, idx) => { + // return { + // ...a, + // [idx]: [], + // }; + // }, {} as Record); + return i; + }); + } + } + + expandChange(i: number) { + if (this.expanded.has(i)) { + this.expanded.delete(i); + } else { + this.expanded.add(i); + } + } + + onSaveDish(v: DishInterface[], day: number, mealIndex: number) { + this.mealDishList = JSON.parse(JSON.stringify(v)); + // this.menuObject[day][mealIndex] = JSON.parse(JSON.stringify(v)); + } + + reuse(day: number, nzContent: TemplateRef<{}>) { + const thisDayDishs = this.mealDishList.filter((f) => f.day === day); + console.log("dayDishs", day, this.mealDishList, thisDayDishs); + this.modal.create({ + nzTitle: "请选择应用到的日期", + nzContent, + nzOnOk: () => { + this.selectDay.forEach((i) => { + if (i["checked"]) { + thisDayDishs.forEach((reused) => { + this.mealDishList.push(JSON.parse(JSON.stringify({ ...reused, day: Number(i.value) }))); + }); + } + i["checked"] = false; + }); + this.mealDishList = JSON.parse(JSON.stringify(this.mealDishList)); + this.msg.success("操作成功"); + }, + }); + } +} diff --git a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.html b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html similarity index 87% rename from projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.html rename to projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html index 24af14a..2146d52 100644 --- a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.html +++ b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html @@ -13,6 +13,7 @@ - @@ -52,13 +53,13 @@ - - - - - - - + + + + + + + diff --git a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.less b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.less similarity index 100% rename from projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.less rename to projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.less diff --git a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts similarity index 71% rename from projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts rename to projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts index c74c139..d63d723 100644 --- a/projects/admin/src/app/components/ingredient-form-basic/ingredient-form-basic.component.ts +++ b/projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts @@ -1,6 +1,5 @@ -import { Component, EventEmitter, OnInit, Output } from "@angular/core"; +import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from "@angular/core"; import { FormArray, FormBuilder, FormGroup } from "@angular/forms"; -import { Router } from "@angular/router"; import { OrgDTO } from "@cdk/dtos"; import { ApiService } from "@cdk/services"; import { OptionItemInterface } from "@cdk/types"; @@ -14,17 +13,14 @@ import { Subject, debounceTime, distinctUntilChanged, filter, finalize, switchMa templateUrl: "./ingredient-form-basic.component.html", styleUrls: ["./ingredient-form-basic.component.less"], }) -export class IngredientFormBasicComponent { - constructor( - private fb: FormBuilder, - private msg: NzMessageService, - private api: ApiService, - private router: Router - ) {} +export class IngredientFormBasicComponent implements OnChanges { + constructor(private fb: FormBuilder, private msg: NzMessageService, private api: ApiService) {} + + @Input() menu: any | null; @Output() onSave = new EventEmitter(); - private standardSearch$ = new Subject(); + private standardSearch$ = new Subject<{ id?: string; name?: string }>(); private destroy$ = new Subject(); @@ -49,22 +45,25 @@ export class IngredientFormBasicComponent { id: this.fb.control("", []), name: this.fb.control("", [FormValidators.required()]), nutrient: this.fb.control("", [FormValidators.required()]), - day: this.fb.control("1", [FormValidators.required()]), + day: this.fb.control(1, [FormValidators.required()]), vendors: this.fb.control([], [FormValidators.required()]), month: this.fb.control([], [FormValidators.required()]), }); - this.standardSearch$ .pipe( filter((f) => !!f), debounceTime(500), distinctUntilChanged(), takeUntil(this.destroy$), - switchMap((term: string) => this.api.getStandard({ name: term })) + switchMap((q) => this.api.getStandard(q)) ) .subscribe((data) => { let listOfOption: Array = []; if (data.body) { + const getById = data.body && !Array.isArray(data.body); + if (getById) { + data.body = [data.body]; + } data.body.forEach((item) => { listOfOption.push({ label: item.name, @@ -73,10 +72,29 @@ export class IngredientFormBasicComponent { }); }); this.searchedStandard = this.searchedStandard.concat(listOfOption); + if (getById && this.menu.nutrient) { + this.onStandardChange(this.menu.nutrient); + } } this.standardOfOption = listOfOption; }); + + this.setValues(); + } + + ngOnChanges(changes: SimpleChanges): void {} + + setValues() { + if (this.menu) { + console.log("this.formGroup", this.formGroup, 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)); + this.formGroup.patchValue({ + ...this.menu, + vendors: [String(this.menu.vender)], + }); + } } ngOnDestroy(): void { @@ -87,7 +105,9 @@ export class IngredientFormBasicComponent { ageChange() {} searchStandard(k: string) { - this.standardSearch$.next(k); + if (k) { + this.standardSearch$.next({ name: k }); + } } onStandardChange(v: any) { @@ -104,6 +124,7 @@ export class IngredientFormBasicComponent { return { label: k, value: k, + checked: this.menu?.crows?.includes(k), ...(v as any), }; }); @@ -144,8 +165,12 @@ export class IngredientFormBasicComponent { ) .subscribe((res) => { this.msg.success(res.desc); - this.onSave.emit({ meals: this.meals, menuId: res.body, peoples: this.currentPeoples }); - // this.router.navigate(["/ingredient/item/list"]); + this.onSave.emit({ + ...this.formGroup.value, + meals: this.meals, + menuId: res.body, + peoples: this.currentPeoples, + }); }); } } diff --git a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html index 11eb0eb..a5b0db1 100644 --- a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html +++ b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html @@ -4,7 +4,7 @@ - @@ -14,239 +14,82 @@ - + 重量/克 - + 菜品 - + 食材 - - 轻体力(体重过低) - - - 轻体力(正常体重) - - - 休息(超重/肥胖) - - - 轻体力(体重过低) - - - 轻体力(正常体重) + + {{p}} - - -
- - 番茄煎蛋面 - - - -
    -
  • 编辑
  • -
  • 删除
  • -
-
-
- - - -
- - 番茄 - - - -
    -
  • 设置价格
  • -
  • 删除
  • -
-
-
- - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - - - - -
- - 面条 - - -
- - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - - - -
- - 鸡蛋青菜面 - - -
- - -
- - 食用油 - - -
- - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - - + + + + +
+ + {{dish['dishName']}} + + + + +
+ + -
- - 小白菜[青菜] - - -
- - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - - +
+ + {{food['foodName']}} + + +
+ + + {{g.value}} + + +
+
-
- - 鸡蛋(均值) - - -
- - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - - - -
- - 面条(均值) - - -
- - - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - -
\ No newline at end of file + +
+ + + + + + + \ No newline at end of file diff --git a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.less b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.less index e69de29..2ca8252 100644 --- a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.less +++ b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.less @@ -0,0 +1,6 @@ +.empty { + margin: 0; + padding: 24px; + border: 1px solid #f0f0f0; + border-top: none; +} \ No newline at end of file diff --git a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts index d862389..c55931d 100644 --- a/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts +++ b/projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts @@ -1,21 +1,130 @@ -import { Component } from "@angular/core"; +import { + Component, + EventEmitter, + Input, + OnChanges, + OnInit, + Output, + SimpleChanges, + TemplateRef, + ViewChild, +} from "@angular/core"; import { NzModalService } from "ng-zorro-antd/modal"; -import { AddDishToIngredientComponent } from "../add-dish-to-ingredient/add-dish-to-ingredient.component"; -import { NzDrawerService } from "ng-zorro-antd/drawer"; +import { + AddDishToIngredientComponent, + FoodInDishInterface, +} from "../add-dish-to-ingredient/add-dish-to-ingredient.component"; +import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; +import { NzMessageService } from "ng-zorro-antd/message"; +import { Augmented } from "@cdk/types"; +import { DishInterface } from "../ingredient-dish/ingredient-dish.component"; + +export type MealDishInterface = Augmented<{ + dishId: number; + dishName: string; + mark: string; + foods: FoodInDishInterface[]; +}>; @Component({ - selector: "lib-ingredient-meals", + selector: "app-ingredient-meals", templateUrl: "./ingredient-meals.component.html", styleUrls: ["./ingredient-meals.component.less"], }) -export class IngredientMealsComponent { - constructor(private modal: NzModalService, private drawer: NzDrawerService) {} +export class IngredientMealsComponent implements OnChanges, OnInit { + constructor(private modal: NzModalService, private msg: NzMessageService, private drawer: NzDrawerService) {} + + @Input() day!: number; + + @Input() mealIndex!: number; + + @Input() peopleGroups: string[] = []; + + @Input() mealDishs: DishInterface[] = []; + + @Output() onSaveDish = new EventEmitter(); + + @ViewChild("addDishFooter") addDishFooter!: TemplateRef<{}>; + + drawerRef?: NzDrawerRef; + + submitLoading = false; + + currentDishs: DishInterface[] = []; + + ngOnInit(): void { + this.init(); + } + + ngOnChanges(changes: SimpleChanges): void { + if (changes["mealDishs"]?.currentValue) { + this.init(); + } + } + init() { + console.log(" ", this.mealDishs, this.day, this.mealIndex); + this.currentDishs = this.mealDishs.filter((f) => f.day === this.day && this.mealIndex === f["mealIndex"]); + } shopDishForm() { - this.drawer.create({ + this.drawerRef = this.drawer.create({ nzTitle: "添加菜品", - nzWidth: 1000, + nzWidth: 1200, nzContent: AddDishToIngredientComponent, + nzFooter: this.addDishFooter, + nzContentParams: { + peopleGroups: this.peopleGroups, + }, }); } + + clearThisMeal() { + this.modal.confirm({ + nzTitle: "警告", + nzContent: "是否要清空本餐?", + nzOkDanger: true, + nzOnOk: () => { + this.mealDishs = this.mealDishs.filter((f) => !(f.day === this.day && f["mealIndex"] === this.mealIndex)); + this.onSaveDish.emit(this.mealDishs); + }, + }); + } + + cancelForm() { + this.drawerRef?.close(); + } + + onSubmit() { + if (this.drawerRef) { + const { dish, foods } = this.drawerRef.getContentComponent() as AddDishToIngredientComponent; + + this.mealDishs.push({ + day: this.day, + mealIndex: this.mealIndex, + meal: "", + dishId: dish.id, + dishName: dish.name, + mark: dish.marks, + items: foods.map((f) => ({ + ...f, + value: f.groupValues.reduce((a, c) => { + return { + ...a, + [c.peopleName]: c.value, + }; + }, {} as Record), + })), + }); + + this.onSaveDish.emit(this.mealDishs); + } + this.cancelForm(); + } + + onRemoveDish(d: DishInterface) { + this.mealDishs = this.mealDishs.filter( + (f) => !(f.dishId === d.dishId && f.day === this.day && f["mealIndex"] === this.mealIndex) + ); + this.onSaveDish.emit(this.mealDishs); + } } diff --git a/projects/cdk/src/ingredient/ingredient.module.ts b/projects/cdk/src/ingredient/ingredient.module.ts index 8b79912..6940216 100644 --- a/projects/cdk/src/ingredient/ingredient.module.ts +++ b/projects/cdk/src/ingredient/ingredient.module.ts @@ -3,10 +3,24 @@ import { SharedModule } from "@cdk/shared/shared.module"; import { AddDishToIngredientComponent } from "./add-dish-to-ingredient/add-dish-to-ingredient.component"; import { IngredientMealsComponent } from "./ingredient-meals/ingredient-meals.component"; import { ConfirmIngredientComponent } from "./confirm-ingredient/confirm-ingredient.component"; +import { IngredientDishComponent } from "./ingredient-dish/ingredient-dish.component"; +import { IngredientFormBasicComponent } from "./ingredient-form-basic/ingredient-form-basic.component"; @NgModule({ - declarations: [AddDishToIngredientComponent, IngredientMealsComponent, ConfirmIngredientComponent], + declarations: [ + AddDishToIngredientComponent, + IngredientMealsComponent, + ConfirmIngredientComponent, + IngredientFormBasicComponent, + IngredientDishComponent, + ], imports: [SharedModule], - exports: [AddDishToIngredientComponent, IngredientMealsComponent, ConfirmIngredientComponent], + exports: [ + AddDishToIngredientComponent, + IngredientMealsComponent, + ConfirmIngredientComponent, + IngredientFormBasicComponent, + IngredientDishComponent, + ], }) export class IngredientModule {} diff --git a/projects/cdk/src/services/api.service.ts b/projects/cdk/src/services/api.service.ts index 0abb602..1376dfa 100644 --- a/projects/cdk/src/services/api.service.ts +++ b/projects/cdk/src/services/api.service.ts @@ -372,9 +372,9 @@ export class ApiService { return this.http.get>(`/api/menu?${params}`); } - getMenuItem() { - const params = Utils.objectStringify({ menuId: 1 }); - return this.http.get(`/api/menu/dish?${params}`); + getMenuItem(id: string | number) { + const params = Utils.objectStringify({ id }); + return this.http.get(`/api/menu?${params}`); } saveMenu(v: AnyObject) { @@ -408,4 +408,8 @@ export class ApiService { const params = Utils.objectToFormData({ id }); return this.http.delete(`/api/menu`, { body: params }); } + + saveMenuDist(d: {}) { + return this.http.put(`/api/menu/dish/batch`, d); + } } diff --git a/projects/cdk/src/shared/components/dish-select/dish-select.component.html b/projects/cdk/src/shared/components/dish-select/dish-select.component.html new file mode 100644 index 0000000..2ffe2a4 --- /dev/null +++ b/projects/cdk/src/shared/components/dish-select/dish-select.component.html @@ -0,0 +1,22 @@ + + + + + + + + + 数据加载中... + + + \ No newline at end of file diff --git a/projects/cdk/src/shared/components/dish-select/dish-select.component.less b/projects/cdk/src/shared/components/dish-select/dish-select.component.less new file mode 100644 index 0000000..e69de29 diff --git a/projects/cdk/src/shared/components/dish-select/dish-select.component.ts b/projects/cdk/src/shared/components/dish-select/dish-select.component.ts new file mode 100644 index 0000000..035d20e --- /dev/null +++ b/projects/cdk/src/shared/components/dish-select/dish-select.component.ts @@ -0,0 +1,97 @@ +import { Component, OnInit } from "@angular/core"; +import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms"; +import { ApiService } from "@cdk/services"; +import { OptionItemInterface } from "@cdk/types"; +import { Subject, debounceTime, distinctUntilChanged, filter, finalize, switchMap, takeUntil, tap } from "rxjs"; + +@Component({ + selector: "app-dish-select", + templateUrl: "./dish-select.component.html", + styleUrls: ["./dish-select.component.less"], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + multi: true, + useExisting: DishSelectComponent, + }, + ], +}) +export class DishSelectComponent implements OnInit, ControlValueAccessor { + constructor(private api: ApiService) {} + + private destroy$ = new Subject(); + + private dishSearch$ = new Subject(); + + nzFilterOption = (): boolean => true; + + value?: string | string[]; + + listOfOption: OptionItemInterface[] = []; + + loading = false; + + ngOnInit(): void { + this.dishSearch$ + .pipe( + filter((f) => !!f), + debounceTime(500), + distinctUntilChanged(), + takeUntil(this.destroy$), + tap(() => { + this.loading = true; + }), + switchMap((term: string) => + this.api.getDishPage({ pageNo: 0, pageSize: 5 }, { keyword: term }).pipe( + finalize(() => { + this.loading = false; + }) + ) + ) + ) + .subscribe((data) => { + const listOfOption: Array = []; + data.body.content.forEach((item) => { + listOfOption.push({ + ...item, + value: String(item.id), + label: item.name, + }); + }); + this.listOfOption = listOfOption; + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + onSelectChange(v: any) { + const item = this.listOfOption.find((f) => f.value === v); + // console.log("v", item); + if (item) { + this.onChange(item); + } + } + + search = (k: string) => { + this.dishSearch$.next(k); + }; + + onChange(v: OptionItemInterface) {} + + ontouch(v: any) {} + + writeValue(v?: string[] | string): void { + this.value = v; + } + + registerOnChange(fn: any): void { + this.onChange = fn; + } + + registerOnTouched(fn: any): void { + this.ontouch = fn; + } +} diff --git a/projects/cdk/src/shared/components/index.ts b/projects/cdk/src/shared/components/index.ts index ae37f41..bdcf5e9 100644 --- a/projects/cdk/src/shared/components/index.ts +++ b/projects/cdk/src/shared/components/index.ts @@ -1,2 +1,4 @@ export * from "./search-and-select/search-and-select.component"; export * from "./month-select/month-select.component"; +export * from "./org-select/org-select.component"; +export * from "./dish-select/dish-select.component"; diff --git a/projects/cdk/src/shared/components/month-select/month-select.component.ts b/projects/cdk/src/shared/components/month-select/month-select.component.ts index e123c3f..cd3c0d1 100644 --- a/projects/cdk/src/shared/components/month-select/month-select.component.ts +++ b/projects/cdk/src/shared/components/month-select/month-select.component.ts @@ -79,6 +79,7 @@ export class MonthSelectComponent implements ControlValueAccessor { ontouch(v: any) {} writeValue(v: number[]): void { + console.log("v", v); this.allMonth = this.allMonth.map((i) => (v.includes(i.value) ? { ...i, checked: true } : i)); this.monthCheckEffect(); } 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 new file mode 100644 index 0000000..69bb7f0 --- /dev/null +++ b/projects/cdk/src/shared/components/org-select/org-select.component.html @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/projects/cdk/src/shared/components/org-select/org-select.component.less b/projects/cdk/src/shared/components/org-select/org-select.component.less new file mode 100644 index 0000000..e69de29 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 new file mode 100644 index 0000000..9ccde8c --- /dev/null +++ b/projects/cdk/src/shared/components/org-select/org-select.component.ts @@ -0,0 +1,81 @@ +import { Component, OnInit } from "@angular/core"; +import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms"; +import { ApiService } from "@cdk/services"; +import { OptionItemInterface } from "@cdk/types"; +import { Subject, debounceTime, distinctUntilChanged, filter, switchMap, takeUntil } from "rxjs"; + +@Component({ + selector: "app-org-select", + templateUrl: "./org-select.component.html", + styleUrls: ["./org-select.component.less"], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + multi: true, + useExisting: OrgSelectComponent, + }, + ], +}) +export class OrgSelectComponent implements OnInit, ControlValueAccessor { + constructor(private api: ApiService) {} + + private destroy$ = new Subject(); + + private orgSearch$ = new Subject(); + + nzFilterOption = (): boolean => true; + + value?: string | string[]; + + listOfOption: OptionItemInterface[] = []; + + ngOnInit(): void { + this.orgSearch$ + .pipe( + filter((f) => !!f), + debounceTime(500), + distinctUntilChanged(), + takeUntil(this.destroy$), + switchMap((term: string) => this.api.getOrgList({ keyword: term })) + ) + .subscribe((data) => { + const listOfOption: Array = []; + data.body.forEach((item) => { + listOfOption.push({ + value: String(item.id), + label: item.name, + }); + }); + this.listOfOption = listOfOption; + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + onSelectChange(v: any) { + this.onChange(v); + } + + searchOrg = (k: string) => { + this.orgSearch$.next(k); + }; + + onChange(v: number[]) {} + + ontouch(v: any) {} + + writeValue(v?: string[] | string): void { + this.value = v; + } + + registerOnChange(fn: any): void { + this.onChange = fn; + } + + registerOnTouched(fn: any): void { + this.ontouch = fn; + } +} diff --git a/projects/cdk/src/shared/ng-zorro.ts b/projects/cdk/src/shared/ng-zorro.ts index 9795829..537c738 100644 --- a/projects/cdk/src/shared/ng-zorro.ts +++ b/projects/cdk/src/shared/ng-zorro.ts @@ -47,8 +47,10 @@ import { NzInputNumberModule } from "ng-zorro-antd/input-number"; import { NzLayoutModule } from "ng-zorro-antd/layout"; import { NzBreadCrumbModule } from "ng-zorro-antd/breadcrumb"; import { NzOutletModule } from "ng-zorro-antd/core/outlet"; +import { NzAlertModule } from "ng-zorro-antd/alert"; export const ngZorroModules = [ + NzAlertModule, NzOutletModule, NzBreadCrumbModule, NzLayoutModule, diff --git a/projects/cdk/src/shared/shared.module.ts b/projects/cdk/src/shared/shared.module.ts index 576b7e2..57a1179 100644 --- a/projects/cdk/src/shared/shared.module.ts +++ b/projects/cdk/src/shared/shared.module.ts @@ -20,7 +20,7 @@ import { // import { environment } from "@manage/environments/environment"; import { NgxPermissionsModule } from "ngx-permissions"; import { AppPageComponent } from "@cdk/app-page/app-page.component"; -import { SearchAndSelectComponent, MonthSelectComponent } from "./components"; +import { SearchAndSelectComponent, MonthSelectComponent, OrgSelectComponent, DishSelectComponent } from "./components"; const ngModules = [CommonModule, HttpClientModule, FormsModule, RouterModule, ReactiveFormsModule]; const components: any = []; @@ -36,7 +36,14 @@ const cdks = [ ] as any; @NgModule({ - declarations: [...components, ...directives, SearchAndSelectComponent, MonthSelectComponent], + declarations: [ + ...components, + ...directives, + SearchAndSelectComponent, + MonthSelectComponent, + DishSelectComponent, + OrgSelectComponent, + ], imports: [...ngZorroModules, ...ngModules, ...cdks, AppPageComponent], exports: [ ...ngZorroModules, @@ -47,6 +54,8 @@ const cdks = [ AppPageComponent, SearchAndSelectComponent, MonthSelectComponent, + OrgSelectComponent, + DishSelectComponent, ], }) export class SharedModule {}