张延森 vor 3 Jahren
Ursprung
Commit
bff78a164e

+ 61
- 0
src/components/SelectButton/InstitutionSelect.jsx Datei anzeigen

@@ -0,0 +1,61 @@
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 Datei anzeigen

@@ -6,6 +6,7 @@ import ImageUpload from '@/components/XForm/ImageUpload'
6 6
 import ImageListUpload from '@/components/XForm/ImageListUpload'
7 7
 import SelectCity from '@/components/SelectButton/CitySelect'
8 8
 import AreaSelect from '@/components/SelectButton/AreaSelect'
9
+import InstitutionSelect from '@/components/SelectButton/InstitutionSelect'
9 10
 import { POI_TYPES_KETY, POI_TYPES, getPoiData } from '@/utils/map'
10 11
 import Amap from '../components/Amap'
11 12
 import BuildingType from '../components/BuildingTypeSelect'
@@ -130,15 +131,7 @@ const BuildingBasic = React.forwardRef((props, ref) => {
130 131
         </Item>
131 132
         <Item label="城市公司">
132 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 136
         </Item>
144 137
         <Item label="楼盘编号" >

+ 5
- 3
src/pages/building/Edit/components/BuildingTypeDetail.jsx Datei anzeigen

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

+ 10
- 2
src/pages/building/Edit/components/BuildingTypeSelect.jsx Datei anzeigen

@@ -16,6 +16,14 @@ const gridBtn = {
16 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 27
 export default React.forwardRef((props, ref) => {
20 28
   const {value, onChange} = props;
21 29
   const [showDrawer, setShowDrawer] = useState(false)
@@ -35,7 +43,7 @@ export default React.forwardRef((props, ref) => {
35 43
     } else {
36 44
       // 取消选择
37 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,7 +76,7 @@ export default React.forwardRef((props, ref) => {
68 76
       data.push(val)
69 77
     }
70 78
 
71
-    onChange(data)
79
+    onChange(fillTypeName(data, typeList))
72 80
     setShowDrawer(false)
73 81
   }
74 82