|
@@ -1,22 +1,59 @@
|
1
|
|
-import React from 'react'
|
2
|
|
-import { Button, Form, Input, Select } from 'antd'
|
|
1
|
+import React, { useEffect, useState } from 'react'
|
|
2
|
+import { Button, Form, Input, message, Select } from 'antd'
|
3
|
3
|
import ImageUpload from '@/components/XForm/ImageUpload'
|
|
4
|
+import { fetch, apis } from '@/utils/request'
|
4
|
5
|
import ModalForm from '../components/ModalForm'
|
5
|
6
|
import InputNumber from '../components/InputNumber'
|
6
|
7
|
import { validMinNum } from '../utils'
|
7
|
8
|
|
8
|
9
|
const Option = Select.Option
|
9
|
10
|
const fullWidth = { width: '100%' }
|
|
11
|
+const saveData = fetch(apis.building.buildingApartmentAdd)
|
|
12
|
+const updateData = fetch(apis.building.buildingApartmentUpdate)
|
10
|
13
|
|
11
|
14
|
const AMForm = (props) => {
|
12
|
|
- const { visible, onCancel, form } = props
|
13
|
|
- const { getFieldDecorator } = form
|
|
15
|
+ const { visible, onCancel, form, onSubmit } = props
|
|
16
|
+ const { getFieldDecorator, setFieldsValue, resetFields, validateFields } = form
|
|
17
|
+
|
|
18
|
+ const [loading, setLoading] = useState(false)
|
|
19
|
+
|
|
20
|
+ const handleSubmit = (e) => {
|
|
21
|
+ e.preventDefault();
|
|
22
|
+ validateFields((err, values) => {
|
|
23
|
+ if (err) {
|
|
24
|
+ console.error(err)
|
|
25
|
+ return
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ const request = props.formData.apartmentId ? updateData : saveData
|
|
29
|
+ const data = {
|
|
30
|
+ ...(props.formData),
|
|
31
|
+ ...values,
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ setLoading(true)
|
|
35
|
+ request({ data }).then((res) => {
|
|
36
|
+ setLoading(false)
|
|
37
|
+ message.success('操作成功')
|
|
38
|
+ props.onSuccess(res)
|
|
39
|
+ }).catch((err) => {
|
|
40
|
+ setLoading(false)
|
|
41
|
+ console.error(err)
|
|
42
|
+ })
|
|
43
|
+ })
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ useEffect(() => {
|
|
47
|
+ resetFields()
|
|
48
|
+ setFieldsValue(props.formData || {})
|
|
49
|
+ }, [props.formData])
|
14
|
50
|
|
15
|
51
|
return (
|
16
|
52
|
<ModalForm
|
17
|
53
|
title="户型设置"
|
18
|
54
|
visible={visible}
|
19
|
55
|
onCancel={onCancel}
|
|
56
|
+ onSubmit={handleSubmit}
|
20
|
57
|
>
|
21
|
58
|
<Form.Item label="编号" style={{ display: 'none' }}>
|
22
|
59
|
{getFieldDecorator('apartmentId')(<Input />)}
|
|
@@ -68,7 +105,7 @@ const AMForm = (props) => {
|
68
|
105
|
})(<InputNumber min={0} step={1} style={fullWidth} />)}
|
69
|
106
|
</Form.Item>
|
70
|
107
|
<Form.Item label=" " colon={false} style={{marginTop: '2em'}}>
|
71
|
|
- <Button style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
|
|
108
|
+ <Button loading={loading} style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
|
72
|
109
|
<Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button>
|
73
|
110
|
</Form.Item>
|
74
|
111
|
</ModalForm>
|