|
@@ -1,4 +1,4 @@
|
1
|
|
-import React from 'react';
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
2
|
2
|
import { Input, Button, Row, Col, Form, Alert } from 'antd';
|
3
|
3
|
import router from 'umi/router';
|
4
|
4
|
import Styles from './style.less';
|
|
@@ -8,22 +8,48 @@ import apis from '../../../services/apis';
|
8
|
8
|
function body(props) {
|
9
|
9
|
const { getFieldDecorator } = props.form;
|
10
|
10
|
|
11
|
|
- console.log('id: ', props.location.query.id)
|
|
11
|
+ // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
12
|
+ let data = {}
|
|
13
|
+ const { id } = props.location.query;
|
|
14
|
+
|
|
15
|
+ if (id !== '') {
|
|
16
|
+ // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
17
|
+ useEffect(() => {
|
|
18
|
+ getById(id)
|
|
19
|
+ }, [])
|
|
20
|
+ }
|
12
|
21
|
|
13
|
22
|
function handleSubmit(e) {
|
14
|
23
|
e.preventDefault();
|
15
|
24
|
props.form.validateFields((err, values) => {
|
16
|
25
|
if (!err) {
|
17
|
26
|
// 提交数据
|
18
|
|
- values.status = 1
|
19
|
|
- values.createDate = new Date()
|
20
|
27
|
submitData(values)
|
21
|
28
|
}
|
22
|
29
|
});
|
23
|
30
|
}
|
24
|
31
|
|
25
|
|
- function submitData(data) {
|
26
|
|
- request({ ...apis.buildingType.add, data: { ...data } }).then(() => {
|
|
32
|
+ // 获取详情信息
|
|
33
|
+ function getById(currentId) {
|
|
34
|
+ const { url, method } = apis.buildingType.getById
|
|
35
|
+ const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(currentId)
|
|
36
|
+
|
|
37
|
+ request({ url: tempUrl, method }).then(res => {
|
|
38
|
+ data = res
|
|
39
|
+ props.form.setFieldsValue(res)
|
|
40
|
+ })
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ function submitData(dataSources) {
|
|
44
|
+ if (id !== '') {
|
|
45
|
+ // 修改
|
|
46
|
+ updateType(dataSources)
|
|
47
|
+ return
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ dataSources.status = 1
|
|
51
|
+ dataSources.createDate = new Date()
|
|
52
|
+ request({ ...apis.buildingType.add, data: { ...dataSources } }).then(() => {
|
27
|
53
|
// eslint-disable-next-line no-unused-expressions
|
28
|
54
|
<Alert
|
29
|
55
|
style={{
|
|
@@ -47,9 +73,26 @@ function body(props) {
|
47
|
73
|
})
|
48
|
74
|
}
|
49
|
75
|
|
|
76
|
+ // 修改
|
|
77
|
+ function updateType(row) {
|
|
78
|
+ const { url, method } = apis.buildingType.update
|
|
79
|
+ const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(row.buildingTypeId)
|
|
80
|
+
|
|
81
|
+ request({ url: tempUrl, method, data: { ...row } }).then(() => {
|
|
82
|
+ router.go(-1)
|
|
83
|
+ })
|
|
84
|
+ }
|
|
85
|
+
|
50
|
86
|
return (
|
51
|
87
|
<>
|
52
|
88
|
<Form onSubmit={handleSubmit} style={{ width: '500px', margin: 'auto' }}>
|
|
89
|
+ <Form.Item style={{ display: 'none' }}>
|
|
90
|
+ {getFieldDecorator('buildingTypeId')(
|
|
91
|
+ <Input
|
|
92
|
+ placeholder="buildingTtypeId"
|
|
93
|
+ />,
|
|
94
|
+ )}
|
|
95
|
+ </Form.Item>
|
53
|
96
|
<Form.Item>
|
54
|
97
|
{getFieldDecorator('buildingTypeName', {
|
55
|
98
|
rules: [{ required: true, message: '请输入名称' }],
|