insCompanyOpt.js
4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import React from 'react'
import { Form, Button, Input, Select, message, Tree, Radio, Row, Col, Spin } from 'antd'
import { NavLink } from 'react-router-dom'
import UserManageBar from '@components/Common/WhiteBar/index'
import axios from '@src/axios/index'
import Utils from '@src/utils/utils'
import {API_CUSTOMER_MANAGE} from '@src/Api'
const FormItem = Form.Item;
class insCompanyOpt extends React.Component {
state = {
form:{
name: '',
id: '',
},
routerParams: '新增公司',
isLoad: true,
isLoadTree: false, // 为true 的情况下 并且 isLoad为false 的情况下 加载树
disabled: true,
spinStatus: false, // 是否显示加载中
};
componentWillMount() {
document.getElementById('root').scrollIntoView(true);//为ture返回顶部,false为底部
}
componentDidMount() {
this.getRouterParams()
}
// 根据路由判断进来的是修改还是新增
getRouterParams = () => {
const params = this.props.match.params
if (!params || !params.params) {
message.warn('请重新选择,或者刷新页面')
this.props.history.push({
pathname: '/home/system/insCompany',
});
return
}
if (params.params === 'add') {
this.setState({
routerParams: '新增保险公司',
disabled: true,
})
} else if (params.params === 'edit') {
this.setState({
routerParams: '修改保险公司',
disabled: false,
spinStatus: true,
})
this.getDetail()
}
}
// 如果是修改 那么就要获取修改某条数据的信息并填充表单
getDetail= () => {
const { params } = this.props.match
if (params.id) {
axios.ajax({
url: API_CUSTOMER_MANAGE.getInsuranceCompanyByid,
data: {
id: params.id
}
}).then(res => {
console.log(res)
if (res && Object.keys(res).length > 0) {
this.setState({isLoad: false, spinStatus: false, form: res})
}
})
}
}
// 保存操作
handleOperator = (e) => {
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.setState({spinStatus: true})
const params = this.props.match.params
let url = params.params && params.params === 'add' ? API_CUSTOMER_MANAGE.addInsuranceCompany : API_CUSTOMER_MANAGE.updInsuranceCompany
const formData = this.props.form.getFieldsValue()
const data = {
id: this.state.form.id,
name: formData.name
}
axios.optAjax({
url: url,
data: {
...data
}
}).then(res => {
if(res && res.code && res.code !== 0){
this.setState({
spinStatus: false,
})
return
}
message.success('操作成功')
this.props.history.push('/home/system/insCompany')
})
}
});
};
render () {
const { getFieldDecorator } = this.props.form;
const state = this.state;
const formItemLayout = {
labelCol: {
md: { span: 12 },
lg: { span: 6 },
},
wrapperCol: {
md: { span: 24 },
lg: { span: 18 },
},
}
return (
<div className='dictBg'>
<Spin tip="加载中..." spinning = {this.state.spinStatus}>
<div className="roleAdd">
<div className="nav">
<NavLink to='/home/system/insCompany' > 保险公司管理 </NavLink> >
<span>{this.state.routerParams}</span>
</div>
<UserManageBar title="基本信息" />
<div className="dictDetail">
<Form layout="horizontal" className = "publicForm">
<Row gutter={24}>
<Col span="8">
<FormItem label="公司名称" { ...formItemLayout}>
{
getFieldDecorator('name', {
initialValue: state.form.name,
rules: [
{required: true, message: '请输入公司名称'},
{max: 32, whitespace: true, message: '公司名称最长为32位字符'},
],
})(
<Input placeholder="保公司名称"/>
)
}
</FormItem>
</Col>
</Row>
</Form>
</div>
<div className="submitBtn" >
<Button type="primary" disabled = {this.state.spinStatus} onClick={this.handleOperator} >保存</Button>
<NavLink to='/home/system/insCompany' ><Button> 返回 </Button></NavLink>
</div>
</div>
</Spin>
</div>
)
}
}
export default Form.create()(insCompanyOpt);