|
@@ -1,5 +1,5 @@
|
1
|
1
|
import React, { useState } from 'react'
|
2
|
|
-import { Button, Row, Col, DatePicker, Form, Input, InputNumber, Radio, notification, Select } from 'antd'
|
|
2
|
+import { Button, Spin, DatePicker, Form, Input, InputNumber, Radio, notification, Select } from 'antd'
|
3
|
3
|
import FileUpload from '@/components/XForm/FileUpload'
|
4
|
4
|
import ImageUpload from '@/components/XForm/ImageUpload'
|
5
|
5
|
import ImageListUpload from '@/components/XForm/ImageListUpload'
|
|
@@ -12,15 +12,27 @@ import OpenTimePicker from '../components/OpenTimePicker'
|
12
|
12
|
import EditableArround from '../components/EditableArround'
|
13
|
13
|
import FormGroupItem, { gourpItemLayout } from '../components/FormGroupItem'
|
14
|
14
|
import { formItemLayout, validMinNum } from '../utils'
|
|
15
|
+import useTags from './tag'
|
15
|
16
|
|
16
|
17
|
const fullWidth= { width: '100%' }
|
17
|
18
|
const Item = Form.Item
|
18
|
|
-const initPoiData = POI_TYPES.map((poi) => poi.key).reduce((acc, key) => ({ ...acc, [key]: undefined }), {})
|
19
|
19
|
|
20
|
20
|
const BuildingBasic = React.forwardRef((props, ref) => {
|
21
|
|
- const [pois, setPois] = useState(initPoiData)
|
22
|
21
|
const { form } = props;
|
23
|
22
|
const { getFieldDecorator, getFieldValue, setFieldsValue } = form;
|
|
23
|
+
|
|
24
|
+ const [ loading, setLoading ] = useState({ arround: false })
|
|
25
|
+ const [
|
|
26
|
+ tags,
|
|
27
|
+ initTags,
|
|
28
|
+ updateTags,
|
|
29
|
+ deletePoi,
|
|
30
|
+ initPois,
|
|
31
|
+ pois2Tags,
|
|
32
|
+ // updatePois,
|
|
33
|
+ deleteTag,
|
|
34
|
+ updatePoisAndTags,
|
|
35
|
+ ] = useTags()
|
24
|
36
|
|
25
|
37
|
// 视频文件上传前 回调
|
26
|
38
|
const fileUploadBeforeUpload = (file, fileList) => {
|
|
@@ -44,22 +56,33 @@ const BuildingBasic = React.forwardRef((props, ref) => {
|
44
|
56
|
}
|
45
|
57
|
|
46
|
58
|
const lngLat = getFieldValue('coordinate').split(',')
|
47
|
|
- let poisCopy = { ...pois }
|
48
|
59
|
|
49
|
60
|
// 把支持的周边分类都去检索一遍
|
50
|
|
- POI_TYPES.forEach(({ key }) => {
|
51
|
|
- getPoiData({ type: key, location: lngLat, radius: e }).then(res => {
|
52
|
|
- const poiStr = (res.pois || []).map((p) => p.name).join(',')
|
53
|
|
- poisCopy = {
|
54
|
|
- ...poisCopy,
|
55
|
|
- [key]: poiStr
|
|
61
|
+ setLoading({ ...loading, arround: true })
|
|
62
|
+ Promise.all(POI_TYPES.map(({ key }) => getPoiData({ type: key, location: lngLat, radius: e }))).then((res) => {
|
|
63
|
+ const pois = POI_TYPES.reduce((acc, { key }, inx) => {
|
|
64
|
+ return {
|
|
65
|
+ ...acc,
|
|
66
|
+ [key]: (res[inx] || {}).pois || []
|
56
|
67
|
}
|
57
|
|
- setPois({ ...poisCopy })
|
58
|
|
- }).catch(err => {
|
59
|
|
- console.error(err)
|
60
|
|
- notification.error({ message: '周边数据获取失败' })
|
61
|
|
- })
|
|
68
|
+ }, {})
|
|
69
|
+
|
|
70
|
+ updatePoisAndTags(pois)
|
|
71
|
+ setLoading({ ...loading, arround: false })
|
|
72
|
+ }).catch((err) => {
|
|
73
|
+ setLoading({ ...loading, arround: false })
|
|
74
|
+ console.error(err)
|
|
75
|
+ notification.error({ message: '周边数据获取异常' })
|
62
|
76
|
})
|
|
77
|
+
|
|
78
|
+ // POI_TYPES.forEach(({ key }) => {
|
|
79
|
+ // getPoiData({ type: key, location: lngLat, radius: e }).then(res => {
|
|
80
|
+ // updatePois(key, res.pois || [])
|
|
81
|
+ // }).catch(err => {
|
|
82
|
+ // console.error(err)
|
|
83
|
+ // notification.error({ message: '周边数据获取失败' })
|
|
84
|
+ // })
|
|
85
|
+ // })
|
63
|
86
|
}
|
64
|
87
|
|
65
|
88
|
return (
|
|
@@ -201,36 +224,56 @@ const BuildingBasic = React.forwardRef((props, ref) => {
|
201
|
224
|
</Select>,
|
202
|
225
|
)}
|
203
|
226
|
</Form.Item>
|
204
|
|
- <Form.Item label="周边交通" >
|
205
|
|
- {getFieldDecorator('buildingTransport')(
|
206
|
|
- <EditableArround pois={pois[POI_TYPES_KETY.Transport]} />,
|
207
|
|
- )}
|
208
|
|
- </Form.Item>
|
209
|
|
- <Form.Item label="周边商业" >
|
210
|
|
- {getFieldDecorator('buildingMall')(
|
211
|
|
- <EditableArround pois={pois[POI_TYPES_KETY.Mall]} />,
|
212
|
|
- )}
|
213
|
|
- </Form.Item>
|
214
|
|
- <Form.Item label="周边学校" >
|
215
|
|
- {getFieldDecorator('buildingEdu')(
|
216
|
|
- <EditableArround pois={pois[POI_TYPES_KETY.Edu]} />,
|
217
|
|
- )}
|
218
|
|
- </Form.Item>
|
219
|
|
- <Form.Item label="周边医院" >
|
220
|
|
- {getFieldDecorator('buildingHospital')(
|
221
|
|
- <EditableArround pois={pois[POI_TYPES_KETY.Hospital]} />,
|
222
|
|
- )}
|
223
|
|
- </Form.Item>
|
224
|
|
- <Form.Item label="周边银行" >
|
225
|
|
- {getFieldDecorator('buildingBank')(
|
226
|
|
- <EditableArround pois={pois[POI_TYPES_KETY.Bank]} />,
|
227
|
|
- )}
|
228
|
|
- </Form.Item>
|
229
|
|
- <Form.Item label="周边餐饮" >
|
230
|
|
- {getFieldDecorator('buildingRestaurant')(
|
231
|
|
- <EditableArround pois={pois[POI_TYPES_KETY.Restaurant]} />,
|
232
|
|
- )}
|
233
|
|
- </Form.Item>
|
|
227
|
+ <Spin spinning={loading.arround}>
|
|
228
|
+ <Form.Item label="周边交通" >
|
|
229
|
+ <EditableArround
|
|
230
|
+ tags={tags.buildingTransport}
|
|
231
|
+ onChange={(e) => updateTags('buildingTransport', e)}
|
|
232
|
+ onDelete={(tag) => deleteTag('buildingTransport', tag)}
|
|
233
|
+ onPoiDelete={(poi) => deletePoi('Transport', poi)}
|
|
234
|
+ />
|
|
235
|
+ </Form.Item>
|
|
236
|
+ <Form.Item label="周边商业" >
|
|
237
|
+ <EditableArround
|
|
238
|
+ tags={tags.buildingMall}
|
|
239
|
+ onChange={(e) => updateTags('buildingMall', e)}
|
|
240
|
+ onDelete={(tag) => deleteTag('buildingMall', tag)}
|
|
241
|
+ onPoiDelete={(poi) => deletePoi('Mall', poi)}
|
|
242
|
+ />
|
|
243
|
+ </Form.Item>
|
|
244
|
+ <Form.Item label="周边学校" >
|
|
245
|
+ <EditableArround
|
|
246
|
+ tags={tags.buildingEdu}
|
|
247
|
+ onChange={(e) => updateTags('buildingEdu', e)}
|
|
248
|
+ onDelete={(tag) => deleteTag('buildingEdu', tag)}
|
|
249
|
+ onPoiDelete={(poi) => deletePoi('Edu', poi)}
|
|
250
|
+ />
|
|
251
|
+ </Form.Item>
|
|
252
|
+ <Form.Item label="周边医院" >
|
|
253
|
+ <EditableArround
|
|
254
|
+ tags={tags.buildingHospital}
|
|
255
|
+ onChange={(e) => updateTags('buildingHospital', e)}
|
|
256
|
+ onDelete={(tag) => deleteTag('buildingHospital', tag)}
|
|
257
|
+ onPoiDelete={(poi) => deletePoi('Hospital', poi)}
|
|
258
|
+ />
|
|
259
|
+ </Form.Item>
|
|
260
|
+ <Form.Item label="周边银行" >
|
|
261
|
+ <EditableArround
|
|
262
|
+ tags={tags.buildingBank}
|
|
263
|
+ onChange={(e) => updateTags('buildingBank', e)}
|
|
264
|
+ onDelete={(tag) => deleteTag('buildingBank', tag)}
|
|
265
|
+ onPoiDelete={(poi) => deletePoi('Bank', poi)}
|
|
266
|
+ />
|
|
267
|
+ </Form.Item>
|
|
268
|
+ <Form.Item label="周边餐饮" >
|
|
269
|
+ <EditableArround
|
|
270
|
+ tags={tags.buildingRestaurant}
|
|
271
|
+ onChange={(e) => updateTags('buildingRestaurant', e)}
|
|
272
|
+ onDelete={(tag) => deleteTag('buildingRestaurant', tag)}
|
|
273
|
+ onPoiDelete={(poi) => deletePoi('Restaurant', poi)}
|
|
274
|
+ />
|
|
275
|
+ </Form.Item>
|
|
276
|
+ </Spin>
|
234
|
277
|
<FormGroupItem>
|
235
|
278
|
<Form.Item label="绿化率" {...gourpItemLayout.ab.a } >
|
236
|
279
|
{getFieldDecorator('greeningRate')(<Input />)}
|