forked from huge/frontEnd/hugeOA

Mr Ke
2020-10-20 b701009667f62901cfd4be9be1f11fe38c630352
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
/* eslint-disable */
import React from 'react';
import { Card, Row, Col, Form, Input, Button, Select, message, Spin } from 'antd';
import { createHashHistory } from 'history'
import fetch from '../../api/request'
 
const history = createHashHistory();
const { TextArea } = Input;
const FormItem = Form.Item;
const Option = Select.Option;
 
class GroupDetail extends React.Component {
  constructor(props) {
    super(props)
    this.id = props.match.params.id == 'new' ? '' : props.match.params.id;
    this.flag = props.match.params.flag == 'Modify' ? '修改' : '新增';
    this.state = {
      spinning: false,
      dataSet: {}
    }
  }
 
  componentDidMount() {
    if (this.id) {
      this.setState({ spinning: true });
      fetch({
        url: `api/group/getById`,
        params: { id: this.id }
      }).then(res => {
        this.setState({ spinning: false });
        if (res) {
          this.setState({ dataSet: res });
        }
      })
    }
  }
 
  // 返回
  goBack = () => {
    history.goBack();
  }
 
  // 确定
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (err) return;
      this.setState({ spinning: true });
      fetch({
        url: `api/group/save`,
        method: 'POST',
        data: {
          ...this.state.dataSet,
          ...values
        }
      }).then(res => {
        this.setState({ spinning: false });
        message.success("保存组成功");
        history.goBack();
      })
    })
  }
 
  render() {
    const { getFieldDecorator } = this.props.form;
    const { dataSet } = this.state;
 
    const formItemLayout1 = {
      labelCol: { xs: { span: 24 }, sm: { span: 10 }, },
      wrapperCol: { xs: { span: 24 }, sm: { span: 14 }, },
    };
    const formItemLayout2 = {
      labelCol: { xs: { span: 24 }, sm: { span: 5 }, },
      wrapperCol: { xs: { span: 24 }, sm: { span: 19 }, },
    };
 
    return (
      <div className="groupdetail-main margin padding bg-white">
 
        <Spin spinning={this.state.spinning}>
          <div style={{ margin: 20 }}>
            <Form onSubmit={this.handleSubmit}>
 
              <Card title={this.id ? '基础信息(编辑)' : '基础信息(新增)'} bordered={false} extra={
                <Row type="flex" gutter={20}>
                  <Col>
                    <Button onClick={this.goBack}>返回</Button>
                  </Col>
                  <Col>
                    <Button htmlType="submit" type="primary">确定</Button>
                  </Col>
                </Row>
              }>
                <Row type="flex">
                  <Col span={8}>
                    <FormItem label={"标识符"} {...formItemLayout1}>
                      {getFieldDecorator('symbol', {
                        rules: [{ required: true, message: '标识符必填' }],
                        initialValue: dataSet.symbol || '',
                      })(
                        <Input placeholder="请输入标识符" />
                      )}</FormItem>
                  </Col>
                  <Col span={8}>
                    <FormItem label={"组名称"} {...formItemLayout1}>
                      {getFieldDecorator('name', {
                        rules: [{ required: true, message: '组名称必填' }],
                        initialValue: dataSet.name || ''
                      })(
                        <Input placeholder="请输入组名称" />
                      )}</FormItem>
                  </Col>
                </Row>
                <Row>
                  <Col span={8}>
                    <FormItem label={"组类型"} {...formItemLayout1}>
                      {getFieldDecorator('groupType', {
                        rules: [{ required: true, message: '组类型必选' }],
                        initialValue: dataSet.groupType || undefined
                      })(
                        <Select style={{ width: '100%' }} placeholder="请选择" allowClear>
                          <Option value={1}>用户类型</Option>
                          <Option value={2}>角色类型</Option>
                          <Option value={3}>资源类型</Option>
                        </Select>
                      )}</FormItem>
                  </Col>
                </Row>
                <Row>
                  <Col span={16}>
                    <FormItem label={"描述"} {...formItemLayout2}>
                      {getFieldDecorator('description', {
                        rules: [{ max: 200, message: '描述的内容不能超过200字' }],
                        initialValue: dataSet.description || ''
                      })(
                        <TextArea placeholder="请输入描述" rows={5} />
                      )}</FormItem>
                  </Col>
                </Row>
              </Card>
            </Form>
          </div>
        </Spin>
      </div>
    )
  }
}
 
const GroupDetailForm = Form.create()(GroupDetail);
export default GroupDetailForm;