傅行帆 5 anos atrás
pai
commit
2e3cc032ad

+ 63
- 0
src/components/SelectButton/AreaSelect.jsx Ver arquivo

@@ -0,0 +1,63 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Select } from 'antd';
3
+
4
+import request from '../../utils/request'
5
+
6
+const { Option } = Select;
7
+
8
+/**
9
+ *
10
+ *
11
+ * @param {*} props
12
+ * @returns
13
+ */
14
+const CitySelect = (props) => {
15
+  const [ data, setData ] = useState([])
16
+  const cityId = typeof props.cityId === 'function' ? props.cityId() : props.cityId
17
+
18
+  useEffect(() => {
19
+    getCityAreaList();
20
+    getValue();
21
+  },[cityId])
22
+
23
+  const getCityAreaList = (e) => {
24
+    request({
25
+        url: '/api/admin/tdCityList/tdAreaCity',
26
+        method: 'GET',
27
+        params: {leveltype: 3, cityId},
28
+        action: 'select',
29
+    }).then((data) => {
30
+        setData(data)
31
+    })
32
+  }
33
+
34
+  /**
35
+   * 因为 有个需求是,如果这个城市被删除了,那么就直接展示为空,不能展示 cityId
36
+   */
37
+  const getValue = () => {
38
+    if (props.value) {
39
+      const tempData = data.filter(f => f.id == props.value)
40
+      const va = (tempData.length > 0) ? props.value : undefined
41
+      props.onChange(va)
42
+    }
43
+  }
44
+
45
+  return (
46
+      <Select
47
+      {...props}
48
+      showSearch
49
+      value={props.value}
50
+      style={{ width: '300px' }}
51
+      placeholder="请选择城市"
52
+      onChange={props.onChange}
53
+      filterOption={(input, option) =>
54
+        option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
55
+      }
56
+      >
57
+          {data.map(city => (
58
+            <Option key={city.id} value={city.name}>{city.name}</Option>
59
+          ))}
60
+      </Select>
61
+  )
62
+}
63
+export default CitySelect

+ 14
- 2
src/pages/building/list/add/components/base.jsx Ver arquivo

@@ -15,6 +15,7 @@ import Amap from './amap'
15 15
 import BudildingProjectType from './buildingProjectType'
16 16
 import DragableUploadImageList from '@/components/DragableUploadImageList'
17 17
 import SelectCity from '../../../../../components/SelectButton/CitySelect'
18
+import AreaSelect from '../../../../../components/SelectButton/AreaSelect'
18 19
 import FileUpload from '@/components/XForm/FileUpload';
19 20
 import { POI_TYPES_KETY, getAroundData, getPOIType, POI_TYPES } from './amapAroundData'
20 21
 
@@ -48,6 +49,7 @@ function AddBuilding(props) {
48 49
   const [poi, setPoi] = useState([])
49 50
   const [videoImage, setVideoImage] = useState(false)
50 51
   const [typeState, setTypeState] = useState("rich")
52
+  const [cityId, setCityId] = useState("")
51 53
 
52 54
   // 存放所以 buildingData 基础信息
53 55
   const [buildingData, setBuildingData] = useState({})
@@ -121,6 +123,7 @@ function AddBuilding(props) {
121 123
       res.buildingRestaurant = stringHandleTag(res.buildingRestaurant)
122 124
 
123 125
       setBuildingData(res)
126
+
124 127
       props.form.setFieldsValue(res)
125 128
       // console.log('mapJson: ', JSON.parse(res.mapJson))
126 129
       setPoi((res.mapJson && JSON.parse(res.mapJson)) || [])
@@ -324,6 +327,15 @@ function AddBuilding(props) {
324 327
     return newPoi
325 328
   }
326 329
 
330
+  function cityChange(e) {
331
+    setCityId(e)
332
+    setTimeout(()=>{
333
+      props.form.setFieldsValue({
334
+          'buildingArea': buildingData.buildingArea
335
+      })
336
+  },0)
337
+  }
338
+
327 339
   function setFormMapScopeTagValue(keyType, item) {
328 340
     const tag = item.data.map(t => ({ tagName: t.name, delete: true, automatic: true }))
329 341
     switch (keyType) {
@@ -487,13 +499,13 @@ function AddBuilding(props) {
487 499
             {getFieldDecorator('cityId', {
488 500
               rules: [{ required: true, message: '请选择城市' }],
489 501
             })(
490
-              <SelectCity />,
502
+              <SelectCity onChange={(e) => cityChange(e)}/>,
491 503
             )}
492 504
           </Form.Item>
493 505
           <Form.Item label="楼盘区域" >
494 506
             {getFieldDecorator('buildingArea', {
495 507
               rules: [{ required: true, message: '请输入楼盘区域' }],
496
-            })(<Input />)}
508
+            })(<AreaSelect cityId={cityId}/>)}
497 509
           </Form.Item>
498 510
           <Form.Item label="项目地址" >
499 511
             {getFieldDecorator('address', {