forked from nsjcy/frontEnd/nsjcy

bug
liuwh
2020-03-24 51351c2d8c7297cb3f96e572c0e1a110ce8a5073
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
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;