|
|
@ -1,5 +1,6 @@ |
|
|
import { Component, OnInit } from "@angular/core"; |
|
|
import { Component, OnInit } from "@angular/core"; |
|
|
import { FormArray, FormBuilder, FormGroup } from "@angular/forms"; |
|
|
import { FormArray, FormBuilder, FormGroup } from "@angular/forms"; |
|
|
|
|
|
import { ApiService } from "@cdk/services"; |
|
|
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 { finalize } from "rxjs"; |
|
|
import { finalize } from "rxjs"; |
|
|
@ -10,10 +11,18 @@ import { finalize } from "rxjs"; |
|
|
styleUrls: ["./dish-form.component.less"], |
|
|
styleUrls: ["./dish-form.component.less"], |
|
|
}) |
|
|
}) |
|
|
export class DishFormComponent { |
|
|
export class DishFormComponent { |
|
|
constructor(private fb: FormBuilder, private msg: NzMessageService) {} |
|
|
constructor(private fb: FormBuilder, private msg: NzMessageService, private api: ApiService) {} |
|
|
|
|
|
|
|
|
formGroup!: FormGroup; |
|
|
formGroup!: FormGroup; |
|
|
|
|
|
|
|
|
|
|
|
selectedValue = null; |
|
|
|
|
|
|
|
|
|
|
|
listOfOption: Array<{ value: string; text: string }> = []; |
|
|
|
|
|
|
|
|
|
|
|
nzFilterOption = (): boolean => true; |
|
|
|
|
|
|
|
|
|
|
|
globalEnum = this.api.globalEnum; |
|
|
|
|
|
|
|
|
allMonth = [ |
|
|
allMonth = [ |
|
|
{ value: "1", label: "一月", checked: false }, |
|
|
{ value: "1", label: "一月", checked: false }, |
|
|
{ value: "2", label: "二月", checked: false }, |
|
|
{ value: "2", label: "二月", checked: false }, |
|
|
@ -41,18 +50,38 @@ export class DishFormComponent { |
|
|
return this.formGroup.get("food") as FormArray; |
|
|
return this.formGroup.get("food") as FormArray; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get icon() { |
|
|
|
|
|
return this.formGroup.get("icon")?.value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
ngOnInit(): void { |
|
|
this.formGroup = this.fb.group({ |
|
|
this.formGroup = this.fb.group({ |
|
|
id: this.fb.control("", [FormValidators.required()]), |
|
|
id: this.fb.control("", [FormValidators.required()]), |
|
|
unit: this.fb.control([], [FormValidators.required()]), |
|
|
vendors: this.fb.control([], [FormValidators.required()]), |
|
|
name: this.fb.control("", [FormValidators.required()]), |
|
|
name: this.fb.control("", [FormValidators.required()]), |
|
|
img: this.fb.control("", []), |
|
|
icon: this.fb.control("", []), |
|
|
tag: this.fb.control([], []), |
|
|
mark: this.fb.control([], []), |
|
|
food: this.fb.array([], [FormValidators.required()]), |
|
|
food: this.fb.array([], [FormValidators.required()]), |
|
|
month: this.fb.control([], []), |
|
|
month: this.fb.control([], []), |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
search(value: string): void { |
|
|
|
|
|
this.api |
|
|
|
|
|
.getOrgList({ keyword: value }) |
|
|
|
|
|
|
|
|
|
|
|
.subscribe((data) => { |
|
|
|
|
|
const listOfOption: Array<{ value: string; text: string }> = []; |
|
|
|
|
|
data.body.forEach((item) => { |
|
|
|
|
|
listOfOption.push({ |
|
|
|
|
|
value: item.id.toString(), |
|
|
|
|
|
text: item.account, |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
this.listOfOption = listOfOption; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
addFood() { |
|
|
addFood() { |
|
|
this.food.push( |
|
|
this.food.push( |
|
|
this.fb.group({ |
|
|
this.fb.group({ |
|
|
@ -98,25 +127,15 @@ 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 = ""; |
|
|
const formData = new FormData(); |
|
|
if (file.size / 1024 / 1024 >= 5) { |
|
|
|
|
|
this.msg.error("图片大小不能超过5M"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
const fileReader = new FileReader(); |
|
|
const fileReader = new FileReader(); |
|
|
fileReader.onload = () => { |
|
|
fileReader.onload = () => { |
|
|
const base64 = fileReader.result as string; |
|
|
const base64 = fileReader.result as string; |
|
|
|
|
|
this.formGroup.get("icon")?.setValue(base64); |
|
|
const v = base64.split("base64,")[1]; |
|
|
|
|
|
}; |
|
|
}; |
|
|
formData.append("file", file); |
|
|
fileReader.readAsDataURL(file); |
|
|
this.uploadLoading = true; |
|
|
|
|
|
// this.api
|
|
|
|
|
|
// .uploadLogo(formData)
|
|
|
|
|
|
// .pipe(
|
|
|
|
|
|
// finalize(() => {
|
|
|
|
|
|
// this.uploadLoading = false;
|
|
|
|
|
|
// })
|
|
|
|
|
|
// )
|
|
|
|
|
|
// .subscribe((r) => {
|
|
|
|
|
|
// this.msg.success(r.desc);
|
|
|
|
|
|
// fileReader.readAsDataURL(file);
|
|
|
|
|
|
// });
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|