king
2022-10-17 e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Row, Col, Input, Select, Switch } from 'antd'
import { formRule } from '@/utils/option.js'
import './index.scss'
 
const { TextArea } = Input
 
class MainSearch extends Component {
  static propTpyes = {
    menu: PropTypes.object,
    config: PropTypes.object,
    updatemenu: PropTypes.func
  }
 
  state = {
    menulist: [],
    submenulist: []
  }
 
  UNSAFE_componentWillMount () {
    const { menu } = this.props
 
    this.setState({
      menulist: menu.fstMenuList || [],
      submenulist: menu.supMenuList || []
    })
  }
 
  selectChange = (key, value) => {
    const { config } = this.props
    const { menulist } = this.state
 
    if (key === 'fstMenuId') {
      let _menu = menulist.filter(cell => cell.MenuID === value)[0]
      let options = _menu ? _menu.children : []
      let ParentId = options[0] ? options[0].MenuID : ''
 
      this.setState({
        submenulist: options
      }, () => {
        this.props.form.setFieldsValue({ParentId: ParentId})
      })
      this.props.updatemenu({...config, fstMenuId: value, ParentId: ParentId})
    } else if (key === 'ParentId') {
      this.setState({}, () => {
        this.props.updatemenu({...config, ParentId: value})
      })
    } else if (key === 'opentype') {
      this.setState({}, () => {
        this.props.updatemenu({...config, OpenType: value})
      })
    } else if (key === 'hidden') {
      this.setState({}, () => {
        this.props.updatemenu({...config, hidden: value})
      })
    }
  }
 
  changeName = (e) => {
    let value = e.target.value || ''
    if (value.length > 100) return
    this.setState({}, () => {
      this.props.updatemenu({...this.props.config, MenuName: value})
    })
  }
 
  changeNo = (e) => {
    let value = e.target.value || ''
    if (value.length > 100) return
    this.setState({}, () => {
      this.props.updatemenu({...this.props.config, MenuNo: value})
    })
  }
 
  changeEasyCode = (e) => {
    let value = e.target.value || ''
    if (value.length > 100) return
    this.setState({}, () => {
      this.props.updatemenu({...this.props.config, easyCode: value})
    })
  }
 
  changeRemark = (e) => {
    let value = e.target.value || ''
    this.setState({}, () => {
      this.props.updatemenu({...this.props.config, Remark: value})
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return is(fromJS(this.props), fromJS(nextProps))
  }
 
  render() {
    const { menu, config } = this.props
    const { getFieldDecorator } = this.props.form
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      }
    }
 
    return (
      <Form {...formItemLayout} className="comtable-menu-form" id="subqazxcvbn">
        <Row gutter={24}>
          <Col span={24}>
            <Form.Item label="一级菜单">
              {getFieldDecorator('fstMenuId', {
                initialValue: menu.fstMenuId,
                rules: [
                  {
                    required: true,
                    message: '请选择一级菜单!'
                  }
                ]
              })(
                <Select onChange={(value) => {this.selectChange('fstMenuId', value)}}>
                  {this.state.menulist.map(option =>
                    <Select.Option key={option.MenuID} value={option.MenuID}>
                      {option.text || option.MenuName}
                    </Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="二级菜单">
              {getFieldDecorator('ParentId', {
                initialValue: menu.ParentId,
                rules: [
                  {
                    required: true,
                    message: '请选择二级菜单!'
                  }
                ]
              })(
                <Select onChange={(value) => {this.selectChange('ParentId', value)}}>
                  {this.state.submenulist.map(option =>
                    <Select.Option key={option.MenuID} value={option.MenuID}>
                      {option.text || option.MenuName}
                    </Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="菜单名称">
              {getFieldDecorator('MenuName', {
                initialValue: menu.MenuName,
                rules: [
                  {
                    required: true,
                    message: '请输入菜单名称!'
                  },
                  {
                    max: formRule.input.max,
                    message: formRule.input.message
                  }
                ]
              })(<Input placeholder="" autoComplete="off" onChange={this.changeName}/>)}
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="菜单参数">
              {getFieldDecorator('MenuNo', {
                initialValue: menu.MenuNo,
                rules: [
                  {
                    required: true,
                    message: '请输入菜单参数!'
                  },
                  {
                    max: formRule.input.max,
                    message: formRule.input.message
                  }
                ]
              })(<Input placeholder="" autoComplete="off" onChange={this.changeNo}/>)}
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="打开方式">
              {getFieldDecorator('opentype', {
                initialValue: menu.PageParam ? menu.PageParam.OpenType : 'newtab',
                rules: [
                  {
                    required: true,
                    message: '请选择打开方式!'
                  }
                ]
              })(
                <Select onChange={(value) => {this.selectChange('opentype', value)}}>
                  <Select.Option value="newtab">标签页</Select.Option>
                  <Select.Option value="newpage">新页面</Select.Option>
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="助记码">
              {getFieldDecorator('easyCode', {
                initialValue: config.easyCode,
                rules: [
                  {
                    max: formRule.input.max,
                    message: formRule.input.message
                  }
                ]
              })(<Input placeholder="" autoComplete="off" onChange={this.changeEasyCode}/>)}
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item className="hidden-menu" labelCol={{span: 8}} wrapperCol={{span: 16}} label={'隐藏菜单'}>
              <Switch checkedChildren={'是'} defaultChecked={menu.PageParam ? (menu.PageParam.hidden === 'true') : false} unCheckedChildren={'否'} onChange={(value) => {
                this.selectChange('hidden', value + '')
              }} />
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="备注">
              {getFieldDecorator('Remark', {
                initialValue: config.Remark || '',
                rules: [
                  {
                    max: 512,
                    message: '备注最多512个字符!'
                  }
                ]
              })(<TextArea rows={2} placeholder={''} onChange={this.changeRemark} />)}
            </Form.Item>
          </Col>
        </Row>
      </Form>
    )
  }
}
 
export default Form.create()(MainSearch)