|
@@ -1,15 +1,37 @@
|
1
|
1
|
import React, { useState, useEffect } from 'react';
|
2
|
2
|
import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, Table, notification, Modal, Layout } from 'antd';
|
3
|
3
|
import ImageListUpload from '../../../../../components/XForm/ImageListUpload';
|
|
4
|
+import moment from 'moment';
|
|
5
|
+import request from '../../../../../utils/request';
|
|
6
|
+import apis from '../../../../../services/apis';
|
4
|
7
|
|
5
|
8
|
const { Header, Footer, Sider, Content } = Layout;
|
6
|
9
|
|
|
10
|
+const modalEdiFormItemLayout = {
|
|
11
|
+ labelCol: {
|
|
12
|
+ xs: { span: 24 },
|
|
13
|
+ sm: { span: 8 },
|
|
14
|
+ },
|
|
15
|
+ wrapperCol: {
|
|
16
|
+ xs: { span: 24 },
|
|
17
|
+ sm: { span: 16 },
|
|
18
|
+ },
|
|
19
|
+};
|
|
20
|
+
|
|
21
|
+const openNotificationWithIcon = (type, message) => {
|
|
22
|
+ notification[type]({
|
|
23
|
+ message,
|
|
24
|
+ description:
|
|
25
|
+ '',
|
|
26
|
+ });
|
|
27
|
+};
|
|
28
|
+
|
7
|
29
|
/**
|
8
|
30
|
* 弹框
|
9
|
31
|
*/
|
10
|
32
|
function ModalEdi(props) {
|
11
|
|
-
|
12
|
|
- const [visibleData, setVisibleData] = useState({ visible: false })
|
|
33
|
+ const { apartment, buildingId, apartmentId } = props.visibleData
|
|
34
|
+ const [visibleData, setVisibleData] = useState({ visible: false, buildingId: '', apartmentId: '', apartment: '' })
|
13
|
35
|
|
14
|
36
|
if (!props.visibleData) {
|
15
|
37
|
console.error('缺少visibleData参数!')
|
|
@@ -17,6 +39,7 @@ function ModalEdi(props) {
|
17
|
39
|
|
18
|
40
|
useEffect(() => {
|
19
|
41
|
setVisibleData(props.visibleData)
|
|
42
|
+ props.form.setFieldsValue({ apartmentId, apartmentName: apartment !== '' ? apartment.apartmentName : '' })
|
20
|
43
|
}, [props.visibleData.visible])
|
21
|
44
|
|
22
|
45
|
function handleOk(e) {
|
|
@@ -29,54 +52,171 @@ function ModalEdi(props) {
|
29
|
52
|
props.onCancel();
|
30
|
53
|
}
|
31
|
54
|
|
|
55
|
+ function handleSubmit(e) {
|
|
56
|
+ e.preventDefault();
|
|
57
|
+ props.form.validateFieldsAndScroll((err, values) => {
|
|
58
|
+ if (!err) {
|
|
59
|
+ console.log('Received values of form: ', values);
|
|
60
|
+ submitData(values)
|
|
61
|
+ }
|
|
62
|
+ });
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ function submitData(data) {
|
|
66
|
+ if (buildingId === '' || buildingId === undefined) {
|
|
67
|
+ return
|
|
68
|
+ }
|
|
69
|
+ if (data.img) {
|
|
70
|
+ // 如果是 名称 和 图片一起编辑,就穿最新的图片
|
|
71
|
+ data.img = data.img.map((item, index) => ({ imgType: 'aparment', url: item, orderNo: index }))
|
|
72
|
+ } else {
|
|
73
|
+ // 如果是 名称 和 图片一起编辑,就穿最新的图片
|
|
74
|
+ data.img = visibleData.apartment.buildingImgList
|
|
75
|
+ }
|
|
76
|
+ data.buildingId = buildingId;
|
|
77
|
+ data.apartmentType = 'photo'
|
|
78
|
+ const api = (data.apartmentId !== undefined && data.apartmentId !== '') ? apis.building.buildingApartmentUpdate : apis.building.buildingApartmentAdd;
|
|
79
|
+
|
|
80
|
+ // 网路请求
|
|
81
|
+ request({ ...api, data: { ...data } }).then(() => {
|
|
82
|
+ // eslint-disable-next-line no-unused-expressions
|
|
83
|
+ openNotificationWithIcon('success', '操作成功')
|
|
84
|
+ handleCancel()
|
|
85
|
+ props.onSuccess()
|
|
86
|
+ // this.setState({ visibleData: { visible: false, apartmentId: '', buildingId: '' } }, () => console.log('回调:', this.state.visibleData))
|
|
87
|
+ }).catch(err => {
|
|
88
|
+ // eslint-disable-next-line no-unused-expressions
|
|
89
|
+ openNotificationWithIcon('error', err)
|
|
90
|
+ })
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ const { getFieldDecorator } = props.form;
|
32
|
94
|
return (
|
33
|
95
|
<>
|
34
|
96
|
<Modal
|
35
|
|
- title="Basic Modal"
|
|
97
|
+ title="编辑"
|
36
|
98
|
visible={visibleData.visible}
|
37
|
99
|
onOk={handleOk}
|
38
|
100
|
onCancel={handleCancel}
|
|
101
|
+ width={700}
|
|
102
|
+ footer={null}
|
39
|
103
|
>
|
40
|
|
- <p>Some contents...</p>
|
41
|
|
- <p>Some contents...</p>
|
42
|
|
- <p>Some contents...</p>
|
|
104
|
+ <Form {...modalEdiFormItemLayout} onSubmit={handleSubmit}>
|
|
105
|
+ <Form.Item label="编号" style={{ display: 'none' }}>
|
|
106
|
+ {getFieldDecorator('apartmentId')(<Input />)}
|
|
107
|
+ </Form.Item>
|
|
108
|
+ <Form.Item label="相册名称">
|
|
109
|
+ {getFieldDecorator('apartmentName', {
|
|
110
|
+ rules: [
|
|
111
|
+ {
|
|
112
|
+ required: true,
|
|
113
|
+ message: '请输入相册名称',
|
|
114
|
+ },
|
|
115
|
+ {
|
|
116
|
+ max: 10,
|
|
117
|
+ message: '不超过10个字符',
|
|
118
|
+ },
|
|
119
|
+ ],
|
|
120
|
+ })(<Input />)}
|
|
121
|
+ </Form.Item>
|
|
122
|
+ {
|
|
123
|
+ !props.noImage && <Form.Item label="选择图片">
|
|
124
|
+ {getFieldDecorator('img', {
|
|
125
|
+ rules: [
|
|
126
|
+ {
|
|
127
|
+ required: true,
|
|
128
|
+ message: '请选择图片',
|
|
129
|
+ },
|
|
130
|
+ ],
|
|
131
|
+ })(<ImageListUpload />)}
|
|
132
|
+ </Form.Item>
|
|
133
|
+ }
|
|
134
|
+ <Form.Item style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
135
|
+ <Button type="primary" htmlType="submit">
|
|
136
|
+ 保存
|
|
137
|
+ </Button>
|
|
138
|
+
|
|
139
|
+ <Button onClick={() => handleCancel()}>
|
|
140
|
+ 取消
|
|
141
|
+ </Button>
|
|
142
|
+ </Form.Item>
|
|
143
|
+ </Form>
|
43
|
144
|
</Modal>
|
44
|
145
|
</>
|
45
|
146
|
)
|
46
|
147
|
}
|
47
|
148
|
|
|
149
|
+const WrappedModalEdiForm = Form.create({ name: 'ModalEdi' })(ModalEdi);
|
|
150
|
+
|
48
|
151
|
/**
|
49
|
152
|
* 模块
|
50
|
153
|
*/
|
51
|
154
|
function BuildingImageModel(props) {
|
52
|
155
|
const [imageList, setImageList] = useState([])
|
53
|
|
- const [visibleData, setVisibleData] = useState({ visible: false })
|
|
156
|
+ const [visibleData, setVisibleData] = useState({ visible: false, buildingId: '', apartmentId: '', apartment: '' })
|
|
157
|
+
|
|
158
|
+ useEffect(() => {
|
|
159
|
+ setImageList(getImgUrl())
|
|
160
|
+ }, [props.apartment.apartmentId])
|
|
161
|
+
|
|
162
|
+ function getImgUrl() {
|
|
163
|
+ return ((props.apartment.buildingImgList || [])).map(item => item.url)
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ function submitData(data) {
|
|
167
|
+ const { apartmentId } = props.apartment
|
|
168
|
+ if (apartmentId === '' || apartmentId === undefined) {
|
|
169
|
+ return
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ data.buildingId = props.apartment.buildingId;
|
|
173
|
+ data.apartmentType = 'photo'
|
|
174
|
+ const api = data.apartmentId !== undefined ? apis.building.buildingApartmentUpdate : apis.building.buildingApartmentAdd;
|
|
175
|
+
|
|
176
|
+ // 网路请求
|
|
177
|
+ request({ ...api, data: { ...data } }).then(() => {
|
|
178
|
+ // eslint-disable-next-line no-unused-expressions
|
|
179
|
+ openNotificationWithIcon('success', '操作成功')
|
|
180
|
+ }).catch(err => {
|
|
181
|
+ // eslint-disable-next-line no-unused-expressions
|
|
182
|
+ // openNotificationWithIcon('error', err)
|
|
183
|
+ })
|
|
184
|
+ }
|
54
|
185
|
|
55
|
186
|
function onImageChange(e) {
|
56
|
187
|
setImageList(e)
|
|
188
|
+
|
|
189
|
+ // 新增加图片后,更新后端数据
|
|
190
|
+ const img = e.map((item, index) => ({ imgType: 'aparment', url: item, orderNo: index }))
|
|
191
|
+ submitData({ ...props.apartment, img })
|
57
|
192
|
}
|
58
|
193
|
|
59
|
194
|
function edi() {
|
60
|
|
- setVisibleData({ visible: true })
|
|
195
|
+ setVisibleData({ visible: true, buildingId: props.apartment.buildingId, apartmentId: props.apartment.apartmentId, apartment: props.apartment })
|
61
|
196
|
}
|
62
|
197
|
|
63
|
198
|
function onCancel(e) {
|
64
|
|
- setVisibleData({ visible: false })
|
|
199
|
+ setVisibleData({ visible: false, buildingId: '', apartmentId: '', apartment: '' })
|
65
|
200
|
}
|
66
|
201
|
|
67
|
202
|
function deletePhoto() {
|
|
203
|
+ request({ ...apis.building.buildingApartmentDelete, urlData: { id: props.apartment.apartmentId } }).then(() => {
|
|
204
|
+ openNotificationWithIcon('success', '操作成功')
|
|
205
|
+ props.onSuccess()
|
|
206
|
+ }).catch(err => {
|
68
|
207
|
|
|
208
|
+ })
|
69
|
209
|
}
|
70
|
210
|
|
71
|
211
|
return (
|
72
|
212
|
<>
|
73
|
|
-<span style={{ marginTop: '10px', marginBottom: '10px' }}>效果图({imageList.length})</span>
|
|
213
|
+ <span style={{ marginTop: '10px', marginBottom: '10px' }}>{props.apartment.apartmentName}({imageList.length})</span>
|
74
|
214
|
<Button type="link" style={{ color: 'blue' }} onClick={() => edi()}>重命名</Button>
|
75
|
215
|
<Button type="link" style={{ color: 'blue' }} onClick={() => deletePhoto()}>删除相册</Button>
|
76
|
216
|
<ImageListUpload value={imageList} onChange={onImageChange} unlimited/>
|
77
|
217
|
|
78
|
218
|
{/* 编辑页 */}
|
79
|
|
- <ModalEdi visibleData={visibleData} onCancel={e => onCancel(e)}/>
|
|
219
|
+ <WrappedModalEdiForm visibleData={visibleData} onCancel={e => onCancel(e)} onSuccess={() => props.onSuccess()} noImage/>
|
80
|
220
|
<hr />
|
81
|
221
|
</>
|
82
|
222
|
)
|
|
@@ -85,28 +225,49 @@ function BuildingImageModel(props) {
|
85
|
225
|
/**
|
86
|
226
|
* 主体
|
87
|
227
|
*/
|
88
|
|
-function buildingImage() {
|
89
|
|
- const [visibleData, setVisibleData] = useState({ visible: false })
|
|
228
|
+function buildingImage(props) {
|
|
229
|
+ // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
230
|
+ const [visibleData, setVisibleData] = useState({ visible: false, buildingId: '', apartmentId: '', apartment: '' })
|
|
231
|
+ const [imageList, setImageList] = useState([])
|
|
232
|
+
|
|
233
|
+ // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
234
|
+ useEffect(() => {
|
|
235
|
+ getList()
|
|
236
|
+ }, [props.building.buildingId])
|
|
237
|
+
|
90
|
238
|
|
91
|
239
|
function edi() {
|
92
|
|
- setVisibleData({ visible: true })
|
|
240
|
+ setVisibleData({ visible: true, buildingId: props.building.buildingId, apartmentId: '', apartment: '' })
|
93
|
241
|
}
|
94
|
242
|
|
95
|
243
|
function onCancel(e) {
|
96
|
|
- setVisibleData({ visible: false })
|
|
244
|
+ setVisibleData({ visible: false, buildingId: '', apartmentId: '', apartment: '' })
|
|
245
|
+ }
|
|
246
|
+
|
|
247
|
+ function onSuccess(e) {
|
|
248
|
+ getList()
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ function getList(params) {
|
|
252
|
+ // 网路请求
|
|
253
|
+ request({ ...apis.building.buildingApartment, urlData: { id: props.building.buildingId }, params: { ...params, apartmentType: 'photo' } }).then(res => {
|
|
254
|
+ setImageList(res)
|
|
255
|
+ }).catch(err => {
|
|
256
|
+ openNotificationWithIcon('error', err.message)
|
|
257
|
+ })
|
97
|
258
|
}
|
98
|
259
|
|
99
|
260
|
return (
|
100
|
261
|
<>
|
101
|
262
|
<Button type="primary" onClick={() => edi()}>新增</Button>
|
102
|
263
|
<Layout style={{ background: '#fff' }}>
|
103
|
|
- <Content><BuildingImageModel /></Content>
|
104
|
|
- <Content><BuildingImageModel /></Content>
|
105
|
|
- <Content><BuildingImageModel /></Content>
|
|
264
|
+ {
|
|
265
|
+ imageList.map(item => <Content><BuildingImageModel apartment={item} key={item.apartmentId} onSuccess={e => onSuccess(e)}/></Content>)
|
|
266
|
+ }
|
106
|
267
|
</Layout>
|
107
|
268
|
|
108
|
269
|
{/* 编辑页 */}
|
109
|
|
- <ModalEdi visibleData={visibleData} onCancel={e => onCancel(e)}/>
|
|
270
|
+ <WrappedModalEdiForm visibleData={visibleData} onCancel={e => onCancel(e)} onSuccess={e => onSuccess(e)}/>
|
110
|
271
|
</>
|
111
|
272
|
)
|
112
|
273
|
}
|