forked from huge/frontEnd/hugeOA

Mr Ke
2020-10-20 6bf92751fe8dfa0624285268968a1fd7a8a7e7e5
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
/* eslint-disable */
import React from 'react';
import { Link } from 'react-router-dom';
import { Card, Row, Col, Form, Input, Button, Select, Spin } from 'antd';
import fetch from '../../api/request'
 
const FormItem = Form.Item;
const { TextArea } = Input;
 
 
class DeptDetail extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      spinning: true,
      id: "",
      dataSet: {}
    }
  }
 
  componentDidMount() { }
 
  handleSubmit = (e) => { // 提交表单数据
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (err) return;
      let obj = {
        ...values,
        id: this.props.params.id,//部门id
        unitId: this.props.params.currentNode[0].id//单位编号
      }
      //触发父级函数,调用保存接口
      this.props.saveFun(obj)
    })
  }
 
  render() {
    const { getFieldDecorator } = this.props.form;
    const { params, dataSet } = this.props;
    const formItemLayout = {
      labelCol: { xs: { span: 24 }, sm: { span: 5 }, },
      wrapperCol: { xs: { span: 24 }, sm: { span: 19 }, },
    };
 
    return (
      <div className="deptdetail-main h-100">
        <Spin spinning={this.props.loading}>
          <div>
            <Form onSubmit={this.handleSubmit}>
              <Card title={params.id == '' ? '部门新增' : '部门编辑'} bordered={false}
                extra={<Row type="flex" gutter={20}>
                  <Col>
                    <Button onClick={this.props.cancelFun}>返回</Button>
                  </Col>
                  <Col>
                    <Button type="primary" htmlType="submit" >确认</Button>
                  </Col>
                </Row>}
              >
                <Row type="flex" >
                  <Col span={14}>
                    <FormItem label={"单位"} {...formItemLayout}>
                      <span>{params.currentNode[0].name}</span>
                    </FormItem>
                  </Col>
                </Row>
                <Row type="flex" >
                  <Col span={14}>
                    <FormItem label={"部门名称"} {...formItemLayout}>
                      {getFieldDecorator('name', {
                        rules: [{ required: true, message: '请输入部门名称' }],
                        initialValue: dataSet.name || '',
                      })(
                        <Input placeholder="请输入部门名称" />
                      )}</FormItem>
                  </Col>
                </Row>
                <Row type="flex" >
                  <Col span={14}>
                    <FormItem label={"描述"} {...formItemLayout}>
                      {getFieldDecorator('description', {
                        rules: [{ max: 200, message: '描述的内容不能超过200字' }],
                        initialValue: dataSet.description
                      })(
                        <TextArea placeholder="请输入描述" rows={5} />
                      )}</FormItem>
                  </Col>
                </Row>
              </Card>
            </Form>
          </div>
        </Spin>
      </div>
    )
  }
}
 
const DeptDetailForm = Form.create()(DeptDetail);
export default DeptDetailForm;