|
@@ -1,112 +1,173 @@
|
1
|
|
-import React, { useEffect, useState } from 'react'
|
2
|
|
-import { Button, Form, Input, message, Select } from 'antd'
|
3
|
|
-import ImageUpload from '@/components/XForm/ImageUpload'
|
4
|
|
-import { fetch, apis } from '@/utils/request'
|
5
|
|
-import ModalForm from '../components/ModalForm'
|
6
|
|
-import InputNumber from '../components/InputNumber'
|
7
|
|
-import { validMinNum } from '../utils'
|
|
1
|
+import React, { useEffect, useState } from 'react';
|
|
2
|
+import { Button, Form, Input, message, Select } from 'antd';
|
|
3
|
+import ImageUpload from '@/components/XForm/ImageUpload';
|
|
4
|
+import { fetch, apis } from '@/utils/request';
|
|
5
|
+import ModalForm from '../components/ModalForm';
|
|
6
|
+import InputNumber from '../components/InputNumber';
|
|
7
|
+import { validMinNum } from '../utils';
|
8
|
8
|
|
9
|
|
-const Option = Select.Option
|
10
|
|
-const fullWidth = { width: '100%' }
|
11
|
|
-const saveData = fetch(apis.building.buildingApartmentAdd)
|
12
|
|
-const updateData = fetch(apis.building.buildingApartmentUpdate)
|
|
9
|
+const Option = Select.Option;
|
|
10
|
+const fullWidth = { width: '100%' };
|
|
11
|
+const saveData = fetch(apis.building.buildingApartmentAdd);
|
|
12
|
+const updateData = fetch(apis.building.buildingApartmentUpdate);
|
13
|
13
|
|
14
|
|
-const AMForm = (props) => {
|
15
|
|
- const { visible, onCancel, form, formData, onSuccess } = props
|
16
|
|
- const { getFieldDecorator, setFieldsValue, resetFields, validateFields } = form
|
|
14
|
+const saleType = [
|
|
15
|
+ {
|
|
16
|
+ id: '1',
|
|
17
|
+ name: '待售',
|
|
18
|
+ },
|
|
19
|
+ {
|
|
20
|
+ id: '2',
|
|
21
|
+ name: '售罄',
|
|
22
|
+ },
|
|
23
|
+ {
|
|
24
|
+ id: '3',
|
|
25
|
+ name: '在售',
|
|
26
|
+ },
|
|
27
|
+ // {
|
|
28
|
+ // id: '4',
|
|
29
|
+ // name: '在租',
|
|
30
|
+ // },
|
|
31
|
+];
|
17
|
32
|
|
18
|
|
- const [loading, setLoading] = useState(false)
|
|
33
|
+const houseType = [
|
|
34
|
+ {
|
|
35
|
+ id: '1',
|
|
36
|
+ name: '1室',
|
|
37
|
+ },
|
|
38
|
+ {
|
|
39
|
+ id: '2',
|
|
40
|
+ name: '2室',
|
|
41
|
+ },
|
|
42
|
+ {
|
|
43
|
+ id: '3',
|
|
44
|
+ name: '3室',
|
|
45
|
+ },
|
|
46
|
+ {
|
|
47
|
+ id: '4',
|
|
48
|
+ name: '4室',
|
|
49
|
+ },
|
|
50
|
+ {
|
|
51
|
+ id: '5',
|
|
52
|
+ name: '5室及以上',
|
|
53
|
+ },
|
|
54
|
+];
|
19
|
55
|
|
20
|
|
- const handleSubmit = (e) => {
|
|
56
|
+const AMForm = props => {
|
|
57
|
+ const { visible, onCancel, form, formData, onSuccess,buildingId } = props;
|
|
58
|
+ const { getFieldDecorator, setFieldsValue, resetFields, validateFields } = form;
|
|
59
|
+
|
|
60
|
+ const [loading, setLoading] = useState(false);
|
|
61
|
+
|
|
62
|
+ const handleSubmit = e => {
|
21
|
63
|
e.preventDefault();
|
22
|
64
|
validateFields((err, values) => {
|
23
|
65
|
if (err) {
|
24
|
|
- console.error(err)
|
25
|
|
- return
|
|
66
|
+ console.error(err);
|
|
67
|
+ return;
|
26
|
68
|
}
|
27
|
69
|
|
28
|
|
- const request = formData && formData.apartmentId ? updateData : saveData
|
|
70
|
+ const request = formData && formData.apartmentId ? updateData : saveData;
|
|
71
|
+
|
|
72
|
+ // console.log(values)
|
|
73
|
+ // TODO 这里应该是要支持多图,但是封装的控件没有
|
|
74
|
+ // data.img = data.img.map((item, index) => ({ imgType: 'aparment', url: item, orderNo: index }))
|
|
75
|
+ console.log(formData, values, '--------------');
|
|
76
|
+ values.img = [{ imgType: 'aparment', url: values.img, orderNo: 0 }];
|
|
77
|
+ values.buildingId = buildingId;
|
|
78
|
+ values.apartmentType = 'apart';
|
|
79
|
+ // const api = data.apartmentId !== undefined ? apis.building.buildingApartmentUpdate : apis.building.buildingApartmentAdd;
|
|
80
|
+
|
29
|
81
|
const data = {
|
30
|
82
|
...(formData || {}),
|
31
|
83
|
...values,
|
32
|
|
- }
|
|
84
|
+ };
|
33
|
85
|
|
34
|
|
- setLoading(true)
|
35
|
|
- request({ data }).then((res) => {
|
36
|
|
- setLoading(false)
|
37
|
|
- message.success('操作成功')
|
38
|
|
- onSuccess(res)
|
39
|
|
- }).catch((err) => {
|
40
|
|
- setLoading(false)
|
41
|
|
- console.error(err)
|
42
|
|
- })
|
43
|
|
- })
|
44
|
|
- }
|
|
86
|
+ setLoading(true);
|
|
87
|
+ request({ data })
|
|
88
|
+ .then(res => {
|
|
89
|
+ setLoading(false);
|
|
90
|
+ message.success('操作成功');
|
|
91
|
+ onSuccess(res);
|
|
92
|
+ })
|
|
93
|
+ .catch(err => {
|
|
94
|
+ setLoading(false);
|
|
95
|
+ console.error(err);
|
|
96
|
+ });
|
|
97
|
+ });
|
|
98
|
+ };
|
45
|
99
|
|
46
|
100
|
useEffect(() => {
|
47
|
|
- resetFields()
|
48
|
|
- setFieldsValue(formData || {})
|
49
|
|
- }, [formData])
|
|
101
|
+ resetFields();
|
|
102
|
+ if (formData?.buildingImgList) {
|
|
103
|
+ formData.img = formData.buildingImgList[0].url;
|
|
104
|
+ }
|
|
105
|
+ setFieldsValue(formData || {});
|
|
106
|
+ setFieldsValue(formData || {});
|
|
107
|
+ }, [formData]);
|
50
|
108
|
|
51
|
109
|
return (
|
52
|
|
- <ModalForm
|
53
|
|
- title="户型设置"
|
54
|
|
- visible={visible}
|
55
|
|
- onCancel={onCancel}
|
56
|
|
- onSubmit={handleSubmit}
|
57
|
|
- >
|
|
110
|
+ <ModalForm title="户型设置" visible={visible} onCancel={onCancel} onSubmit={handleSubmit}>
|
58
|
111
|
<Form.Item label="户型名称">
|
59
|
112
|
{getFieldDecorator('apartmentName', {
|
60
|
113
|
rules: [
|
61
|
114
|
{ required: true, message: '请填写户型名称' },
|
62
|
115
|
{ max: 10, message: '户型名称不超过10个字符' },
|
63
|
116
|
],
|
64
|
|
- })(<Input placeholder="户型名称不超过10个字符"/>)}
|
|
117
|
+ })(<Input placeholder="户型名称不超过10个字符" />)}
|
65
|
118
|
</Form.Item>
|
66
|
119
|
<Form.Item label="销售状态">
|
67
|
120
|
{getFieldDecorator('marketStatus', {
|
68
|
121
|
rules: [{ required: true, message: '请选择销售状态' }],
|
69
|
122
|
})(
|
70
|
123
|
<Select placeholder="销售状态">
|
71
|
|
- <Option value="未开盘">未开盘</Option>
|
72
|
|
- <Option value="在售">在售</Option>
|
73
|
|
- <Option value="售罄">售罄</Option>
|
74
|
|
- </Select>
|
|
124
|
+ {saleType.map((item, _) => (
|
|
125
|
+ <Option value={item.id}>{item.name}</Option>
|
|
126
|
+ ))}
|
|
127
|
+ </Select>,
|
75
|
128
|
)}
|
76
|
129
|
</Form.Item>
|
77
|
130
|
<Form.Item label="图片" help="建议图片尺寸336px*336px,比例1:1,格式:jpg">
|
78
|
|
- {getFieldDecorator('img', {
|
|
131
|
+ {getFieldDecorator('img', {
|
79
|
132
|
rules: [{ required: true, message: '请上传户型图片' }],
|
80
|
|
- })(
|
81
|
|
- <ImageUpload />,
|
82
|
|
- )}
|
|
133
|
+ })(<ImageUpload />)}
|
83
|
134
|
</Form.Item>
|
84
|
135
|
<Form.Item label="厅室">
|
85
|
136
|
{getFieldDecorator('houseType', {
|
86
|
137
|
rules: [{ required: true, message: '请填写户型厅室' }],
|
87
|
|
- })(<Input placeholder="例如: 三室一厅" />)}
|
|
138
|
+ })(
|
|
139
|
+ <Select placeholder="户型">
|
|
140
|
+ {houseType.map((item, _) => (
|
|
141
|
+ <Option value={item.id}>{item.name}</Option>
|
|
142
|
+ ))}
|
|
143
|
+ </Select>,
|
|
144
|
+ )}
|
88
|
145
|
</Form.Item>
|
89
|
146
|
<Form.Item label="面积">
|
90
|
147
|
{getFieldDecorator('buildingArea', {
|
91
|
|
- rules: [{ validator: validMinNum }]
|
92
|
|
- })(<InputNumber precision={2} min={0} step={0.01} addonAfter="㎡" />)}
|
|
148
|
+ rules: [{ validator: validMinNum }],
|
|
149
|
+ })(<InputNumber precision={2} min={0} step={0.01} addonAfter="㎡" />)}
|
93
|
150
|
</Form.Item>
|
94
|
151
|
<Form.Item label="使用面积">
|
95
|
152
|
{getFieldDecorator('insideArea', {
|
96
|
|
- rules: [{ validator: validMinNum }]
|
97
|
|
- })(<InputNumber precision={2} min={0} step={0.01} addonAfter="㎡" />)}
|
|
153
|
+ rules: [{ validator: validMinNum }],
|
|
154
|
+ })(<InputNumber precision={2} min={0} step={0.01} addonAfter="㎡" />)}
|
98
|
155
|
</Form.Item>
|
99
|
156
|
<Form.Item label="权重" help="数值越大越靠前">
|
100
|
157
|
{getFieldDecorator('orderNo', {
|
101
|
|
- rules: [{ validator: validMinNum }]
|
102
|
|
- })(<InputNumber min={0} step={1} style={fullWidth} />)}
|
|
158
|
+ rules: [{ validator: validMinNum }],
|
|
159
|
+ })(<InputNumber min={0} step={1} style={fullWidth} />)}
|
103
|
160
|
</Form.Item>
|
104
|
|
- <Form.Item label=" " colon={false} style={{marginTop: '2em'}}>
|
105
|
|
- <Button loading={loading} style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
|
106
|
|
- <Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button>
|
|
161
|
+ <Form.Item label=" " colon={false} style={{ marginTop: '2em' }}>
|
|
162
|
+ <Button loading={loading} style={{ marginLeft: '4em' }} type="primary" htmlType="submit">
|
|
163
|
+ 保存
|
|
164
|
+ </Button>
|
|
165
|
+ <Button style={{ marginLeft: '2em' }} onClick={props.onCancel}>
|
|
166
|
+ 取消
|
|
167
|
+ </Button>
|
107
|
168
|
</Form.Item>
|
108
|
169
|
</ModalForm>
|
109
|
|
- )
|
110
|
|
-}
|
|
170
|
+ );
|
|
171
|
+};
|
111
|
172
|
|
112
|
|
-export default Form.create({})(AMForm)
|
|
173
|
+export default Form.create({})(AMForm);
|