|
@@ -1,58 +1,46 @@
|
1
|
|
-import { addDish, updataDish, getDishById, getDishList, getFoodIngredientsList } from '@/services/api/dish';
|
2
|
|
-import { queryTable } from '@/utils/request';
|
3
|
|
-import { PageContainer, ProForm, ProFormDigit, ProFormText, ModalForm, ProFormSelect } from '@ant-design/pro-components';
|
|
1
|
+import { addDish, getDishById } from '@/services/api/dish';
|
|
2
|
+import { getStoreList } from '@/services/api/stock';
|
|
3
|
+import { PageContainer, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
4
|
4
|
import { history, useSearchParams } from '@umijs/max';
|
5
|
|
-import { Card, Col, message, Row, Space, Image, Select, Option } from 'antd';
|
6
|
|
-import { values } from 'lodash';
|
|
5
|
+import { Card, Col, message, Row, Space } from 'antd';
|
7
|
6
|
import { useEffect, useRef, useState } from 'react';
|
8
|
7
|
|
9
|
8
|
export default (props) => {
|
10
|
9
|
const [searchParams] = useSearchParams();
|
11
|
10
|
const id = searchParams.get('id');
|
12
|
|
- const [datas, setDatas] = useState([]);
|
13
|
|
- const [data, setData] = useState({});
|
|
11
|
+ const [foodDict, setFoodDict] = useState([]);
|
|
12
|
+
|
14
|
13
|
const formRef = useRef();
|
15
|
14
|
useEffect(() => {
|
16
|
|
-
|
17
|
|
- getFoodIngredientsList().then((res) => {
|
18
|
|
- setDatas(res?.records?.map((x) => ({
|
19
|
|
- label: x.name,
|
20
|
|
- value: x.dishId
|
21
|
|
- })))
|
22
|
|
-
|
|
15
|
+ getStoreList({ isDish: 1, pageSize: 9999 }).then((res) => {
|
|
16
|
+ setFoodDict(
|
|
17
|
+ res?.records?.map((x) => ({
|
|
18
|
+ label: x.name,
|
|
19
|
+ value: x.id,
|
|
20
|
+ })),
|
|
21
|
+ );
|
23
|
22
|
});
|
24
|
23
|
}, [id]);
|
25
|
24
|
|
26
|
25
|
useEffect(() => {
|
27
|
26
|
if (id) {
|
28
|
27
|
getDishById(id).then((res) => {
|
29
|
|
- setData(res);
|
30
|
|
-
|
31
|
28
|
formRef.current.setFieldsValue(res);
|
32
|
29
|
});
|
33
|
30
|
}
|
34
|
31
|
}, [id]);
|
35
|
32
|
|
36
|
33
|
const onFinish = async (values) => {
|
|
34
|
+ console.log(values, '===');
|
37
|
35
|
|
38
|
|
-
|
39
|
|
- if (id) {
|
40
|
|
- // 修改
|
41
|
|
- updataDish(id, { ...values }).then((res) => {
|
42
|
|
- message.success('修改成功');
|
43
|
|
- history.back();
|
44
|
|
- });
|
45
|
|
- } else {
|
46
|
|
- // 新增
|
47
|
|
- addDish({ ...values }).then((res) => {
|
48
|
|
- message.success('添加成功');
|
49
|
|
- history.back();
|
50
|
|
- });
|
51
|
|
- }
|
|
36
|
+ addDish({ ...values, id }).then((res) => {
|
|
37
|
+ message.success('添加成功');
|
|
38
|
+ history.back();
|
|
39
|
+ });
|
52
|
40
|
|
53
|
41
|
return false;
|
54
|
42
|
};
|
55
|
|
- console.log("datas", datas)
|
|
43
|
+
|
56
|
44
|
return (
|
57
|
45
|
<PageContainer>
|
58
|
46
|
<Card>
|
|
@@ -73,21 +61,37 @@ export default (props) => {
|
73
|
61
|
<Row>
|
74
|
62
|
<Col span={8} offset={8}>
|
75
|
63
|
<Space>{doms}</Space>
|
76
|
|
-
|
77
|
64
|
</Col>
|
78
|
65
|
</Row>
|
79
|
66
|
);
|
80
|
67
|
},
|
81
|
68
|
}}
|
82
|
69
|
>
|
83
|
|
- <ProFormText name="name" label="菜肴名称" placeholder="请输入菜肴名称" width={460} />
|
84
|
|
- <ProFormText name="unit" label="菜肴单位" placeholder="请输入菜肴单位" width={460} />
|
85
|
|
- <ProFormSelect mode="multiple" label="包含食材" placeholder="多选下拉" width={460}
|
86
|
|
- options={datas}
|
|
70
|
+ <ProFormText
|
|
71
|
+ name="name"
|
|
72
|
+ label="菜肴名称"
|
|
73
|
+ placeholder="请输入菜肴名称"
|
|
74
|
+ rules={[{ required: true, message: '请输入菜肴名称' }]}
|
|
75
|
+ width={460}
|
|
76
|
+ />
|
|
77
|
+ <ProFormText
|
|
78
|
+ name="unit"
|
|
79
|
+ label="菜肴单位"
|
|
80
|
+ placeholder="请输入菜肴单位"
|
|
81
|
+ rules={[{ required: true, message: '请输入菜肴单位' }]}
|
|
82
|
+ width={460}
|
|
83
|
+ />
|
|
84
|
+ <ProFormSelect
|
|
85
|
+ mode="multiple"
|
|
86
|
+ name="ingredientsIdList"
|
|
87
|
+ label="包含食材"
|
|
88
|
+ placeholder="请选择包含食材"
|
|
89
|
+ rules={[{ required: true, message: '请选择包含食材' }]}
|
|
90
|
+ width={460}
|
|
91
|
+ options={foodDict}
|
87
|
92
|
/>
|
88
|
93
|
</ProForm>
|
89
|
94
|
</Card>
|
90
|
95
|
</PageContainer>
|
91
|
|
-
|
92
|
96
|
);
|
93
|
|
-};
|
|
97
|
+};
|