Browse Source

Merge branch 'master' of http://git.ycjcjy.com/jgz/admin

Yansen 2 years ago
parent
commit
225205668c
2 changed files with 44 additions and 49 deletions
  1. 42
    38
      src/pages/dish/edit/index.jsx
  2. 2
    11
      src/pages/dish/list/index.jsx

+ 42
- 38
src/pages/dish/edit/index.jsx View File

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
 import { history, useSearchParams } from '@umijs/max';
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
 import { useEffect, useRef, useState } from 'react';
6
 import { useEffect, useRef, useState } from 'react';
8
 
7
 
9
 export default (props) => {
8
 export default (props) => {
10
   const [searchParams] = useSearchParams();
9
   const [searchParams] = useSearchParams();
11
   const id = searchParams.get('id');
10
   const id = searchParams.get('id');
12
-  const [datas, setDatas] = useState([]);
13
-  const [data, setData] = useState({});
11
+  const [foodDict, setFoodDict] = useState([]);
12
+
14
   const formRef = useRef();
13
   const formRef = useRef();
15
   useEffect(() => {
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
   }, [id]);
23
   }, [id]);
25
 
24
 
26
   useEffect(() => {
25
   useEffect(() => {
27
     if (id) {
26
     if (id) {
28
       getDishById(id).then((res) => {
27
       getDishById(id).then((res) => {
29
-        setData(res);
30
-
31
         formRef.current.setFieldsValue(res);
28
         formRef.current.setFieldsValue(res);
32
       });
29
       });
33
     }
30
     }
34
   }, [id]);
31
   }, [id]);
35
 
32
 
36
   const onFinish = async (values) => {
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
     return false;
41
     return false;
54
   };
42
   };
55
-  console.log("datas", datas)
43
+
56
   return (
44
   return (
57
     <PageContainer>
45
     <PageContainer>
58
       <Card>
46
       <Card>
73
                 <Row>
61
                 <Row>
74
                   <Col span={8} offset={8}>
62
                   <Col span={8} offset={8}>
75
                     <Space>{doms}</Space>
63
                     <Space>{doms}</Space>
76
-
77
                   </Col>
64
                   </Col>
78
                 </Row>
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
         </ProForm>
93
         </ProForm>
89
       </Card>
94
       </Card>
90
     </PageContainer>
95
     </PageContainer>
91
-
92
   );
96
   );
93
-};
97
+};

+ 2
- 11
src/pages/dish/list/index.jsx View File

42
     },
42
     },
43
     {
43
     {
44
       title: '包含食材(种)',
44
       title: '包含食材(种)',
45
-      dataIndex: 'status',
45
+      dataIndex: 'foodNum',
46
       search: false,
46
       search: false,
47
     },
47
     },
48
     {
48
     {
50
       valueType: 'option',
50
       valueType: 'option',
51
       width: 200,
51
       width: 200,
52
       render: (_, record) => [
52
       render: (_, record) => [
53
-        <Button
54
-          key={1}
55
-          style={{ padding: 0 }}
56
-          type="link"
57
-          onClick={() => {
58
-            updata(record);
59
-          }}
60
-        >
61
-          {/* {record.state === '1' ? '下架' : '上架'} */}
62
-        </Button>,
53
+
63
         <Button
54
         <Button
64
           key={2}
55
           key={2}
65
           style={{ padding: 0 }}
56
           style={{ padding: 0 }}