张延森 3 anos atrás
pai
commit
bff78a164e

+ 61
- 0
src/components/SelectButton/InstitutionSelect.jsx Ver arquivo

1
+import React, { useEffect, useMemo, useRef, useState } from 'react'
2
+import { TreeSelect } from 'antd'
3
+import { connect } from 'dva'
4
+
5
+const getTreeFrom = (arr) => {
6
+  const copy = (arr || []).map((it) => ({ ...it, children: undefined }))
7
+
8
+  const tree = []
9
+  for (let inx in copy) {
10
+    const it = copy[inx]
11
+    const key = it.institutionCode
12
+    const node = {
13
+      key,
14
+      value: key,
15
+      title: it.institutionName,
16
+      children: it.children,
17
+      parent: it.parent,
18
+    }
19
+    const parent = key.length === 2 ? undefined : key.substring(0, key.length - 2)
20
+
21
+    if (parent) {
22
+      for (let cur of copy) {
23
+        if ((cur.institutionCode || cur.key) === parent) {
24
+          node.parent = cur
25
+          cur.children = [
26
+            ...(cur.children || []),
27
+            node,
28
+          ]
29
+          break
30
+        }
31
+      }
32
+    }
33
+
34
+    copy[inx] = node
35
+    tree.push(node)
36
+  }
37
+  return tree.filter(x => !x.parent)
38
+}
39
+
40
+const InstitutionSelect = React.forwardRef((props, ref) => {
41
+
42
+  const { user, ...leftProps } = props
43
+
44
+  const [expandedKeys, setExpandedKeys] = useState([])
45
+
46
+  const treeData = useMemo(() => {
47
+    return getTreeFrom(user.institutionList) || []
48
+  }, [user.institutionList])
49
+
50
+  useEffect(() => {
51
+    setExpandedKeys((user.institutionList || []).map((x) => x.institutionCode))
52
+  }, [user.institutionList])
53
+
54
+  return (
55
+    <TreeSelect allowClear treeExpandedKeys={expandedKeys} onTreeExpand={setExpandedKeys} {...leftProps} treeData={treeData} />
56
+  )
57
+})
58
+
59
+export default connect(({ user }) => ({
60
+  user: user.currentUser,
61
+}))(InstitutionSelect)

+ 2
- 9
src/pages/building/Edit/Basic/index.jsx Ver arquivo

6
 import ImageListUpload from '@/components/XForm/ImageListUpload'
6
 import ImageListUpload from '@/components/XForm/ImageListUpload'
7
 import SelectCity from '@/components/SelectButton/CitySelect'
7
 import SelectCity from '@/components/SelectButton/CitySelect'
8
 import AreaSelect from '@/components/SelectButton/AreaSelect'
8
 import AreaSelect from '@/components/SelectButton/AreaSelect'
9
+import InstitutionSelect from '@/components/SelectButton/InstitutionSelect'
9
 import { POI_TYPES_KETY, POI_TYPES, getPoiData } from '@/utils/map'
10
 import { POI_TYPES_KETY, POI_TYPES, getPoiData } from '@/utils/map'
10
 import Amap from '../components/Amap'
11
 import Amap from '../components/Amap'
11
 import BuildingType from '../components/BuildingTypeSelect'
12
 import BuildingType from '../components/BuildingTypeSelect'
130
         </Item>
131
         </Item>
131
         <Item label="城市公司">
132
         <Item label="城市公司">
132
           {getFieldDecorator('institutionId')(
133
           {getFieldDecorator('institutionId')(
133
-            <Select placeholder="所属城市公司" style={fullWidth}>
134
-              {
135
-                (user.institutionList || []).map((item) => (
136
-                  <Select.Option key={item.institutionId} value={item.institutionId}>
137
-                    {item.institutionName}
138
-                  </Select.Option>
139
-                ))
140
-              }
141
-            </Select>
134
+            <InstitutionSelect />
142
           )}
135
           )}
143
         </Item>
136
         </Item>
144
         <Item label="楼盘编号" >
137
         <Item label="楼盘编号" >

+ 5
- 3
src/pages/building/Edit/components/BuildingTypeDetail.jsx Ver arquivo

31
       };
31
       };
32
 
32
 
33
       const data = {
33
       const data = {
34
+        status: 1,
34
         ...dataset || {},
35
         ...dataset || {},
35
         ...values,
36
         ...values,
36
       }
37
       }
43
   }
44
   }
44
 
45
 
45
   useEffect(() => {
46
   useEffect(() => {
47
+    if (!dataset.rightsYear) {
48
+      dataset.rightsYear = 70
49
+    }
46
     form.setFieldsValue(dataset)
50
     form.setFieldsValue(dataset)
47
   }, [dataset])
51
   }, [dataset])
48
 
52
 
88
           {getFieldDecorator('decoration')(<Input />)}
92
           {getFieldDecorator('decoration')(<Input />)}
89
         </Item>
93
         </Item>
90
         <Item label="产权年限" {...formItemLayout}>
94
         <Item label="产权年限" {...formItemLayout}>
91
-          {getFieldDecorator('rightsYear', {
92
-            initialValue: 70,
93
-          })(<Input />)}
95
+          {getFieldDecorator('rightsYear')(<Input />)}
94
         </Item>
96
         </Item>
95
       </Form>
97
       </Form>
96
       <div className={styles['drawer-form-action']}>
98
       <div className={styles['drawer-form-action']}>

+ 10
- 2
src/pages/building/Edit/components/BuildingTypeSelect.jsx Ver arquivo

16
   padding: '0',
16
   padding: '0',
17
 }
17
 }
18
 
18
 
19
+const fillTypeName = (data, typeList) => (data || []).map((it) => {
20
+  const typ = typeList.filter((x) => x.buildingTypeId === it.buildingTypeId)[0]
21
+  return {
22
+    ...it,
23
+    buildingTypeName: typ ? typ.buildingTypeName : it.buildingTypeName
24
+  }
25
+})
26
+
19
 export default React.forwardRef((props, ref) => {
27
 export default React.forwardRef((props, ref) => {
20
   const {value, onChange} = props;
28
   const {value, onChange} = props;
21
   const [showDrawer, setShowDrawer] = useState(false)
29
   const [showDrawer, setShowDrawer] = useState(false)
35
     } else {
43
     } else {
36
       // 取消选择
44
       // 取消选择
37
       const data = (value || []).filter((it) => it.buildingTypeId !== buildingType.buildingTypeId)
45
       const data = (value || []).filter((it) => it.buildingTypeId !== buildingType.buildingTypeId)
38
-      onChange(data)
46
+      onChange(fillTypeName(data, typeList))
39
     }
47
     }
40
   }
48
   }
41
 
49
 
68
       data.push(val)
76
       data.push(val)
69
     }
77
     }
70
 
78
 
71
-    onChange(data)
79
+    onChange(fillTypeName(data, typeList))
72
     setShowDrawer(false)
80
     setShowDrawer(false)
73
   }
81
   }
74
 
82