-
-
-
-
-
-
-
- 点击或将文件拖拽到这里上传
-
-
- 支持扩展名:.xls .xlsx
-
+
+
+
+
+
+
+
+
+ 点击或将文件拖拽到这里上传
+
+
+ 支持扩展名:.xls .xlsx
+
+
-
+
diff --git a/projects/admin/src/app/pages/food/food.component.ts b/projects/admin/src/app/pages/food/food.component.ts
index 26881f3..ab94d69 100644
--- a/projects/admin/src/app/pages/food/food.component.ts
+++ b/projects/admin/src/app/pages/food/food.component.ts
@@ -46,6 +46,8 @@ export class FoodComponent implements OnInit, OnDestroy {
submitLoading = false;
+ uploadLoading = false;
+
editItem = null;
ngOnInit(): void {
@@ -66,8 +68,8 @@ export class FoodComponent implements OnInit, OnDestroy {
{ key: "key", title: "食材编号" },
{ key: "name", title: "食材名称" },
{ key: "type", title: "食材类型" },
- { key: "nutrientArr", title: "营养素(每100g可食部)" },
- { key: "time", title: "更新日期" },
+ { key: "nutrientArr", title: "营养素(每100g可食部)", width: "40%" },
+ { key: "modify", title: "更新日期" },
]);
this.tableList = this.tableList.setOptions([
@@ -145,6 +147,12 @@ export class FoodComponent implements OnInit, OnDestroy {
});
}
+ downloadTemplate() {
+ this.api.getFoodExcelTemplate().subscribe((res) => {
+ console.log("res", res);
+ });
+ }
+
showImportForm(nzContent: TemplateRef<{}>) {
this.importModalRef = this.modal.create({
nzTitle: "导入食材清单",
@@ -169,15 +177,36 @@ export class FoodComponent implements OnInit, OnDestroy {
}
};
- onFileChange(files: FileList) {
+ onFileChange(e: FileList | Event) {
+ let files: FileList;
+ console.log(e instanceof FileList, e);
+ if (e instanceof FileList) {
+ files = e;
+ } else {
+ const target = e.target as HTMLInputElement;
+ console.log(e instanceof FileList, target.files);
+ files = target.files!;
+ }
if (files?.length > 0) {
const formData = new FormData();
- formData.append("files", files[0]);
- this.api.importFood(formData).subscribe((res) => {
- this.msg.success(res.desc);
- this.tableList.run();
- this.importModalRef?.close();
- });
+ formData.append("file", files[0]);
+ this.uploadLoading = true;
+ this.api
+ .importFood(formData)
+ .pipe(
+ finalize(() => {
+ this.uploadLoading = false;
+ })
+ )
+ .subscribe(() => {
+ this.msg.success("导入成功");
+ this.tableList.run();
+ this.importModalRef?.close();
+ });
+ }
+ if (e instanceof Event) {
+ const target = e.target as HTMLInputElement;
+ target.value = "";
}
}
}
diff --git a/projects/admin/src/app/pages/standard/standard-form/standard-form.component.html b/projects/admin/src/app/pages/standard/standard-form/standard-form.component.html
index cca922c..480f85d 100644
--- a/projects/admin/src/app/pages/standard/standard-form/standard-form.component.html
+++ b/projects/admin/src/app/pages/standard/standard-form/standard-form.component.html
@@ -26,14 +26,14 @@
适用单位
-
+
+
-
+
+
+
+
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 39bc4d8..779c2a5 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
@@ -7,7 +7,7 @@ import { OptionItemInterface } from "@cdk/types";
import { Utils } from "@cdk/utils";
import { FormValidators } from "@cdk/validators";
import { NzMessageService } from "ng-zorro-antd/message";
-import { finalize, map } from "rxjs";
+import { Subject, debounceTime, distinctUntilChanged, filter, finalize, map, switchMap } from "rxjs";
@Component({
selector: "app-standard-form",
@@ -33,6 +33,8 @@ export class StandardFormComponent {
}
}
+ private orgSearch$ = new Subject();
+
formGroup!: FormGroup;
submitLoading = false;
@@ -41,9 +43,13 @@ export class StandardFormComponent {
state: any;
- nzPopoverVisible = false;
+ // nzPopoverVisible = false;
+
+ // vendors: OptionItemInterface[] = [];
+
+ listOfOption: Array<{ value: number; text: string }> = [];
- vendors: OptionItemInterface[] = [];
+ nzFilterOption = (): boolean => true;
ngOnInit(): void {
this.formGroup = this.fb.group({
@@ -52,34 +58,59 @@ export class StandardFormComponent {
vendors: this.fb.control([], [FormValidators.required()]),
overflow: this.fb.control("0", [FormValidators.required()]),
});
- this.formGroup.patchValue(this.state);
+ if (this.state) {
+ this.formGroup.patchValue(this.state);
+ if (Array.isArray(this.state.vendors)) {
+ this.api.getOrgList({ vendors: this.state.vendors }).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.formGroup.patchValue(this.state);
+ });
+ }
+ }
+ this.orgSearch$
+ .pipe(
+ filter((f) => !!f),
+ debounceTime(500),
+ distinctUntilChanged(),
+ 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;
+ });
}
searchOrg = (k: string) => {
- return this.api.getOrgList({ keyword: k }).pipe(
- map((res) => {
- return res.body.map((i) => ({
- label: i.name,
- value: i.id + "",
- }));
- })
- );
+ this.orgSearch$.next(k);
};
- onSelectOrg(v: OptionItemInterface[]) {
- v.forEach((i) => {
- if (!this.vendors.some((s) => s.value === i.value)) {
- this.vendors.push(i);
- }
- });
- this.formGroup.get("vendors")?.setValue(this.vendors.map((i) => i.value));
- this.nzPopoverVisible = false;
- }
+ // onSelectOrg(v: OptionItemInterface[]) {
+ // v.forEach((i) => {
+ // if (!this.vendors.some((s) => s.value === i.value)) {
+ // this.vendors.push(i);
+ // }
+ // });
+ // this.formGroup.get("vendors")?.setValue(this.vendors.map((i) => i.value));
+ // this.nzPopoverVisible = false;
+ // }
- removeOrg(v: string) {
- this.vendors = this.vendors.filter((f) => f.value !== v);
- this.formGroup.get("vendors")?.setValue(this.vendors.map((i) => i.value));
- }
+ // removeOrg(v: string) {
+ // this.vendors = this.vendors.filter((f) => f.value !== v);
+ // this.formGroup.get("vendors")?.setValue(this.vendors.map((i) => i.value));
+ // }
onSubmit(gotoSetting?: boolean) {
if (Utils.validateFormGroup(this.formGroup)) {
diff --git a/projects/cdk/src/services/api.service.ts b/projects/cdk/src/services/api.service.ts
index d53653e..8d9c086 100644
--- a/projects/cdk/src/services/api.service.ts
+++ b/projects/cdk/src/services/api.service.ts
@@ -1,4 +1,4 @@
-import { HttpClient, HttpParams } from "@angular/common/http";
+import { HttpClient, HttpParams, HttpResponse } from "@angular/common/http";
import { Inject, Injectable, InjectionToken } from "@angular/core";
import { AnyObject, PageResult, ResponseType } from "@cdk/types";
import { Utils } from "@cdk/utils";
@@ -220,7 +220,29 @@ export class ApiService {
getFoodList(query: {}) {
const q = Utils.objectStringify(query);
- return this.http.get>(`/api/vender/select?${q}`);
+ return this.http.get>(`/api/ingredient/select?${q}`);
+ }
+
+ getFoodExcelTemplate() {
+ return this.http.get("/api/ingredient/excel", { observe: "response", responseType: "blob" as "json" }).pipe(
+ tap((res) => {
+ this.downLoadFile(res);
+ })
+ );
+ }
+
+ downLoadFile(response: HttpResponse