king
2020-04-03 4c6bdfe1f3557e49a315c1564bcb6164c0bc7faa
src/templates/zshare/columnform/index.jsx
@@ -1,34 +1,44 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon } from 'antd'
import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon, Cascader, notification } from 'antd'
import { formRule } from '@/utils/option.js'
import options from '@/store/options.js'
import Api from '@/api'
import './index.scss'
class MainSearch extends Component {
  static propTpyes = {
    dict: PropTypes.object,     // 字典项
    MenuID: PropTypes.any,
    formlist: PropTypes.any,
    card: PropTypes.any,
    inputSubmit: PropTypes.any  // 回车提交事件
  }
  state = {
    formlist: null
    formlist: null,
    menulist: null
  }
  UNSAFE_componentWillMount () {
    let _type = this.props.formlist.filter(form => form.key === 'type')[0].initVal
    let _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'fieldlength', 'blacklist']
    let _menulist = this.props.formlist.filter(form => form.key === 'linkmenu')[0] || ''
    let _options = null
    if (_type === 'text') {
      _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'matchVal', 'color', 'fieldlength', 'blacklist']
      _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'matchVal', 'color', 'fieldlength', 'blacklist', 'linkmenu']
    } else if (_type === 'number') {
      _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'match', 'matchVal', 'color', 'blacklist']
      _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'match', 'matchVal', 'color', 'blacklist', 'linkmenu']
    } else if (_type === 'textarea') {
      _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'matchVal', 'color', 'fieldlength', 'blacklist']
    } else if (_type === 'picture') {
      _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'fieldlength', 'blacklist', 'scale']
    }
    this.setState({
      menulist: _menulist.options || [],
      formlist: this.props.formlist.map(item => {
        item.hidden = !_options.includes(item.key)
        if (item.key === 'matchVal' && (_type === 'text' || _type === 'textarea')) {
@@ -56,14 +66,16 @@
  typeChange = (key, value) => {
    if (key === 'type') {
      let _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'fieldlength', 'blacklist']
      let _options = null
      if (value === 'text') {
        _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'matchVal', 'color', 'fieldlength', 'blacklist']
        _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'matchVal', 'color', 'fieldlength', 'blacklist', 'linkmenu']
      } else if (value === 'number') {
        _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'match', 'matchVal', 'color', 'blacklist']
        _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'match', 'matchVal', 'color', 'blacklist', 'linkmenu']
      } else if (value === 'textarea') {
        _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'matchVal', 'color', 'fieldlength', 'blacklist']
      } else if (value === 'picture') {
        _options = ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'fieldlength', 'blacklist', 'scale']
      }
      this.setState({
@@ -242,18 +254,107 @@
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'cascader') { // 多选
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.key, {
                initialValue: item.initVal || []
              })(
                <Cascader
                  options={this.state.menulist}
                  loadData={this.loadData}
                  placeholder=""
                  getPopupContainer={() => document.getElementById('columnwinter')}
                />
              )}
            </Form.Item>
          </Col>
        )
      }
    })
    return fields
  }
  loadData = selectedOptions => {
    const { MenuID } = this.props
    const targetOption = selectedOptions[selectedOptions.length - 1]
    targetOption.loading = true
    let _param = {
      func: 'sPC_Get_FunMenu',
      ParentID: targetOption.value,
      systemType: options.systemType,
      debug: 'Y'
    }
    Api.getSystemConfig(_param).then(result => {
      if (result.status) {
        targetOption.loading = false
        targetOption.children = result.data.map(item => {
          let submenu = {
            value: item.ParentID,
            label: item.MenuNameP,
            children: item.FunMenu.map(cell => {
              return {
                value: cell.MenuID,
                label: cell.MenuName,
                MenuID: cell.MenuID,
                MenuName: cell.MenuName,
                MenuNo: cell.MenuNo,
                Ot: cell.Ot,
                PageParam: cell.PageParam,
                LinkUrl: cell.LinkUrl
              }
            })
          }
          submenu.children = submenu.children.filter(cell => cell.MenuID !== MenuID)
          return submenu
        })
        this.setState({
          menulist: [...this.state.menulist]
        })
      } else {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 10
        })
        targetOption.loading = false
      }
    })
  }
  handleConfirm = () => {
    const { menulist } = this.state
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          values.id = this.props.card.id
          values.uuid = this.props.card.uuid
          if ((values.type === 'text' || values.type === 'number') && values.linkmenu && values.linkmenu.length > 0) {
            let linkThdMenu = ''
            menulist.forEach(menu => {
              if (menu.value === values.linkmenu[0]) {
                menu.children.forEach(item => {
                  if (item.value === values.linkmenu[1]) {
                    item.children.forEach(cell => {
                      if (cell.value === values.linkmenu[2]) {
                        linkThdMenu = cell
                      }
                    })
                  }
                })
              }
            })
            values.linkThdMenu = linkThdMenu
          }
          resolve(values)
        } else {
          reject(err)
@@ -274,7 +375,7 @@
      }
    }
    return (
      <Form {...formItemLayout} className="ant-advanced-search-form commontable-column-form" id="columnwinter">
      <Form {...formItemLayout} className="commontable-column-form" id="columnwinter">
        <Row gutter={24}>{this.getFields()}</Row>
      </Form>
    )