import React from 'react';
|
import { Card, Row, Col, message, Form, Input, Button,Spin } from 'antd';
|
|
import Fetch from '../fetch';
|
|
const FormItem = Form.Item;
|
|
class GroupDetail extends React.Component{
|
constructor(props){
|
super(props)
|
this.state={
|
spinning:false,
|
id: '',
|
parentId: '',
|
dataSet: {},
|
}
|
}
|
|
componentWillMount(){
|
}
|
componentDidMount() {
|
}
|
|
handleSubmit = (e) => { // 提交表单数据
|
|
let _this = this;
|
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) => {
|
console.log('提交表单数据:',values);
|
if(err) return;
|
Fetch.saveType({
|
...values,
|
id: _this.props.params.id,
|
parentId
|
}).then( res => {
|
if( res.statuscode == 1 ) {
|
message.success("保存成功", 2)
|
_this.props.saveFun(values);
|
}else{
|
message.error(res.msg, 2);
|
}
|
this.setState({ spinning: false });
|
})
|
})
|
}
|
|
render(){
|
const { getFieldDecorator } = this.props.form;
|
|
const formItemLayout2 = {
|
labelCol: {xs: {span: 24}, sm: {span: 5},},
|
wrapperCol: {xs: {span: 24}, sm: {span: 19},},
|
};
|
const { params } =this.props;
|
const dataSet = this.props.dataSet || {};
|
console.log(dataSet);
|
return(
|
<div>
|
{
|
this.props.edit == 'true' ?
|
<div>
|
<Spin spinning={this.props.loading}>
|
<div>
|
<Form onSubmit={this.handleSubmit}>
|
<div className="card-title">
|
<Row style={{borderStyle:'solid', borderWidth:0.01, display: 'flex'}}>
|
<span style={{fontSize:16,fontWeight:650}} className="flex1 vertical-middle">文章分类编辑</span>
|
</Row>
|
</div>
|
<Card>
|
{
|
this.props.params.currentNode.length > 0 && Object.keys(dataSet).length == 0 &&
|
<Row>
|
<Col span={11}>
|
<FormItem label={"上级分类"} {...formItemLayout2}>
|
<span>{params.currentNode[0].channelName}</span>
|
</FormItem>
|
</Col>
|
</Row>
|
}
|
<Row>
|
<Col span={11}>
|
<FormItem label={"分类名称"} {...formItemLayout2}>
|
{getFieldDecorator('channelName',{
|
rules: [{ required: true, message: '请输入分类名称' }],
|
initialValue:dataSet.channelName || '',
|
})(
|
<Input placeholder="请输入分类名称" />
|
)}</FormItem>
|
</Col>
|
</Row>
|
<Row>
|
<Button className="button-do" htmlType="submit">保存</Button>
|
<Button onClick={this.props.cancelFun} style={{margin:'5px'}}>取消</Button>
|
</Row>
|
</Card>
|
</Form>
|
</div>
|
</Spin>
|
</div>
|
:
|
<div>
|
<Spin spinning={this.state.spinning}>
|
<div>
|
<Form onSubmit={this.props.editFun}>
|
<div className="card-title">
|
<Row style={{borderStyle:'solid', borderWidth:0.01, display: 'flex'}}>
|
<span style={{fontSize:16,fontWeight:650}} className="flex1 vertical-middle">文章分类信息</span>
|
</Row>
|
</div>
|
<Card>
|
<Row>
|
<Col span={11}>
|
<FormItem label={"分类名称"} {...formItemLayout2}>
|
<span>{dataSet.channelName}</span>
|
</FormItem>
|
</Col>
|
</Row>
|
|
<Row>
|
<Button className="button-do" htmlType="submit">编辑</Button>
|
<Button onClick={this.props.cancelData} style={{margin:'5px'}}>取消</Button>
|
</Row>
|
</Card>
|
</Form>
|
</div>
|
</Spin>
|
</div>
|
}
|
</div>
|
)
|
}
|
}
|
|
// const SHOW_PARENT = TreeSelect.SHOW_PARENT;
|
const GroupDetailForm = Form.create()(GroupDetail);
|
export default GroupDetailForm;
|