|
@@ -0,0 +1,262 @@
|
|
1
|
+import React, { useEffect, useState } from 'react'
|
|
2
|
+import { Button, Radio, Icon, Form, Input, Row, Col, Modal, notification, Checkbox } from 'antd';
|
|
3
|
+import { render } from 'react-dom';
|
|
4
|
+import request from '../../../../../utils/request';
|
|
5
|
+import apis from '../../../../../services/apis';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+const formItemLayout = {
|
|
9
|
+ labelCol: {
|
|
10
|
+ xs: { span: 24 },
|
|
11
|
+ sm: { span: 3 },
|
|
12
|
+ },
|
|
13
|
+ wrapperCol: {
|
|
14
|
+ xs: { span: 24 },
|
|
15
|
+ sm: { span: 16 },
|
|
16
|
+ },
|
|
17
|
+};
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ * 项目类型 form 表单子组件
|
|
21
|
+ *
|
|
22
|
+ * @param {*} props
|
|
23
|
+ */
|
|
24
|
+class TypeForm extends React.Component {
|
|
25
|
+
|
|
26
|
+ componentDidMount() {
|
|
27
|
+ this.props.form.setFieldsValue(this.props.type)
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ onChange(e, name) {
|
|
31
|
+ // console.log(e.target.value)
|
|
32
|
+ this.props.form.validateFieldsAndScroll((err, values) => {
|
|
33
|
+ if (!err) {
|
|
34
|
+ // console.log('Received values of form: ', values);
|
|
35
|
+ values[name] = e.target.value
|
|
36
|
+ values.buildingTypeName = this.props.type.buildingTypeName
|
|
37
|
+ console.log('values: ', values)
|
|
38
|
+ this.props.onSuccess(values)
|
|
39
|
+ }
|
|
40
|
+ });
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ close() {
|
|
44
|
+ this.props.onClose(this.props.form.getFieldsValue(['buildingTypeId']))
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ render() {
|
|
48
|
+ const { getFieldDecorator } = this.props.form;
|
|
49
|
+
|
|
50
|
+ // this.props.form.setFieldsValue(this.props.type)
|
|
51
|
+
|
|
52
|
+ return (
|
|
53
|
+ <>
|
|
54
|
+ <div>
|
|
55
|
+ <Row>
|
|
56
|
+ <Col span={8}>{ this.props.type.buildingTypeName || ''}</Col>
|
|
57
|
+ <Col span={1}>
|
|
58
|
+ <Button type="link" icon="close" onClick={() => this.close()} />
|
|
59
|
+ </Col>
|
|
60
|
+ </Row>
|
|
61
|
+ <Row>
|
|
62
|
+ <Col span={12}>
|
|
63
|
+ <Form {...formItemLayout}>
|
|
64
|
+ <Form.Item label="类型编号" style={{ display: 'none' }}>
|
|
65
|
+ {getFieldDecorator('buildingTypeId')(<Input disabled />)}
|
|
66
|
+ </Form.Item>
|
|
67
|
+ <Form.Item label="状态" style={{ display: 'none' }}>
|
|
68
|
+ {getFieldDecorator('status')(<Input disabled />)}
|
|
69
|
+ </Form.Item>
|
|
70
|
+ <Form.Item label="价格">
|
|
71
|
+ {getFieldDecorator('price')(<Input type="number" placeholder="元/㎡" onChange={e => this.onChange(e, 'price')}/>)}
|
|
72
|
+ </Form.Item>
|
|
73
|
+ <Form.Item label="装修标准">
|
|
74
|
+ {getFieldDecorator('decoration')(<Input onChange={e => this.onChange(e, 'decoration')}/>)}
|
|
75
|
+ </Form.Item>
|
|
76
|
+ <Form.Item label="产权年限">
|
|
77
|
+ {getFieldDecorator('rightsYear')(<Input onChange={e => this.onChange(e, 'rightsYear')}/>)}
|
|
78
|
+ </Form.Item>
|
|
79
|
+ </Form>
|
|
80
|
+ </Col>
|
|
81
|
+ </Row>
|
|
82
|
+ </div>
|
|
83
|
+ </>
|
|
84
|
+ )
|
|
85
|
+ }
|
|
86
|
+}
|
|
87
|
+
|
|
88
|
+const WrappedTypeForm = Form.create({ name: 'TypeForm' })(TypeForm);
|
|
89
|
+
|
|
90
|
+/**
|
|
91
|
+ *项目类型组件
|
|
92
|
+ *
|
|
93
|
+ * @param {*} props
|
|
94
|
+ */
|
|
95
|
+class ProjectTypeBody extends React.Component {
|
|
96
|
+
|
|
97
|
+ constructor(props) {
|
|
98
|
+ super(props)
|
|
99
|
+ this.state = {
|
|
100
|
+ one: false,
|
|
101
|
+ projectType: [],
|
|
102
|
+ defaultCheckboxValue: [], // 多选框默认选中的值
|
|
103
|
+ visible: false,
|
|
104
|
+ data: [],
|
|
105
|
+ // data: [{ buildingTypeId: '1', buildingTypeName: '公寓', price: '10', decoration: '全包', rightsYear: '10', status: '1' }, { buildingTypeId: '2', buildingTypeName: '住宅', price: '10', decoration: '全包', rightsYear: '10', status: '1' }, { buildingTypeId: '3', buildingTypeName: '太平房', price: '10', decoration: '全包', rightsYear: '10', status: '1' }],
|
|
106
|
+ }
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ componentDidMount() {
|
|
110
|
+ this.getList({ pageNum: 1, pageSize: 999 })
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ componentDidUpdate(prevProps) {
|
|
114
|
+ // 典型用法(不要忘记比较 props):
|
|
115
|
+ if (this.props.value !== prevProps.data && !this.state.one) {
|
|
116
|
+ this.setValue()
|
|
117
|
+ this.setState({ one: true })
|
|
118
|
+ }
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ onSuccess = (values, item) => {
|
|
122
|
+ console.log('values: ', values)
|
|
123
|
+ console.log('data: ', this.state.data, 'item: ', item)
|
|
124
|
+ const newData = this.getNewProjectType(values)
|
|
125
|
+ console.log('newData: ', newData)
|
|
126
|
+ this.setState({ data: newData })
|
|
127
|
+ if (typeof this.props.onChange === 'function') {
|
|
128
|
+ this.props.onChange(newData)
|
|
129
|
+ }
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ onCheckboxChange = checkedValues => {
|
|
133
|
+ const checked = (`${checkedValues}` || '').split(',')
|
|
134
|
+ const { projectType } = this.state
|
|
135
|
+ const buildingType = projectType.filter(item => checked.includes(`${item.buildingTypeId}`))
|
|
136
|
+
|
|
137
|
+ // 这里会把值替换掉
|
|
138
|
+
|
|
139
|
+ const tempDate = buildingType.map(item => ({ buildingTypeId: item.buildingTypeId, buildingTypeName: item.buildingTypeName, price: '', decoration: '', rightsYear: '', status: '1' }))
|
|
140
|
+ const updateProjectDate = this.updateProjectType(checkedValues)
|
|
141
|
+ console.log('updateProjectDate: ', updateProjectDate)
|
|
142
|
+ this.setState({ data: updateProjectDate })
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ onClose = e => {
|
|
146
|
+ const { data } = this.state
|
|
147
|
+ const buildingType = data.filter(item => e.buildingTypeId !== item.buildingTypeId)
|
|
148
|
+ console.log('buildingType: ', buildingType)
|
|
149
|
+ this.setState({ data: buildingType })
|
|
150
|
+ this.setState({ defaultCheckboxValue: buildingType.map(item => item.buildingTypeId) })
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ getNewProjectType = values => {
|
|
154
|
+ const data = []
|
|
155
|
+ this.state.data.map(item => {
|
|
156
|
+ console.log('item: ', item)
|
|
157
|
+ if (item.buildingTypeId === values.buildingTypeId) {
|
|
158
|
+ data.push(values)
|
|
159
|
+ } else {
|
|
160
|
+ data.push(item)
|
|
161
|
+ }
|
|
162
|
+ })
|
|
163
|
+
|
|
164
|
+ return data
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ updateProjectType = values => {
|
|
168
|
+ const data = []
|
|
169
|
+ this.state.data.map(item => {
|
|
170
|
+ values.map(va => {
|
|
171
|
+ if (item.buildingTypeId === va.buildingTypeId) {
|
|
172
|
+ data.push(va)
|
|
173
|
+ } else {
|
|
174
|
+ data.push(item)
|
|
175
|
+ }
|
|
176
|
+ })
|
|
177
|
+ })
|
|
178
|
+
|
|
179
|
+ return data
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ getList = params => {
|
|
183
|
+ request({ ...apis.buildingType.getList, params: { ...params } }).then(res => {
|
|
184
|
+ this.setState({ projectType: res.records })
|
|
185
|
+ }).catch(err => {
|
|
186
|
+ this.openNotificationWithIcon('error', err.message)
|
|
187
|
+ })
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ setValue = () => {
|
|
191
|
+ let tempData = []
|
|
192
|
+ let tempCheckboxValue = []
|
|
193
|
+ const { value } = this.props
|
|
194
|
+ // console.log('value: ', value)
|
|
195
|
+ if (value !== undefined && value !== null) {
|
|
196
|
+ tempData = value
|
|
197
|
+ tempCheckboxValue = tempData.map(item => item.buildingTypeId)
|
|
198
|
+ this.setState({ defaultCheckboxValue: tempCheckboxValue })
|
|
199
|
+ this.setState({ data: tempData }, () => {
|
|
200
|
+ console.log("state: ", this.state.data)
|
|
201
|
+ })
|
|
202
|
+
|
|
203
|
+ console.log("tempData: ", tempData, "tempCheckboxValue: ", tempCheckboxValue, "value: ", value)
|
|
204
|
+ }
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ openNotificationWithIcon = (type, message) => {
|
|
208
|
+ notification[type]({
|
|
209
|
+ message,
|
|
210
|
+ description: '',
|
|
211
|
+ })
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ handleOk = e => {
|
|
215
|
+ this.setState({
|
|
216
|
+ visible: false,
|
|
217
|
+ });
|
|
218
|
+ };
|
|
219
|
+
|
|
220
|
+ handleCancel = e => {
|
|
221
|
+ this.setState({
|
|
222
|
+ visible: false,
|
|
223
|
+ });
|
|
224
|
+ };
|
|
225
|
+
|
|
226
|
+ showMadel = () => {
|
|
227
|
+ this.setState({ visible: true })
|
|
228
|
+ this.getList({ pageNum: 1, pageSize: 999 })
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ render () {
|
|
232
|
+
|
|
233
|
+ // let tempData = []
|
|
234
|
+ // let tempCheckboxValue = []
|
|
235
|
+ // const { value } = this.props
|
|
236
|
+ // if (value !== undefined && value !== null) {
|
|
237
|
+ // tempData = value
|
|
238
|
+ // } else {
|
|
239
|
+ // tempData = this.state.data
|
|
240
|
+ // }
|
|
241
|
+
|
|
242
|
+ // tempCheckboxValue = tempData.map(item => item.buildingTypeId)
|
|
243
|
+ return (
|
|
244
|
+ <>
|
|
245
|
+ <Button type="primary" icon="plus" size="large" onClick={() => this.showMadel()} />
|
|
246
|
+ <Modal
|
|
247
|
+ title="项目类型"
|
|
248
|
+ visible={this.state.visible}
|
|
249
|
+ onOk={this.handleOk}
|
|
250
|
+ onCancel={this.handleCancel}
|
|
251
|
+ >
|
|
252
|
+ <Checkbox.Group options={this.state.projectType.map(item => ({ label: item.buildingTypeName, value: item.buildingTypeId }))} defaultValue={this.state.defaultCheckboxValue} onChange={e => this.onCheckboxChange(e)} />
|
|
253
|
+ </Modal>
|
|
254
|
+ {
|
|
255
|
+ this.state.data.map(item => <WrappedTypeForm type={item} key={item.id} onSuccess={(e) => this.onSuccess(e, item)} onClose={(e) => this.onClose(e)} />)
|
|
256
|
+ }
|
|
257
|
+ </>
|
|
258
|
+ )
|
|
259
|
+ }
|
|
260
|
+}
|
|
261
|
+
|
|
262
|
+export default ProjectTypeBody
|