ソースを参照

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

Yansen 2 年 前
コミット
225205668c
共有2 個のファイルを変更した44 個の追加49 個の削除を含む
  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 ファイルの表示

@@ -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
+};

+ 2
- 11
src/pages/dish/list/index.jsx ファイルの表示

@@ -42,7 +42,7 @@ const DishList = (props) => {
42 42
     },
43 43
     {
44 44
       title: '包含食材(种)',
45
-      dataIndex: 'status',
45
+      dataIndex: 'foodNum',
46 46
       search: false,
47 47
     },
48 48
     {
@@ -50,16 +50,7 @@ const DishList = (props) => {
50 50
       valueType: 'option',
51 51
       width: 200,
52 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 54
         <Button
64 55
           key={2}
65 56
           style={{ padding: 0 }}