Browse Source

Merge branch 'main' of github.com:klyq/catering

main
kkerwin 1 year ago
parent
commit
5f97138585
  1. 13
      projects/admin/src/app/components/dish-form/dish-form.component.html
  2. 40
      projects/admin/src/app/components/dish-form/dish-form.component.ts
  3. 4
      projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.ts
  4. 7
      projects/admin/src/app/pages/dish/dish.component.html
  5. 44
      projects/admin/src/app/pages/dish/dish.component.ts
  6. 3
      projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html
  7. 24
      projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts
  8. 4
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html
  9. 20
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts
  10. 4
      projects/admin/src/app/pages/ingredients/ingredient-release/ingredient-release.component.ts
  11. 4
      projects/admin/src/app/pages/standard/standard-form/standard-form.component.ts
  12. 2
      projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html
  13. 18
      projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts
  14. 19
      projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.html
  15. 80
      projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts
  16. 5
      projects/cdk/src/ingredient/ingredient-preview/ingredient-preview.component.html
  17. 3
      projects/cdk/src/ingredient/ingredient-preview/ingredient-preview.component.less
  18. 11
      projects/cdk/src/ingredient/ingredient-preview/ingredient-preview.component.ts
  19. 67
      projects/cdk/src/services/api.service.ts
  20. 2
      projects/cdk/src/shared/components/month-select/month-select.component.ts
  21. 2
      projects/cdk/src/shared/components/org-select/org-select.component.ts
  22. 4
      projects/client/src/app/components/dish-form/dish-form.component.html
  23. 6
      projects/client/src/app/components/dish-form/dish-form.component.ts
  24. 18
      projects/client/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts
  25. 4
      projects/client/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html
  26. 14
      projects/client/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts

13
projects/admin/src/app/components/dish-form/dish-form.component.html

@ -11,15 +11,14 @@
nzPlaceHolder="请选择单位,多选时在多个单位均添加此菜品"> nzPlaceHolder="请选择单位,多选时在多个单位均添加此菜品">
</nz-select> --> </nz-select> -->
<nz-select <nz-select
[nzMode]="'multiple'" [nzMode]="'multiple'"
nzShowSearch
nzServerSearch
nzPlaceHolder="请选择单位,多选时在多个单位均添加此菜品" nzPlaceHolder="请选择单位,多选时在多个单位均添加此菜品"
[nzShowArrow]="false" [nzShowArrow]="false"
[nzFilterOption]="nzFilterOption"
formControlName="vendors" formControlName="vendors">
(nzOnSearch)="searchOrg($event)">
<nz-option *ngFor="let o of orgListOfOption" [nzLabel]="o.text" [nzValue]="o.value"></nz-option> <nz-option *ngFor="let o of orgListOfOption" [nzLabel]="o.text" [nzValue]="o.value"></nz-option>
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
@ -72,7 +71,7 @@
<nz-form-label> <nz-form-label>
菜品图片 菜品图片
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzExtra="支持.jpg .jpeg .png 格式,小于2M">
<input type="hidden" formControlName="icon" /> <input type="hidden" formControlName="icon" />
<div class="mb-2" *ngIf="iconPreview"> <div class="mb-2" *ngIf="iconPreview">
<img [src]="iconPreview" class="h-20 w-20" /> <img [src]="iconPreview" class="h-20 w-20" />
@ -80,7 +79,7 @@
<button class="upload-btn " nz-button [nzLoading]="uploadLoading"> <button class="upload-btn " nz-button [nzLoading]="uploadLoading">
<i nz-icon nzType="upload"></i> <i nz-icon nzType="upload"></i>
上传图片 上传图片
<input type="file" (change)="onFileChange($event)" /> <input type="file" (change)="onFileChange($event)" accept=".jpg,.jpeg,.png" />
</button> </button>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>

40
projects/admin/src/app/components/dish-form/dish-form.component.ts

@ -67,22 +67,26 @@ export class DishFormComponent {
month: this.fb.control([], []), month: this.fb.control([], []),
}); });
this.orgSearch$ this.api.getOrgList().subscribe((res) => {
.pipe( this.orgListOfOption = res;
debounceTime(500),
distinctUntilChanged(),
switchMap((q) => this.api.getOrgList(q))
)
.subscribe((data) => {
const listOfOption: Array<{ value: string; text: string }> = [];
data.body.forEach((item) => {
listOfOption.push({
value: item.id.toString(),
text: item.name,
});
});
this.orgListOfOption = listOfOption;
}); });
// this.orgSearch$
// .pipe(
// debounceTime(500),
// distinctUntilChanged(),
// switchMap((q) => this.api.getOrgList(q))
// )
// .subscribe((data) => {
// const listOfOption: Array<{ value: string; text: string }> = [];
// data.forEach((item) => {
// listOfOption.push({
// value: item.id.toString(),
// text: item.name,
// });
// });
// this.orgListOfOption = listOfOption;
// });
this.foodSearch$ this.foodSearch$
.pipe( .pipe(
filter((f) => !!f), filter((f) => !!f),
@ -121,7 +125,9 @@ export class DishFormComponent {
this.foodSelected.push(f.key); this.foodSelected.push(f.key);
} }
}); });
if (this.data["icon"]) {
this.iconPreview = "/icon/" + this.data["icon"]; this.iconPreview = "/icon/" + this.data["icon"];
}
this.formGroup.patchValue({ this.formGroup.patchValue({
...this.data, ...this.data,
vendors: [this.data.vender], vendors: [this.data.vender],
@ -222,8 +228,8 @@ export class DishFormComponent {
const target = e.target as HTMLInputElement; const target = e.target as HTMLInputElement;
const file = target.files![0]; const file = target.files![0];
target.value = ""; target.value = "";
if (file.size / 1024 / 1024 >= 5) { if (file.size / 1024 / 1024 >= 2) {
this.msg.error("图片大小不能超过5M"); this.msg.error("图片大小不能超过2M");
return; return;
} }
const fileReader = new FileReader(); const fileReader = new FileReader();

4
projects/admin/src/app/components/ingredient-status-list/ingredient-status-list.component.ts

@ -128,8 +128,8 @@ export class IngredientStatusListComponent {
if (vendors.length > 0) { if (vendors.length > 0) {
this.api.getOrgList({ vendors }).subscribe((org) => { this.api.getOrgList({ vendors }).subscribe((org) => {
if (Array.isArray(org.body)) { if (Array.isArray(org)) {
this.tableOrg = org.body.reduce((a, c) => { this.tableOrg = org.reduce((a, c) => {
return { return {
...a, ...a,
[c.id]: c, [c.id]: c,

7
projects/admin/src/app/pages/dish/dish.component.html

@ -21,13 +21,8 @@
<nz-form-item class="w-60"> <nz-form-item class="w-60">
<nz-form-control> <nz-form-control>
<nz-select <nz-select
nzShowSearch
nzServerSearch
nzPlaceHolder="请选择单位" nzPlaceHolder="请选择单位"
[nzShowArrow]="false" formControlName="vendors">
formControlName="vendors"
[nzFilterOption]="nzFilterOption"
(nzOnSearch)="searchOrg($event)">
<nz-option *ngFor="let o of listOfOption" [nzLabel]="o.text" <nz-option *ngFor="let o of listOfOption" [nzLabel]="o.text"
[nzValue]="o.value"></nz-option> [nzValue]="o.value"></nz-option>
</nz-select> </nz-select>

44
projects/admin/src/app/pages/dish/dish.component.ts

@ -64,7 +64,7 @@ export class DishComponent {
tableFoods: { [k: string]: any } = {}; tableFoods: { [k: string]: any } = {};
listOfOption: Array<{ value: number; text: string }> = []; listOfOption: Array<{ value: number | string; text: string }> = [];
nzFilterOption = (): boolean => true; nzFilterOption = (): boolean => true;
@ -72,24 +72,28 @@ export class DishComponent {
ngOnInit(): void { ngOnInit(): void {
this.initTableList(); this.initTableList();
this.orgSearch$
.pipe( this.api.getOrgList().subscribe((res) => {
filter((f) => !!f), this.listOfOption = res;
debounceTime(500),
distinctUntilChanged(),
takeUntil(this.destroy$),
switchMap((term: string) => this.api.getOrgList({ keyword: term }))
)
.subscribe((data) => {
const listOfOption: Array<{ value: number; text: string }> = [];
data.body.forEach((item) => {
listOfOption.push({
value: item.id,
text: item.name,
});
});
this.listOfOption = listOfOption;
}); });
// 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<{ value: number; text: string }> = [];
// data.forEach((item) => {
// listOfOption.push({
// value: item.id,
// text: item.name,
// });
// });
// this.listOfOption = listOfOption;
// });
this.tableList.getState$.pipe(takeUntil(this.destroy$)).subscribe((res) => { this.tableList.getState$.pipe(takeUntil(this.destroy$)).subscribe((res) => {
this.selectedIds = res.selectedKeys as Array<string>; this.selectedIds = res.selectedKeys as Array<string>;
@ -174,8 +178,8 @@ export class DishComponent {
if (vendors.length > 0) { if (vendors.length > 0) {
this.api.getOrgList({ vendors }).subscribe((org) => { this.api.getOrgList({ vendors }).subscribe((org) => {
if (Array.isArray(org.body)) { if (Array.isArray(org)) {
this.tableOrg = org.body.reduce((a, c) => { this.tableOrg = org.reduce((a, c) => {
return { return {
...a, ...a,
[c.id]: c, [c.id]: c,

3
projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.html

@ -40,7 +40,8 @@
</nz-card> </nz-card>
<div class="p-4"> <div class="p-4">
<app-ingredient-dish #menuDish [menuBaisc]="menuItem" <app-ingredient-dish #menuDish
[menuBaisc]="menuItem"
[menuDishFormServer]="menuDishFormServer"> [menuDishFormServer]="menuDishFormServer">
</app-ingredient-dish> </app-ingredient-dish>
</div> </div>

24
projects/admin/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts

@ -45,12 +45,13 @@ export class IngredientFormComponent implements OnInit {
getDetail() { getDetail() {
if (this.id && this.id !== "create") { if (this.id && this.id !== "create") {
this.api.getMenuItem(this.id).subscribe((res) => { const id = this.id.split(",")[0];
this.api.getMenuItem(id).subscribe((res) => {
if (res.body) { if (res.body) {
this.menuItem = res.body; this.menuItem = res.body;
} }
}); });
this.api.getMenuDist(this.id).subscribe((res) => { this.api.getMenuDist(id).subscribe((res) => {
if (Array.isArray(res.body)) { if (Array.isArray(res.body)) {
res.body.forEach((d) => { res.body.forEach((d) => {
d.ingredient.forEach((f: any) => { d.ingredient.forEach((f: any) => {
@ -91,20 +92,10 @@ export class IngredientFormComponent implements OnInit {
}); });
} }
onStepChange(basicInfo: any) { onStepChange(idStr: string) {
this.step = 1; this.step = 1;
this.menuItem = { this.id = idStr;
...basicInfo, this.getDetail();
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[]
),
};
} }
createNewMenu() { createNewMenu() {
@ -153,10 +144,9 @@ export class IngredientFormComponent implements OnInit {
nzWidth: 650, nzWidth: 650,
nzOnOk: () => { nzOnOk: () => {
const { mealDishList } = this.menuDish; const { mealDishList } = this.menuDish;
this.api this.api
.saveMenuDist({ .saveMenuDist({
menuIds: this.menuItem.menuIds ?? [this.menuItem.id], menuIds: this.id?.split(","),
dishes: this.formatData(mealDishList), dishes: this.formatData(mealDishList),
}) })
.subscribe((res) => { .subscribe((res) => {

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

@ -55,7 +55,7 @@
<nz-tag *ngFor="let item of data">{{item}}</nz-tag> <nz-tag *ngFor="let item of data">{{item}}</nz-tag>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'day'"> <ng-container *ngSwitchCase="'day'">
{{data}} {{data}}
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'status'"> <ng-container *ngSwitchCase="'status'">
{{statusTextMap[data]}} {{statusTextMap[data]}}
@ -69,7 +69,7 @@
</ng-container> </ng-container>
<ng-container *ngIf="data.length !== 12"> <ng-container *ngIf="data.length !== 12">
<nz-tag *ngFor="let item of data" class="mb-1"> <nz-tag *ngFor="let item of data" class="mb-1">
{{monthText[item]}} {{item}}
</nz-tag> </nz-tag>
</ng-container> </ng-container>
</div> </div>

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

@ -71,16 +71,16 @@ export class IngredientListComponent {
} }
initTableList() { initTableList() {
this.tableList.scroll = { x: null }; this.tableList.scroll = { x: "900px" };
this.tableList = this.tableList.setColumns([ this.tableList = this.tableList.setColumns([
{ key: "name", title: "食谱名称" }, { key: "name", title: "食谱名称", width: "200px" },
{ key: "vender", title: "单位" }, { key: "vender", title: "单位", width: "200px" },
{ key: "meals", title: "包含餐次" }, { key: "meals", title: "包含餐次", width: "180px" },
{ key: "month", title: "适用月份", width: "300px" }, { key: "month", title: "适用月份" },
{ key: "day", title: "周期" }, { key: "day", title: "周期" },
{ key: "status", title: "状态" }, { key: "status", title: "状态", width: "120px" },
{ key: "modify", title: "更新时间" }, { key: "modify", title: "更新时间", width: "170px" },
{ key: "operate", title: "创建人" }, { key: "operate", title: "创建人", width: "160px" },
]); ]);
this.tableList = this.tableList.setOptions([ this.tableList = this.tableList.setOptions([
@ -156,8 +156,8 @@ export class IngredientListComponent {
if (vendors.length > 0) { if (vendors.length > 0) {
this.api.getOrgList({ vendors }).subscribe((org) => { this.api.getOrgList({ vendors }).subscribe((org) => {
if (Array.isArray(org.body)) { if (Array.isArray(org)) {
this.tableOrg = org.body.reduce((a, c) => { this.tableOrg = org.reduce((a, c) => {
return { return {
...a, ...a,
[c.id]: c, [c.id]: c,

4
projects/admin/src/app/pages/ingredients/ingredient-release/ingredient-release.component.ts

@ -97,8 +97,8 @@ export class IngredientReleaseComponent {
if (vendors.length > 0) { if (vendors.length > 0) {
this.api.getOrgList({ vendors }).subscribe((org) => { this.api.getOrgList({ vendors }).subscribe((org) => {
if (Array.isArray(org.body)) { if (Array.isArray(org)) {
this.tableOrg = org.body.reduce((a, c) => { this.tableOrg = org.reduce((a, c) => {
return { return {
...a, ...a,
[c.id]: c, [c.id]: c,

4
projects/admin/src/app/pages/standard/standard-form/standard-form.component.ts

@ -63,7 +63,7 @@ export class StandardFormComponent {
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; text: string }> = [];
data.body.forEach((item) => { data.forEach((item) => {
listOfOption.push({ listOfOption.push({
value: item.id, value: item.id,
text: item.name, text: item.name,
@ -83,7 +83,7 @@ export class StandardFormComponent {
) )
.subscribe((data) => { .subscribe((data) => {
const listOfOption: Array<{ value: number; text: string }> = []; const listOfOption: Array<{ value: number; text: string }> = [];
data.body.forEach((item) => { data.forEach((item) => {
listOfOption.push({ listOfOption.push({
value: item.id, value: item.id,
text: item.name, text: item.name,

2
projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.html

@ -15,7 +15,7 @@
<span class="expanded-icon" nz-icon nzType="caret-right" nzTheme="outline"></span> <span class="expanded-icon" nz-icon nzType="caret-right" nzTheme="outline"></span>
</button> </button>
<span> <span>
{{day}} {{weekdayMap[day]}}
</span> </span>
</div> </div>
</ng-template> </ng-template>

18
projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts

@ -7,6 +7,7 @@ import { forkJoin } from "rxjs";
import { ApiService } from "@cdk/services"; import { ApiService } from "@cdk/services";
import { NzDrawerService } from "ng-zorro-antd/drawer"; import { NzDrawerService } from "ng-zorro-antd/drawer";
import { IngredientAnalysisComponent } from "../ingredient-analysis/ingredient-analysis.component"; import { IngredientAnalysisComponent } from "../ingredient-analysis/ingredient-analysis.component";
import { weekdayMap } from "../ingredient-form-basic/ingredient-form-basic.component";
// export interface MenuObjectInterface { // export interface MenuObjectInterface {
// [Day: number]: { // [Day: number]: {
@ -53,6 +54,8 @@ export class IngredientDishComponent implements OnChanges {
selectDay: OptionItemInterface[] = []; selectDay: OptionItemInterface[] = [];
weekdayMap = weekdayMap;
mealCurrentIndex: Record<number, number> = {}; mealCurrentIndex: Record<number, number> = {};
// d = { // d = {
@ -102,15 +105,16 @@ export class IngredientDishComponent implements OnChanges {
initMenuBasic() { initMenuBasic() {
if (this.menuBaisc) { if (this.menuBaisc) {
const meals = this.menuBaisc.meals as string[]; const meals = this.menuBaisc.meals as string[];
const day = this.menuBaisc.day as number; console.log("this.menuBaisc", this.menuBaisc);
this.days = Array.from({ length: day }, (_, i) => { const day = this.menuBaisc.day as number[];
const d = i + 1; this.days = day.map((i) => {
const d = weekdayMap[i];
this.selectDay.push({ this.selectDay.push({
label: `${d}`, label: d,
value: String(d), value: String(d),
}); });
this.mealCurrentIndex[d] = 0; this.mealCurrentIndex[i] = 0;
this.expanded.add(d); this.expanded.add(i);
// if (!this.menuObject) { // if (!this.menuObject) {
// this.menuObject = {}; // this.menuObject = {};
// } // }
@ -120,7 +124,7 @@ export class IngredientDishComponent implements OnChanges {
// [idx]: [], // [idx]: [],
// }; // };
// }, {} as Record<number, MealDishInterface[]>); // }, {} as Record<number, MealDishInterface[]>);
return i + 1; return i;
}); });
} }
} }

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

@ -51,16 +51,14 @@
<nz-form-label nzRequired nzSpan="6"> <nz-form-label nzRequired nzSpan="6">
天数 天数
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<nz-radio-group formControlName="day">
<label nz-radio [nzValue]="1">1天</label> <nz-checkbox-group
<label nz-radio [nzValue]="2">2天</label>
<label nz-radio [nzValue]="3">3天</label> [(ngModel)]="weekday"
<label nz-radio [nzValue]="4">4天</label> [ngModelOptions]="{standalone: true}">
<label nz-radio [nzValue]="5">5天</label>
<label nz-radio [nzValue]="6">6天</label> </nz-checkbox-group>
<label nz-radio [nzValue]="7">7天</label>
</nz-radio-group>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
<nz-form-item class="block"> <nz-form-item class="block">
@ -68,6 +66,7 @@
餐次 餐次
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<nz-checkbox-group <nz-checkbox-group
class="flex flex-wrap checkbox-wrap" class="flex flex-wrap checkbox-wrap"
[(ngModel)]="meals" [(ngModel)]="meals"

80
projects/cdk/src/ingredient/ingredient-form-basic/ingredient-form-basic.component.ts

@ -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,
});
}); });
} }
} }

5
projects/cdk/src/ingredient/ingredient-preview/ingredient-preview.component.html

@ -60,7 +60,7 @@
<th *ngFor="let day of days"> <th *ngFor="let day of days">
<div> <div>
<div class="table-day-row"> <div class="table-day-row">
<div class="td"> {{day}} </div> <div class="td"> {{weekdayMap[day]}} </div>
<div class="td"> 重量/克 </div> <div class="td"> 重量/克 </div>
</div> </div>
<div class="table-menu-row flex "> <div class="table-menu-row flex ">
@ -103,7 +103,8 @@
<ul> <ul>
<ng-container *ngFor="let f of d.items;let last = last"> <ng-container *ngFor="let f of d.items;let last = last">
<li class="flex food-item"> <li class="flex food-item">
<div class="td food-name text-left"> <div class="td food-name text-left"
[attr.title]="f['foodName']">
{{f['foodName']}} {{f['foodName']}}
</div> </div>
<div <div

3
projects/cdk/src/ingredient/ingredient-preview/ingredient-preview.component.less

@ -105,6 +105,9 @@
.food-name { .food-name {
width: 180px; width: 180px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
} }
.td { .td {

11
projects/cdk/src/ingredient/ingredient-preview/ingredient-preview.component.ts

@ -6,6 +6,7 @@ import { DishInterface } from "../ingredient-dish/ingredient-dish.component";
import { forkJoin, map } from "rxjs"; import { forkJoin, map } from "rxjs";
import { IngredientAnalysisComponent } from "../ingredient-analysis/ingredient-analysis.component"; import { IngredientAnalysisComponent } from "../ingredient-analysis/ingredient-analysis.component";
import { NzDrawerService } from "ng-zorro-antd/drawer"; import { NzDrawerService } from "ng-zorro-antd/drawer";
import { weekdayMap } from "../ingredient-form-basic/ingredient-form-basic.component";
@Component({ @Component({
selector: "app-ingredient-preview", selector: "app-ingredient-preview",
@ -42,6 +43,8 @@ export class IngredientPreviewComponent {
12: "十二月", 12: "十二月",
} as any; } as any;
weekdayMap = weekdayMap;
days: number[] = []; days: number[] = [];
ngOnInit(): void { ngOnInit(): void {
@ -57,8 +60,9 @@ export class IngredientPreviewComponent {
}) })
) )
.subscribe(([dishs, basic]) => { .subscribe(([dishs, basic]) => {
console.log(dishs, basic); // this.days = Array.from({ length: basic.day }, (_, i) => i + 1);
this.days = Array.from({ length: basic.day }, (_, i) => i + 1); this.days = basic.day;
this.getStandardName(basic.nutrient); this.getStandardName(basic.nutrient);
this.basic = basic; this.basic = basic;
@ -70,7 +74,8 @@ export class IngredientPreviewComponent {
if (storage) { if (storage) {
try { try {
const { basic, dishs } = JSON.parse(storage); const { basic, dishs } = JSON.parse(storage);
this.days = Array.from({ length: basic.day }, (_, i) => i + 1); // this.days = Array.from({ length: basic.day }, (_, i) => i + 1);
this.days = basic.day;
this.getStandardName(basic.nutrient); this.getStandardName(basic.nutrient);
this.basic = basic; this.basic = basic;
this.dishs = dishs; this.dishs = dishs;

67
projects/cdk/src/services/api.service.ts

@ -1,6 +1,6 @@
import { HttpClient, HttpParams, HttpResponse } from "@angular/common/http"; import { HttpClient, HttpParams, HttpResponse } from "@angular/common/http";
import { Inject, Injectable, InjectionToken } from "@angular/core"; import { Inject, Injectable, InjectionToken } from "@angular/core";
import { AnyObject, OptionItemInterface, PageResult, ResponseType } from "@cdk/types"; import { AnyObject, Augmented, OptionItemInterface, PageResult, ResponseType } from "@cdk/types";
import { format, addDays } from "date-fns"; import { format, addDays } from "date-fns";
import { Utils } from "@cdk/utils"; import { Utils } from "@cdk/utils";
import { Observable, map, of, tap } from "rxjs"; import { Observable, map, of, tap } from "rxjs";
@ -189,9 +189,25 @@ export class ApiService {
}); });
} }
getOrgList(query: { vendors?: number[]; keyword?: string }) { orgList: (OrgDTO & { value: string; text: string })[] = [];
const q = Utils.objectStringify(query);
return this.http.get<ResponseType<OrgDTO[]>>(`/api/vender/select?${q}`); getOrgList(query?: { vendors?: number[]; keyword?: string }, force?: boolean) {
if (this.orgList.length && !force) {
return of(this.orgList);
}
// const q = Utils.objectStringify(query);
return this.http.get<ResponseType<OrgDTO[]>>(`/api/vender/select?keyword= `).pipe(
map((r) => {
return r.body.map((i) => ({
...i,
value: i.id.toString(),
text: i.name,
}));
}),
tap((r) => {
this.orgList = r;
})
);
} }
getOrgPage(p: {}, q: {}) { getOrgPage(p: {}, q: {}) {
@ -340,9 +356,46 @@ export class ApiService {
); );
} }
getStandard(q: { id?: string; name?: string }) { getO1rgList(query?: { vendors?: number[]; keyword?: string }, force?: boolean) {
const query = Utils.objectStringify(q); if (this.orgList.length && !force) {
return this.http.get<ResponseType<any>>(`/api/nutrition/select?${query}`); return of(this.orgList);
}
// const q = Utils.objectStringify(query);
return this.http.get<ResponseType<OrgDTO[]>>(`/api/vender/select?keyword= `).pipe(
map((r) => {
return r.body.map((i) => ({
...i,
value: i.id.toString(),
text: i.name,
}));
}),
tap((r) => {
this.orgList = r;
})
);
}
standardList: (AnyObject & { value: string; text: string })[] = [];
getStandard(q: { id?: string; name?: string }, force?: boolean) {
// if (this.standardList.length && !force) {
// return of(this.standardList);
// }
const query = q ? Utils.objectStringify(q) : { name: "" };
return this.http
.get<ResponseType<any>>(`/api/nutrition/select?${query}`)
.pipe
// map((r) => {
// return r.body.map((i: any) => ({
// ...i,
// value: i.id.toString(),
// text: i.name,
// }));
// }),
// tap((r) => {
// this.orgList = r;
// })
();
} }
saveStandard(v: AnyObject, isEdit?: boolean) { saveStandard(v: AnyObject, isEdit?: boolean) {

2
projects/cdk/src/shared/components/month-select/month-select.component.ts

@ -79,7 +79,7 @@ export class MonthSelectComponent implements ControlValueAccessor {
ontouch(v: any) {} ontouch(v: any) {}
writeValue(v: number[]): void { writeValue(v: number[]): void {
console.log("v", v); // console.log("v", v);
this.allMonth = this.allMonth.map((i) => (v.includes(i.value) ? { ...i, checked: true } : i)); this.allMonth = this.allMonth.map((i) => (v.includes(i.value) ? { ...i, checked: true } : i));
this.monthCheckEffect(); this.monthCheckEffect();
} }

2
projects/cdk/src/shared/components/org-select/org-select.component.ts

@ -40,7 +40,7 @@ export class OrgSelectComponent implements OnInit, ControlValueAccessor {
) )
.subscribe((data) => { .subscribe((data) => {
const listOfOption: Array<OptionItemInterface> = []; const listOfOption: Array<OptionItemInterface> = [];
data.body.forEach((item) => { data.forEach((item) => {
listOfOption.push({ listOfOption.push({
value: String(item.id), value: String(item.id),
label: item.name, label: item.name,

4
projects/client/src/app/components/dish-form/dish-form.component.html

@ -45,7 +45,7 @@
<nz-form-label> <nz-form-label>
菜品图片 菜品图片
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzExtra="支持.jpg .jpeg .png 格式,小于2M">
<input type="hidden" formControlName="icon" /> <input type="hidden" formControlName="icon" />
<div class="mb-2" *ngIf="iconPreview"> <div class="mb-2" *ngIf="iconPreview">
<img [src]="iconPreview" class="h-20 w-20" /> <img [src]="iconPreview" class="h-20 w-20" />
@ -53,7 +53,7 @@
<button class="upload-btn " nz-button [nzLoading]="uploadLoading"> <button class="upload-btn " nz-button [nzLoading]="uploadLoading">
<i nz-icon nzType="upload"></i> <i nz-icon nzType="upload"></i>
上传图片 上传图片
<input type="file" (change)="onFileChange($event)" /> <input type="file" (change)="onFileChange($event)" accept=".jpg,.jpeg,.png" />
</button> </button>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>

6
projects/client/src/app/components/dish-form/dish-form.component.ts

@ -74,7 +74,7 @@ export class DishFormComponent {
) )
.subscribe((data) => { .subscribe((data) => {
const listOfOption: Array<{ value: string; text: string }> = []; const listOfOption: Array<{ value: string; text: string }> = [];
data.body.forEach((item) => { data.forEach((item) => {
listOfOption.push({ listOfOption.push({
value: item.id.toString(), value: item.id.toString(),
text: item.name, text: item.name,
@ -222,8 +222,8 @@ export class DishFormComponent {
const target = e.target as HTMLInputElement; const target = e.target as HTMLInputElement;
const file = target.files![0]; const file = target.files![0];
target.value = ""; target.value = "";
if (file.size / 1024 / 1024 >= 5) { if (file.size / 1024 / 1024 >= 2) {
this.msg.error("图片大小不能超过5M"); this.msg.error("图片大小不能超过2M");
return; return;
} }
const fileReader = new FileReader(); const fileReader = new FileReader();

18
projects/client/src/app/pages/ingredients/ingredient-form/ingredient-form.component.ts

@ -90,20 +90,10 @@ export class IngredientFormComponent implements OnInit {
}); });
} }
onStepChange(basicInfo: any) { onStepChange(idStr: string) {
this.step = 1; this.step = 1;
this.menuItem = { this.id = idStr;
...basicInfo, this.getDetail();
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[]
),
};
} }
createNewMenu() { createNewMenu() {
@ -155,7 +145,7 @@ export class IngredientFormComponent implements OnInit {
this.api this.api
.saveMenuDist({ .saveMenuDist({
menuIds: this.menuItem.menuIds ?? [this.menuItem.id], menuIds: this.id?.split(","),
dishes: this.formatData(mealDishList), dishes: this.formatData(mealDishList),
}) })
.subscribe((res) => { .subscribe((res) => {

4
projects/client/src/app/pages/ingredients/ingredient-list/ingredient-list.component.html

@ -51,7 +51,7 @@
<nz-tag *ngFor="let item of data">{{item}}</nz-tag> <nz-tag *ngFor="let item of data">{{item}}</nz-tag>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'day'"> <ng-container *ngSwitchCase="'day'">
{{data}} {{data}}
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'status'"> <ng-container *ngSwitchCase="'status'">
{{statusTextMap[data]}} {{statusTextMap[data]}}
@ -65,7 +65,7 @@
</ng-container> </ng-container>
<ng-container *ngIf="data.length !== 12"> <ng-container *ngIf="data.length !== 12">
<nz-tag *ngFor="let item of data" class="mb-1"> <nz-tag *ngFor="let item of data" class="mb-1">
{{monthText[item]}} {{item}}
</nz-tag> </nz-tag>
</ng-container> </ng-container>
</div> </div>

14
projects/client/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts

@ -71,16 +71,16 @@ export class IngredientListComponent {
} }
initTableList() { initTableList() {
this.tableList.scroll = { x: null }; this.tableList.scroll = { x: "900px" };
this.tableList = this.tableList.setColumns([ this.tableList = this.tableList.setColumns([
{ key: "name", title: "食谱名称" }, { key: "name", title: "食谱名称", width: "200px" },
{ key: "meals", title: "包含餐次" }, { key: "meals", title: "包含餐次", width: "180px" },
{ key: "month", title: "适用月份", width: "300px" }, { key: "month", title: "适用月份" },
{ key: "day", title: "周期" }, { key: "day", title: "周期" },
{ key: "status", title: "状态" }, { key: "status", title: "状态", width: "120px" },
{ key: "modify", title: "更新时间" }, { key: "modify", title: "更新时间", width: "170px" },
{ key: "operate", title: "创建人" }, { key: "operate", title: "创建人", width: "160px" },
]); ]);
this.tableList = this.tableList.setOptions([ this.tableList = this.tableList.setOptions([

Loading…
Cancel
Save