|
@@ -0,0 +1,243 @@
|
|
1
|
+import React, { useRef, useState, useEffect } from 'react'
|
|
2
|
+import { Form, Input, Select, Button, Radio, Modal, Descriptions } from 'antd'
|
|
3
|
+import router from 'umi/router'
|
|
4
|
+import { fetch, apis } from '@/utils/request'
|
|
5
|
+
|
|
6
|
+const fetchPhaseList = fetch(apis.buildingOwnerInfo.getPhaseList)
|
|
7
|
+const fetchBuildingList = fetch(apis.buildingOwnerInfo.getBuildingList)
|
|
8
|
+const fetchUnitList = fetch(apis.buildingOwnerInfo.getUnitList)
|
|
9
|
+const fetchLevelList = fetch(apis.buildingOwnerInfo.getLevelList)
|
|
10
|
+const fetchRoomNoList = fetch(apis.buildingOwnerInfo.getRoomNoList)
|
|
11
|
+const addPerson = fetch(apis.buildingOwnerInfo.addBuilding)
|
|
12
|
+const taUserHasOwner = fetch(apis.propUser.taUserHasOwner)
|
|
13
|
+const taUserHas = fetch(apis.propUser.taUserHas)
|
|
14
|
+
|
|
15
|
+const formItemLayout = {
|
|
16
|
+ labelCol: {
|
|
17
|
+ xs: { span: 24 },
|
|
18
|
+ sm: { span: 6 },
|
|
19
|
+ },
|
|
20
|
+ wrapperCol: {
|
|
21
|
+ xs: { span: 24 },
|
|
22
|
+ sm: { span: 12 },
|
|
23
|
+ },
|
|
24
|
+}
|
|
25
|
+
|
|
26
|
+const tailFormItemLayout = {
|
|
27
|
+ wrapperCol: {
|
|
28
|
+ xs: {
|
|
29
|
+ span: 24,
|
|
30
|
+ offset: 0,
|
|
31
|
+ },
|
|
32
|
+ sm: {
|
|
33
|
+ span: 16,
|
|
34
|
+ offset: 6,
|
|
35
|
+ },
|
|
36
|
+ },
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+export default Form.create()(props => {
|
|
40
|
+ const [phaseList, setPhaseList] = useState([])
|
|
41
|
+ const [buildingList, setBuildingList] = useState([])
|
|
42
|
+ const [unitList, setUnitList] = useState([])
|
|
43
|
+ const [levelList, setLevelList] = useState([])
|
|
44
|
+ const [roomNoList, setRoomNoList] = useState([])
|
|
45
|
+
|
|
46
|
+ const [phaseId, setPhaseId] = useState()
|
|
47
|
+ const [buildingId, setBuildingId] = useState()
|
|
48
|
+ const [unitId, setUnitId] = useState()
|
|
49
|
+ const [levelId, setLevelId] = useState()
|
|
50
|
+ const [roomNoId, setRoomNoId] = useState()
|
|
51
|
+
|
|
52
|
+ const [owerExist, setOwnerExist] = useState(false)
|
|
53
|
+ const [telAccUser, setTelAccUser] = useState()
|
|
54
|
+
|
|
55
|
+ const handlePhaseChange = e => setPhaseId(e)
|
|
56
|
+ const handleBuildingChange = e => setBuildingId(e)
|
|
57
|
+ const handleUnitChange = e => setUnitId(e)
|
|
58
|
+ const handleLevelChange = e => setLevelId(e)
|
|
59
|
+ const handleRoomChange = e => setRoomNoId(e)
|
|
60
|
+ const handlePhoneBlur = e => {
|
|
61
|
+ const ownerTel = props.form.getFieldValue('ownerTel')
|
|
62
|
+ if (ownerTel) {
|
|
63
|
+ taUserHas({params: {ownerTel}}).then(res => {
|
|
64
|
+ setTelAccUser(res)
|
|
65
|
+ })
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ // 获取期
|
|
70
|
+ useEffect(() => {
|
|
71
|
+ fetchPhaseList().then(res => setPhaseList(res))
|
|
72
|
+ }, [])
|
|
73
|
+
|
|
74
|
+ // 楼栋
|
|
75
|
+ useEffect(() => {
|
|
76
|
+ if (phaseId) {
|
|
77
|
+ fetchBuildingList({params: {phaseId}}).then(res => setBuildingList(res))
|
|
78
|
+ }
|
|
79
|
+ setBuildingId()
|
|
80
|
+ }, [phaseId])
|
|
81
|
+
|
|
82
|
+ // 单元
|
|
83
|
+ useEffect(() => {
|
|
84
|
+ if (phaseId && buildingId) {
|
|
85
|
+ fetchUnitList({params: {phaseId, buildingId}}).then(res => setUnitList(res))
|
|
86
|
+ }
|
|
87
|
+ setUnitId()
|
|
88
|
+ }, [phaseId, buildingId])
|
|
89
|
+
|
|
90
|
+ // 楼层
|
|
91
|
+ useEffect(() => {
|
|
92
|
+ if (phaseId && buildingId && unitId) {
|
|
93
|
+ fetchLevelList({params: {phaseId, buildingId, unitId}}).then(res => setLevelList(res))
|
|
94
|
+ }
|
|
95
|
+ setLevelId()
|
|
96
|
+ }, [phaseId, buildingId, unitId])
|
|
97
|
+
|
|
98
|
+ // 房号
|
|
99
|
+ useEffect(() => {
|
|
100
|
+ if (phaseId && buildingId && unitId && levelId) {
|
|
101
|
+ fetchRoomNoList({params: {phaseId, buildingId, unitId, levelId}}).then(res => setRoomNoList(res))
|
|
102
|
+ }
|
|
103
|
+ setRoomNoId()
|
|
104
|
+ }, [phaseId, buildingId, unitId, levelId])
|
|
105
|
+
|
|
106
|
+ useEffect(() => {
|
|
107
|
+ if (roomNoId) {
|
|
108
|
+ taUserHasOwner({ params: {phaseId, buildingId, unitId, levelId, roomNoId} }).then(res => {
|
|
109
|
+ setOwnerExist(res.boolRole)
|
|
110
|
+ })
|
|
111
|
+ }
|
|
112
|
+ }, [roomNoId])
|
|
113
|
+
|
|
114
|
+ useEffect(() => {
|
|
115
|
+ if (roomNoId) {
|
|
116
|
+ taUserHasOwner({ params: {phaseId, buildingId, unitId, levelId, roomNoId} }).then(res => {
|
|
117
|
+ setOwnerExist(res.boolRole)
|
|
118
|
+ })
|
|
119
|
+ }
|
|
120
|
+ }, [roomNoId])
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+ const handleSubmit = e => {
|
|
124
|
+ e.preventDefault();
|
|
125
|
+ if (telAccUser) {
|
|
126
|
+ return
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ props.form.validateFields((err, values) => {
|
|
130
|
+ if (!err) {
|
|
131
|
+ const data = {
|
|
132
|
+ ...values,
|
|
133
|
+ phaseId,
|
|
134
|
+ buildingId,
|
|
135
|
+ unitId,
|
|
136
|
+ levelId,
|
|
137
|
+ roomNoId
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ addPerson({ data }).then(res => {
|
|
141
|
+ Modal.success({
|
|
142
|
+ content: '添加成功',
|
|
143
|
+ onOk: () => {
|
|
144
|
+ router.go(-1)
|
|
145
|
+ }
|
|
146
|
+ })
|
|
147
|
+ })
|
|
148
|
+ }
|
|
149
|
+ });
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ return (
|
|
153
|
+ <div>
|
|
154
|
+ <Form {...formItemLayout} onSubmit={handleSubmit}>
|
|
155
|
+ <Form.Item label="期/区" required>
|
|
156
|
+ <Select value={phaseId} onChange={handlePhaseChange} style={{ minWidth: '120px' }} placeholder="期/区">
|
|
157
|
+ {
|
|
158
|
+ phaseList.map(x => (<Select.Option key={x.id} value={x.id}>{x.name}</Select.Option>))
|
|
159
|
+ }
|
|
160
|
+ </Select>
|
|
161
|
+ </Form.Item>
|
|
162
|
+ <Form.Item label="栋/幢" required>
|
|
163
|
+ <Select value={buildingId} onChange={handleBuildingChange} style={{ minWidth: '120px' }} placeholder="栋/幢">
|
|
164
|
+ {
|
|
165
|
+ buildingList.map(x => (<Select.Option key={x.id} value={x.id}>{x.name}</Select.Option>))
|
|
166
|
+ }
|
|
167
|
+ </Select>
|
|
168
|
+ </Form.Item>
|
|
169
|
+ <Form.Item label="单元" required>
|
|
170
|
+ <Select value={unitId} onChange={handleUnitChange} style={{ minWidth: '120px' }} placeholder="单元">
|
|
171
|
+ {
|
|
172
|
+ unitList.map(x => (<Select.Option key={x.id} value={x.id}>{x.name}</Select.Option>))
|
|
173
|
+ }
|
|
174
|
+ </Select>
|
|
175
|
+ </Form.Item>
|
|
176
|
+ <Form.Item label="楼层" required>
|
|
177
|
+ <Select value={levelId} onChange={handleLevelChange} style={{ minWidth: '120px' }} placeholder="楼层">
|
|
178
|
+ {
|
|
179
|
+ levelList.map(x => (<Select.Option key={x.id} value={x.id}>{x.name}</Select.Option>))
|
|
180
|
+ }
|
|
181
|
+ </Select>
|
|
182
|
+ </Form.Item>
|
|
183
|
+ <Form.Item label="户号" required>
|
|
184
|
+ <Select value={roomNoId} onChange={handleRoomChange} style={{ minWidth: '120px' }} placeholder="户号">
|
|
185
|
+ {
|
|
186
|
+ roomNoList.map(x => (<Select.Option key={x.id} value={x.id}>{x.name}</Select.Option>))
|
|
187
|
+ }
|
|
188
|
+ </Select>
|
|
189
|
+ </Form.Item>
|
|
190
|
+ <Form.Item label="手机号">
|
|
191
|
+ {
|
|
192
|
+ props.form.getFieldDecorator('ownerTel', {
|
|
193
|
+ rules: [
|
|
194
|
+ { required: true, message: '请填写手机号' }
|
|
195
|
+ ]
|
|
196
|
+ })(<Input onBlur={handlePhoneBlur} />)
|
|
197
|
+ }
|
|
198
|
+ </Form.Item>
|
|
199
|
+ <Form.Item label="身份">
|
|
200
|
+ {
|
|
201
|
+ props.form.getFieldDecorator('roleId')(
|
|
202
|
+ <Select style={{ minWidth: '120px' }} placeholder="请选择身份">
|
|
203
|
+ <Select.Option value="1" disabled={owerExist}>户主</Select.Option>
|
|
204
|
+ <Select.Option value="2">租客</Select.Option>
|
|
205
|
+ <Select.Option value="3">家属</Select.Option>
|
|
206
|
+ </Select>
|
|
207
|
+ )
|
|
208
|
+ }
|
|
209
|
+ </Form.Item>
|
|
210
|
+ <Form.Item label="姓名">
|
|
211
|
+ {
|
|
212
|
+ props.form.getFieldDecorator('ownerName')(<Input />)
|
|
213
|
+ }
|
|
214
|
+ </Form.Item>
|
|
215
|
+ <Form.Item label="性别">
|
|
216
|
+ {
|
|
217
|
+ props.form.getFieldDecorator('gender')(
|
|
218
|
+ <Radio.Group>
|
|
219
|
+ <Radio value="1">男</Radio>
|
|
220
|
+ <Radio value="2">女</Radio>
|
|
221
|
+ </Radio.Group>
|
|
222
|
+ )
|
|
223
|
+ }
|
|
224
|
+ </Form.Item>
|
|
225
|
+ {
|
|
226
|
+ telAccUser && (
|
|
227
|
+ <Form.Item label=" " colon={false}>
|
|
228
|
+ <Descriptions column={3}>
|
|
229
|
+ <Descriptions.Item label="姓名">{telAccUser.userName}</Descriptions.Item>
|
|
230
|
+ <Descriptions.Item label="性别">{telAccUser.gender === '2' ? '女' : '男'}</Descriptions.Item>
|
|
231
|
+ <Descriptions.Item label="身份证号">{(telAccUser.idCard || '').replace(/^(.{4})(?:\w+)(.{4})$/, "$1****$2")}</Descriptions.Item>
|
|
232
|
+ </Descriptions>
|
|
233
|
+ </Form.Item>
|
|
234
|
+ )
|
|
235
|
+ }
|
|
236
|
+ <Form.Item {...tailFormItemLayout}>
|
|
237
|
+ <Button type="primary" htmlType="submit">提交</Button>
|
|
238
|
+ <Button style={{ marginLeft: '48px' }} onClick={() => router.go(-1)}>取消</Button>
|
|
239
|
+ </Form.Item>
|
|
240
|
+ </Form>
|
|
241
|
+ </div>
|
|
242
|
+ )
|
|
243
|
+})
|