/* eslint-disable */
|
import React from 'react';
|
import { Card, Row, Col, Form, Input, Button, Spin, message } from 'antd';
|
import fetch from '../../api/request';
|
|
const { TextArea } = Input;
|
const FormItem = Form.Item;
|
|
class GroupDetail extends React.Component {
|
constructor(props) {
|
super(props)
|
this.state = {
|
spinning: false,
|
id: '',
|
parentId: '',
|
dataSet: {},
|
btnLoading: false,//保存按钮loading
|
}
|
}
|
|
componentWillMount() {
|
}
|
componentDidMount() {
|
}
|
|
handleSubmit = (e) => { // 提交表单数据
|
e.preventDefault();
|
let parentId = '';
|
if (this.props.params.currentNode.length == 0) {
|
//没有选中节点
|
parentId = '';
|
} else {
|
// 判断是新增还是编辑
|
if (this.props.params.id == '') {
|
parentId = this.props.params.currentNode[0].id //此为新增
|
} else {
|
parentId = this.props.params.currentNode[0].parentId //此为编辑
|
}
|
}
|
this.props.form.validateFields((err, values) => {
|
if (err) return;
|
this.setState({ btnLoading: true });
|
fetch({
|
url: `api/unit/save`,
|
method: 'POST',
|
data: {
|
...values,
|
id: this.props.params.id,
|
parentId
|
}
|
}).then(res => {
|
this.setState({ btnLoading: false })
|
if (res) {
|
message.success("保存成功");
|
this.props.saveFun(values);//触发父级保存响应函数,刷新页面数据
|
}
|
})
|
})
|
}
|
|
render() {
|
const { getFieldDecorator } = this.props.form;
|
const formItemLayout = {
|
labelCol: { xs: { span: 24 }, sm: { span: 5 }, },
|
wrapperCol: { xs: { span: 24 }, sm: { span: 19 }, },
|
};
|
|
const { params } = this.props;
|
const dataSet = this.props.dataSet || {};
|
const { btnLoading } = this.state;
|
|
return (
|
<div>
|
{
|
this.props.edit == 'true' ?
|
<div>
|
<Spin spinning={this.props.loading}>
|
<div>
|
<Form onSubmit={this.handleSubmit}>
|
<Card title={this.props.params.id ? '单位信息(编辑)' : '单位信息(新增)'} bordered={false}>
|
{
|
this.props.params.currentNode.length > 0 && Object.keys(dataSet).length == 0 &&
|
<Row type="flex">
|
<Col span={16}>
|
<FormItem label={"上级单位"} {...formItemLayout}>
|
<span>{params.currentNode[0].name}</span>
|
</FormItem>
|
</Col>
|
</Row>
|
}
|
<Row type="flex">
|
<Col span={16}>
|
<FormItem label={"单位名称"} {...formItemLayout}>
|
{getFieldDecorator('name', {
|
rules: [{ required: true, message: '请输入单位名称' }],
|
initialValue: dataSet.name || '',
|
})(
|
<Input placeholder="请输入单位名称" />
|
)}</FormItem>
|
</Col>
|
</Row>
|
<Row type="flex">
|
<Col span={16}>
|
<FormItem label={"描述"} {...formItemLayout}>
|
{getFieldDecorator('description', {
|
rules: [{ max: 200, message: '描述的内容不能超过200字' }],
|
initialValue: dataSet.description || ''
|
})(
|
<TextArea placeholder="请输入描述" rows={5} />
|
)}</FormItem>
|
</Col>
|
</Row>
|
<Row type="flex" justify="center" gutter={20} style={{ width: '75%' }}>
|
<Col>
|
<Button onClick={this.props.cancelFun}>取消</Button>
|
</Col>
|
<Col>
|
<Button type="primary" htmlType="submit" loading={btnLoading}>保存</Button>
|
</Col>
|
</Row>
|
</Card>
|
</Form>
|
</div>
|
</Spin>
|
</div>
|
:
|
<div>
|
<Spin spinning={this.props.loading}>
|
<div>
|
<Form onSubmit={this.props.editFun}>
|
|
<Card title={'单位信息'} bordered={false}>
|
<Row type="flex">
|
<Col span={16}>
|
<FormItem label={"单位名称"} {...formItemLayout} style={{ marginBottom: 10 }}>
|
<span>{dataSet.name || '暂无'}</span>
|
</FormItem>
|
</Col>
|
</Row>
|
<Row type="flex">
|
<Col span={16}>
|
<FormItem label={"描述"} {...formItemLayout} style={{ marginBottom: 10 }}>
|
{dataSet.description || '暂无'}
|
</FormItem>
|
</Col>
|
</Row>
|
<Row type='flex' gutter={20} justify="center" style={{ width: '75%' }}>
|
<Col>
|
<Button onClick={this.props.cancelData}>取消</Button>
|
</Col>
|
<Col>
|
<Button className="button-do" htmlType="submit" type="primary">编辑</Button>
|
</Col>
|
</Row>
|
</Card>
|
</Form>
|
</div>
|
</Spin>
|
</div>
|
}
|
</div>
|
)
|
}
|
}
|
|
const GroupDetailForm = Form.create()(GroupDetail);
|
export default GroupDetailForm;
|