李志伟 před 3 roky
rodič
revize
f596f96a00

+ 102
- 61
src/pages/Machinery/Machinery/edit.jsx Zobrazit soubor

@@ -1,11 +1,14 @@
1
-import { Form, Input, Card, InputNumber, Select, message, Button } from 'antd';
1
+import { useState, useEffect } from 'react';
2
+import { Form, Input, Card, DatePicker, Select, InputNumber, message, Button } from 'antd';
2 3
 import { history } from 'umi';
3 4
 import ProCard from '@ant-design/pro-card';
4
-import { useState, useEffect } from 'react';
5
-// import { getTagList } from '@/services/tag';
6
-// import { addAttaList, gettaTouristForm, EditaddAttaList } from '@/services/AttaList'
5
+import { UploadImage, UploadImageList } from '@/components/Upload';
6
+import { addMachinery, updateMachinery, getMachineryDetail } from '@/services/machinery';
7
+import { getMachineryTypeList } from '@/services/machineryType';
8
+import { getRegionList } from '@/services/region';
9
+import { getCooperativeList } from '@/services/cooperative';
10
+import moment from 'moment';
7 11
 
8
-const { TextArea } = Input;
9 12
 const { Option } = Select;
10 13
 const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
11 14
 
@@ -17,43 +20,44 @@ export default (props) => {
17 20
   const { location } = props;
18 21
   const { id } = location.query;
19 22
   const [form] = Form.useForm();
20
-  const [listForm, setListForm] = useState({});
21 23
   const [loading, setLoading] = useState(false);
22 24
   const [imageList, setImageList] = useState([]);
25
+  //农机类型列表
26
+  const [machineryTypeList, setMachineryTypeList] = useState([]);
27
+  //区域列表
28
+  const [regionList, setRegionList] = useState([]);
29
+  //机构列表
30
+  const [cooperativeList, setCooperativeList] = useState([]);
23 31
 
24 32
   const Submit = (data) => {
25
-    const typeList = (data.typeList || []).map((x) => {
26
-      return { ...x, targetId: id, targetType: 'tourist' };
27
-    });
33
+    var newData = { ...data, buyDate: data.buyDate.format('YYYY-MM-DDTHH:mm:ss.SSS[Z]') };
28 34
     setLoading(true);
29 35
 
30
-    // if (id) {
31
-    //   EditaddAttaList(id, { ...listForm, ...data, imageList, typeList }).then(() => {
32
-    //     setLoading(false);
33
-    //     message.success('数据更新成功');
34
-    //     goBack();
35
-    //   })
36
-    //     .catch(err => {
37
-    //       setLoading(false);
38
-    //       message.error(err.message || err);
39
-    //     });
40
-    // } else {
41
-    //   addAttaList({ ...data, imageList, typeList }).then((res) => {
42
-    //     setLoading(false);
43
-    //     message.success('数据保存成功');
44
-    //     history.replace(`/Attractions/Edit?id=${res.touristId}`)
45
-    //   })
46
-    //     .catch(err => {
47
-    //       setLoading(false);
48
-    //       message.error(err.message || err);
49
-    //     });
50
-    // }
36
+    if (id) {
37
+      updateMachinery(id, newData)
38
+        .then(() => {
39
+          setLoading(false);
40
+          message.success('数据更新成功');
41
+          goBack();
42
+        })
43
+        .catch((err) => {
44
+          setLoading(false);
45
+          message.error(err.message || err);
46
+        });
47
+    } else {
48
+      addMachinery(newData)
49
+        .then((res) => {
50
+          setLoading(false);
51
+          message.success('数据保存成功');
52
+          goBack();
53
+        })
54
+        .catch((err) => {
55
+          setLoading(false);
56
+          message.error(err.message || err);
57
+        });
58
+    }
51 59
   };
52 60
 
53
-  //地址--占位
54
-  const [newLocName, setLocName] = useState('');
55
-  const [newAddress, setAddress] = useState('');
56
-
57 61
   const selectTagList = (params) => {
58 62
     // return getTagList({
59 63
     // }).then((res) => {
@@ -63,7 +67,7 @@ export default (props) => {
63 67
     //   }
64 68
     // })
65 69
   };
66
-
70
+  const onDateChange = () => {};
67 71
   const imageInput = (image) => {
68 72
     return {
69 73
       uid: image.imageId,
@@ -74,19 +78,25 @@ export default (props) => {
74 78
   const imageOutput = (image) => {
75 79
     return {
76 80
       imageId: image?.raw?.imageId,
77
-      shopId: id,
81
+      targetId: id,
78 82
       url: image.url,
79 83
     };
80 84
   };
81 85
   useEffect(() => {
82
-    selectTagList();
83
-    // if (id) {
84
-    //   gettaTouristForm(id).then((res) => {
85
-    //     setListForm(res)
86
-    //     form.setFieldsValue(res)
87
-    //     setImageList(res?.imageList || [])
88
-    //   })
89
-    // }
86
+    getMachineryTypeList().then((res) => {
87
+      setMachineryTypeList(res.records);
88
+    });
89
+    getRegionList().then((res) => {
90
+      setRegionList(res.records);
91
+    });
92
+    getCooperativeList().then((res) => {
93
+      setCooperativeList(res.records);
94
+    });
95
+    if (id) {
96
+      getMachineryDetail(id).then((res) => {
97
+        form.setFieldsValue({ ...res, buyDate: moment(res.buyDate, 'YYYY-MM-DD') });
98
+      });
99
+    }
90 100
   }, [id]);
91 101
 
92 102
   return (
@@ -107,44 +117,75 @@ export default (props) => {
107 117
               rules={[{ required: true, message: '请选择农机类型' }]}
108 118
             >
109 119
               <Select style={{ width: '350px' }}>
110
-                <Option value="6" key="6">
111
-                  {6}
112
-                </Option>
113
-                <Option value="7" key="7">
114
-                  {7}
115
-                </Option>
120
+                {machineryTypeList.map((item) => (
121
+                  <Option value={item.typeId} key={item.typeId}>
122
+                    {item.name}
123
+                  </Option>
124
+                ))}
116 125
               </Select>
117 126
             </FormItem>
127
+            <FormItem label="主图" name="thumb" rules={[{ required: true, message: '请选择主图' }]}>
128
+              <UploadImage />
129
+            </FormItem>
130
+            <FormItem label="农机图集" name="images">
131
+              <UploadImageList
132
+                value={imageList}
133
+                onChange={setImageList}
134
+                input={imageInput}
135
+                output={imageOutput}
136
+              />
137
+            </FormItem>
118 138
             <FormItem
119
-              label="农机归属"
139
+              label="区域"
120 140
               name="regionId"
121
-              rules={[{ required: true, message: '请选择农机归属' }]}
141
+              rules={[{ required: true, message: '请选择区域' }]}
122 142
             >
123 143
               <Select style={{ width: '350px' }}>
124
-                <Option value="6" key="6">
125
-                  {6}
126
-                </Option>
127
-                <Option value="7" key="7">
128
-                  {7}
129
-                </Option>
144
+                {regionList.map((item) => (
145
+                  <Option value={item.regionId} key={item.regionId}>
146
+                    {item.name}
147
+                  </Option>
148
+                ))}
149
+              </Select>
150
+            </FormItem>
151
+            <FormItem
152
+              label="归属机构"
153
+              name="orgId"
154
+              rules={[{ required: true, message: '请选择归属机构' }]}
155
+            >
156
+              <Select style={{ width: '350px' }}>
157
+                {cooperativeList.map((item) => (
158
+                  <Option value={item.orgId} key={item.orgId}>
159
+                    {item.name}
160
+                  </Option>
161
+                ))}
130 162
               </Select>
131 163
             </FormItem>
132 164
             <FormItem label="价格" name="price" rules={[{ required: true, message: '请输入价格' }]}>
133
-              <Input placeholder="请输入价格" style={{ width: '350px' }} />
165
+              <InputNumber placeholder="请输入价格" style={{ width: '350px' }} />
134 166
             </FormItem>
135 167
             <FormItem
136 168
               label="押金"
137 169
               name="deposit"
138 170
               rules={[{ required: true, message: '请输入押金' }]}
139 171
             >
140
-              <Input placeholder="请输入押金" style={{ width: '350px' }} />
172
+              <InputNumber placeholder="请输入押金" style={{ width: '350px' }} />
141 173
             </FormItem>
142 174
             <FormItem
143 175
               label="人工费"
144 176
               name="laborCost"
145 177
               rules={[{ required: true, message: '请输入人工费' }]}
146 178
             >
147
-              <Input placeholder="请输入人工费" style={{ width: '350px' }} />
179
+              <InputNumber placeholder="请输入人工费" style={{ width: '350px' }} />
180
+            </FormItem>
181
+            <FormItem label="购买时间" name="buyDate">
182
+              <DatePicker format="YYYY-MM-DD" onChange={onDateChange} style={{ width: '350px' }} />
183
+            </FormItem>
184
+            <FormItem label="状态" name="status" rules={[{ required: true, message: '请选择' }]}>
185
+              <Select placeholder="请选择是否发布" style={{ width: '350px' }}>
186
+                <Option value={1}>发布</Option>
187
+                <Option value={0}>未发布</Option>
188
+              </Select>
148 189
             </FormItem>
149 190
             <FormItem label=" " colon={false}>
150 191
               <Button type="default" onClick={() => goBack()}>

+ 89
- 15
src/pages/Machinery/Machinery/index.jsx Zobrazit soubor

@@ -1,26 +1,56 @@
1
-import React from 'react';
1
+import React, { useRef } from 'react';
2 2
 import { history, Link } from 'umi';
3
-import { Button, Popconfirm, message, Tooltip } from 'antd';
3
+import { Button, Popconfirm, message, Select, Modal } from 'antd';
4 4
 import { PlusOutlined } from '@ant-design/icons';
5
-// import { getPersonList, exportPersonList } from '@/services/person';
6 5
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
7 6
 import moment from 'moment';
8 7
 import PageTable from '@/components/PageTable';
8
+import { getMachineryList, deleteMachinery, updateMachinery } from '@/services/machinery';
9 9
 
10 10
 const formatterTime = (val) => {
11 11
   return val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : '';
12 12
 };
13
+const { Option } = Select;
13 14
 
14 15
 export default (props) => {
16
+  const actionRef = useRef();
17
+
18
+  const gotoEdit = (id) => {
19
+    const queryStr = id ? `?id=${id}` : '';
20
+    history.push(`./machinery/edit.jsx${queryStr}`);
21
+  };
22
+  const handleDelete = (id) => {
23
+    deleteMachinery(id).then(() => {
24
+      message.success('删除成功');
25
+      actionRef.current.reload();
26
+    });
27
+  };
28
+  //列表切换农机状态方法
29
+  const handleOK = (record, data) => {
30
+    const title = record.status
31
+      ? '您确定要将该农机状态变更为禁用吗? 禁用后该农机将不在移动端显示'
32
+      : '您确定要将该农机状态变更为启用吗? 启用后该农机可以在移动端显示';
33
+    Modal.confirm({
34
+      title: title,
35
+      okText: '确认',
36
+      cancelText: '取消',
37
+      onOk() {
38
+        updateMachinery(record.machineryId, { ...record, status: record.status === 1 ? 0 : 1 })
39
+          .then((res) => {
40
+            message.success('操作成功');
41
+            actionRef.current.reload();
42
+          })
43
+          .catch((err) => {
44
+            message.error(err);
45
+          });
46
+      },
47
+    });
48
+  };
15 49
   const actions = () => [
16 50
     <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoEdit()}>
17 51
       新增农机
18 52
     </Button>,
19 53
   ];
20
-  const gotoEdit = (id) => {
21
-    const queryStr = id ? `?id=${id}` : '';
22
-    history.push(`./machinery/edit.jsx${queryStr}`);
23
-  };
24 54
   const columns = [
25 55
     {
26 56
       title: '名称',
@@ -41,53 +71,97 @@ export default (props) => {
41 71
       title: '农机价格',
42 72
       dataIndex: 'price',
43 73
       key: 'price',
74
+      search: false,
44 75
     },
45 76
     {
46 77
       title: '人工费',
47 78
       dataIndex: 'laborCost',
48 79
       key: 'laborCost',
80
+      search: false,
49 81
     },
50 82
     {
51 83
       title: '押金',
52 84
       dataIndex: 'deposit',
53 85
       key: 'deposit',
86
+      search: false,
87
+    },
88
+    {
89
+      title: '主图',
90
+      dataIndex: 'thumb',
91
+      key: 'thumb',
92
+      width: 150,
93
+      render: (t) => <img width={110} src={t} alt="" />,
94
+      search: false,
54 95
     },
55 96
     {
56 97
       title: '工作状态',
57 98
       dataIndex: 'jobStatus',
58 99
       key: 'jobStatus',
100
+      renderFormItem: (item, field, form) => {
101
+        return (
102
+          <Select>
103
+            <Option value="1">忙碌</Option>
104
+            <Option value="0">空闲</Option>
105
+          </Select>
106
+        );
107
+      },
108
+      render: (_, record) => {
109
+        return record.jobStatus === 1 ? '忙碌' : '空闲';
110
+      },
59 111
     },
60 112
     {
61
-      title: '状态',
113
+      title: '发布状态',
62 114
       dataIndex: 'status',
63 115
       key: 'status',
116
+      renderFormItem: (item, field, form) => {
117
+        return (
118
+          <Select>
119
+            <Option value="1">发布</Option>
120
+            <Option value="0">未发布</Option>
121
+          </Select>
122
+        );
123
+      },
124
+      render: (_, record) => {
125
+        return record.status === 1 ? '发布' : '未发布';
126
+      },
64 127
     },
65 128
     {
66 129
       title: '操作',
67 130
       valueType: 'option',
68 131
       render: (_, record) => [
69
-        <Link key={1} to={`./machinery/edit.jsx`}>
132
+        <Button style={{ padding: 0 }} type="link" key={1} onClick={() => handleOK(record)}>
133
+          {record.status === 0 ? '发布' : '取消发布'}
134
+        </Button>,
135
+        <Button
136
+          style={{ padding: 0 }}
137
+          type="link"
138
+          key={2}
139
+          onClick={() => gotoEdit(record.machineryId)}
140
+        >
70 141
           编辑
71
-        </Link>,
142
+        </Button>,
72 143
         <Popconfirm
73
-          key={2}
144
+          key={3}
74 145
           title="您是否确认删除 ?"
75
-          onConfirm={() => handleDelete(record.cooperativeId)}
146
+          onConfirm={() => handleDelete(record.machineryId)}
76 147
           okText="确定"
77 148
           cancelText="取消"
78 149
         >
79
-          <a href="#">删除</a>
150
+          <Button style={{ padding: 0 }} type="link">
151
+            删除
152
+          </Button>
80 153
         </Popconfirm>,
81 154
       ],
82 155
     },
83 156
   ];
84
-  const handleDelete = () => {};
157
+
85 158
   return (
86 159
     <PageHeaderWrapper>
87 160
       <PageTable
88
-        // request={getPersonList}
161
+        request={getMachineryList}
89 162
         // expfunc={exportPersonList}
90 163
         toolBarRender={actions}
164
+        actionRef={actionRef}
91 165
         columns={columns}
92 166
         rowKey="machineryId"
93 167
         options={false}

+ 2
- 2
src/pages/Machinery/MachineryType/index.jsx Zobrazit soubor

@@ -28,8 +28,8 @@ export default (props) => {
28 28
   //列表切换分类状态方法
29 29
   const handleOK = (record, data) => {
30 30
     const title = record.status
31
-      ? '您确定要将该分类状态变更为禁用吗? 禁用后该分类将不能录'
32
-      : '您确定要将该分类状态变更为启用吗? 启用后该分类可以登录!';
31
+      ? '您确定要将该分类状态变更为禁用吗? 禁用后该分类将不能录入农机'
32
+      : '您确定要将该分类状态变更为启用吗? 启用后该分类可以录入农机';
33 33
     Modal.confirm({
34 34
       title: title,
35 35
       okText: '确认',

+ 36
- 0
src/services/machinery.js Zobrazit soubor

@@ -0,0 +1,36 @@
1
+import request from '@/utils/request';
2
+
3
+/**
4
+ * 保存农机
5
+ * @param {*} data
6
+ * @returns
7
+ */
8
+export const addMachinery = (data) => request('/machinery', { method: 'post', data });
9
+
10
+/**
11
+ * 修改农机
12
+ * @param {*} data
13
+ * @returns
14
+ */
15
+export const updateMachinery = (id, data) => request(`/machinery/${id}`, { method: 'put', data });
16
+
17
+/**
18
+ * 查询农机列表
19
+ * @param {*} params
20
+ * @returns
21
+ */
22
+export const getMachineryList = (params) => request('/machinery', { params });
23
+
24
+/**
25
+ * 删除农机
26
+ * @param {*} data
27
+ * @returns
28
+ */
29
+export const deleteMachinery = (id) => request(`/machinery/${id}`, { method: 'delete' });
30
+
31
+/**
32
+ * 查询农机详情
33
+ * @param {*} params
34
+ * @returns
35
+ */
36
+export const getMachineryDetail = (id) => request(`/machinery/${id}`);