|
@@ -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()}>
|