forked from huge/frontEnd/hugeOA

liyj
2020-09-07 f7e9b835c30e5b3287b2c04e24950871cafa907d
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import React from 'react';
import { Card, Row, Col, Icon, Form, Input, Button, Spin, Modal, Radio } from 'antd';
 
const { TextArea } = Input;
const FormItem = Form.Item;
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
 
class ModuleDetailEdit extends React.Component {
  constructor(props) {
    super(props)
    // this.id = props.match.params.id;
    // this.flag = props.match.params.flag == 'Modify' ? '修改' : '新增';
    this.state = {
      spinning: false,
      id: '',
      parentId: '',
      dataSet: {},
    }
  }
 
  componentDidMount() { }
 
  //提交表单数据(保存)
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      console.log('提交表单数据:', values);
      if (err) return;
      //触发父级保存接口函数
      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 { dataSet, params, loading } = this.props;
 
    return (
      <div>
        {
          this.props.edit == 'true' ?
            <div>
              <Spin spinning={loading}>
 
                <div>
                  <Form onSubmit={this.handleSubmit}>
                    <Card title={params.id ? '模块信息(编辑)' : '模块信息(新增)'} bordered={false}>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"资源类型"} {...formItemLayout}>
                            {getFieldDecorator('isMenu', {
                              rules: [{ required: true, message: '资源类型必选' }],
                              initialValue: dataSet.isMenu
                            })(
                              <RadioGroup>
                                <RadioButton value={1}>菜单</RadioButton>
                                <RadioButton value={0}>模块</RadioButton>
                              </RadioGroup>
                            )}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"标识符"} {...formItemLayout}>
                            {getFieldDecorator('symbol', {
                              rules: [{ required: true, message: '请输入标志符' }],
                              initialValue: dataSet.symbol || '',
                            })(
                              <Input placeholder="请输入标识符" />
                            )}</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('url', {
                              rules: [{ required: true, message: '请输入路径' }],
                              initialValue: dataSet.url || '',
                            })(
                              <Input />
                            )}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"路径设置"} {...formItemLayout}>
                            {getFieldDecorator('urlType', {
                              rules: [{ required: true, message: '路径类型必选' }],
                              initialValue: dataSet.urlType || undefined
                            })(
                              <RadioGroup>
                                <RadioButton value={1}>相对路径</RadioButton>
                                <RadioButton value={0}>绝对路径</RadioButton>
                              </RadioGroup>
                            )}
                          </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" gutter={20} style={{ width: '75%' }} justify="center">
                        <Col>
                          <Button onClick={this.props.cancelFun}>取消</Button>
                        </Col>
                        <Col>
                          <Button className="button-do" htmlType="submit" type="primary">保存</Button>
                        </Col>
                      </Row>
                    </Card>
                  </Form>
                </div>
              </Spin>
            </div>
            :
            <div>
              <Spin spinning={loading}>
                <div>
                  <Form onSubmit={this.props.editFun}>
                    <Card title={'模块信息'} bordered={false}>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"资源类型"} {...formItemLayout}>
                            {dataSet.isMenu == 1 && '菜单'}
                            {dataSet.isMenu == 0 && '模块'}
 
                          </FormItem>
                        </Col>
                      </Row>
 
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"标识符"} {...formItemLayout}>
                            {dataSet.symbol}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"资源名称"} {...formItemLayout}>
                            {dataSet.name}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"路径"} {...formItemLayout}>
                            {dataSet.url}
                            {dataSet.urlType == 1 && "(相对地址)"}
                            {dataSet.urlType == 0 && "(绝对地址)"}
                          </FormItem>
                        </Col>
                      </Row>
                      <Row type="flex">
                        <Col span={16}>
                          <FormItem label={"描述"} {...formItemLayout}>
                            <TextArea value={dataSet.description} rows={5} disabled={true} />
                          </FormItem>
                        </Col>
                      </Row>
                      <Row type="flex" gutter={20} style={{ width: '75%' }} justify="center">
                        <Col>
                          <Button onClick={this.props.cancelData}>取消</Button>
                        </Col>
                        <Col>
                          <Button type="primary" htmlType="submit">编辑</Button>
                        </Col>
                      </Row>
                    </Card>
                  </Form>
                </div>
              </Spin>
            </div>
        }
      </div>
    )
  }
}
 
// const SHOW_PARENT = TreeSelect.SHOW_PARENT;
const ModuleDetailEditForm = Form.create()(ModuleDetailEdit);
export default ModuleDetailEditForm;