| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Form, Row, Col, Input, Select, Icon } from 'antd' |
| | | import Utils from '@/utils/utils.js' |
| | | import './index.scss' |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | options: PropTypes.object |
| | | } |
| | | |
| | | state = { |
| | | formlist: [], |
| | | menuform: { |
| | | slevel: [ |
| | | { |
| | | type: 'select', |
| | | key: 'parentId', |
| | | label: this.props.dict['header.menu.supMenu'], |
| | | initVal: '', |
| | | required: true, |
| | | options: [] |
| | | }, |
| | | { |
| | | type: 'text', |
| | | key: 'menuName', |
| | | label: this.props.dict['header.menu.menuName'], |
| | | initVal: '', |
| | | required: true, |
| | | readonly: false |
| | | }, |
| | | { |
| | | type: 'select', |
| | | key: 'icon', |
| | | label: this.props.dict['header.menu.icon'], |
| | | initVal: 'folder', |
| | | required: true, |
| | | options: [{ |
| | | MenuID: 'folder', |
| | | text: 'folder' |
| | | }, { |
| | | MenuID: 'api', |
| | | text: 'api' |
| | | }] |
| | | } |
| | | ], |
| | | tlevel: [ |
| | | { |
| | | type: 'select', |
| | | key: 'parentId', |
| | | label: this.props.dict['header.menu.supMenu'], |
| | | initVal: '', |
| | | required: true, |
| | | options: [] |
| | | }, |
| | | { |
| | | type: 'text', |
| | | key: 'menuName', |
| | | label: this.props.dict['header.menu.menuName'], |
| | | initVal: '', |
| | | required: true, |
| | | readonly: false |
| | | }, |
| | | { |
| | | type: 'text', |
| | | key: 'menuNo', |
| | | label: this.props.dict['header.menu.menuNo'], |
| | | initVal: '', |
| | | required: true, |
| | | readonly: false |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | this.resetform(this.props.options) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (nextProps.options.visible && !is(fromJS(this.props.options), fromJS(nextProps.options))) { |
| | | this.resetform(nextProps.options) |
| | | } |
| | | } |
| | | |
| | | resetform = (options) => { |
| | | if (!options.visible) return |
| | | |
| | | let formlist = JSON.parse(JSON.stringify(this.state.menuform[options.level])) |
| | | if (options.type === 'add' && options.level === 'slevel') { |
| | | this.setState({ |
| | | formlist: formlist.map(item =>{ |
| | | if (item.key === 'parentId') { |
| | | item.initVal = options.parentMenu.MenuID |
| | | item.options = options.supMenuList |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | } else if (options.type === 'add' && options.level === 'tlevel') { |
| | | this.setState({ |
| | | formlist: formlist.map(item =>{ |
| | | if (item.key === 'parentId') { |
| | | item.initVal = options.parentMenu.MenuID |
| | | item.options = options.supMenuList |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | } else if (options.type === 'edit' && options.level === 'slevel') { |
| | | this.setState({ |
| | | formlist: formlist.map(item => { |
| | | if (item.key === 'parentId') { |
| | | item.initVal = options.parentMenu.MenuID |
| | | item.options = options.supMenuList |
| | | } else if (item.key === 'menuName') { |
| | | item.initVal = options.menu.text |
| | | } else if (item.key === 'icon') { |
| | | item.initVal = options.menu.PageParam.Icon |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | } else if (options.type === 'edit' && options.level === 'tlevel') { |
| | | this.setState({ |
| | | formlist: formlist.map(item => { |
| | | if (item.key === 'parentId') { |
| | | item.initVal = options.parentMenu.MenuID |
| | | item.options = options.supMenuList |
| | | } else if (item.key === 'menuName') { |
| | | item.initVal = options.menu.text |
| | | } else if (item.key === 'menuNo') { |
| | | item.initVal = options.menu.MenuNo |
| | | } |
| | | return item |
| | | }) |
| | | }) |
| | | } |
| | | formlist: PropTypes.array |
| | | } |
| | | |
| | | openTypeChange = (key, value) => { |
| | |
| | | getFields() { |
| | | const { getFieldDecorator } = this.props.form |
| | | const fields = [] |
| | | this.state.formlist.forEach((item, index) => { |
| | | if (item.hidden) return |
| | | |
| | | this.props.formlist.forEach((item, index) => { |
| | | if (item.type === 'text') { // 文本搜索 |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | |
| | | ) |
| | | } |
| | | }) |
| | | |
| | | return fields |
| | | } |
| | | |
| | |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | if (this.props.options.type === 'add' && this.props.options.level === 'slevel') { |
| | | // 二级菜单添加 |
| | | resolve({ |
| | | ParentID: values.parentId, |
| | | MenuID: Utils.getuuid(), |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | Icon: values.icon |
| | | }) |
| | | }) |
| | | } else if (this.props.options.type === 'edit' && this.props.options.level === 'slevel') { |
| | | resolve({ |
| | | ParentID: values.parentId, |
| | | MenuID: this.props.options.menu.MenuID, |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | Icon: values.icon |
| | | }) |
| | | }) |
| | | } else if (this.props.options.type === 'add' && this.props.options.level === 'tlevel') { |
| | | resolve({ |
| | | ParentID: values.parentId, |
| | | MenuID: this.props.options.menu.MenuID, |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | Icon: values.icon |
| | | }) |
| | | }) |
| | | } else if (this.props.options.type === 'edit' && this.props.options.level === 'tlevel') { |
| | | resolve({ |
| | | ParentID: values.parentId, |
| | | MenuID: this.props.options.menu.MenuID, |
| | | MenuName: values.menuName, |
| | | MenuNo: values.menuNo, |
| | | PageParam: JSON.stringify({ |
| | | Icon: values.icon |
| | | }) |
| | | }) |
| | | } |
| | | resolve(values) |
| | | } else { |
| | | reject(err) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | handleReset = (type) => { |
| | | // 重置 |
| | | if (type === 'add') { |
| | | let formlist = this.state.formlist.map(item => { |
| | | if (item.key === 'linkUrl') { |
| | | item.hidden = true |
| | | } |
| | | return item |
| | | }) |
| | | this.setState({formlist}) |
| | | } |
| | | this.props.form.resetFields() |
| | | } |
| | | |
| | | render() { |