king
2019-11-23 9f9d68cf40f1d7470bfb49220266b26663cbb722
src/templates/comtableconfig/searchform/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Select, Icon, Radio, notification } from 'antd'
import moment from 'moment'
// import moment from 'moment'
import EditTable from '../editable'
import './index.scss'
@@ -17,7 +17,13 @@
  state = {
    openType: null,
    resourceType: null,
    formlist: null
    formlist: null,
    dateoptions: {
      date: [{value: '', text: '空'}, {value: '0', text: '当天'}, {value: 1, text: '前一天'}, {value: 3, text: '前三天'}, {value: 7, text: '前七天'}, {value: 30, text: '前30天'}],
      dateweek: [{value: '', text: '空'}, {value: '0', text: '本周'}, {value: 1, text: '上周'}, {value: 3, text: '前三周'}, {value: 7, text: '前七周'}],
      datemonth: [{value: '', text: '空'}, {value: '0', text: '本月'}, {value: 1, text: '上月'}, {value: 3, text: '前三月'}, {value: 7, text: '前七月'}],
      dateyear: [{value: '', text: '空'}, {value: '0', text: '当年'}, {value: 1, text: '去年'}, {value: 3, text: '前年'}],
    }
  }
  openTypeChange = (key, value) => {
@@ -37,7 +43,26 @@
        openType: value,
        formlist: this.state.formlist.map(form => {
          form.hidden = !_options.includes(form.key)
          if (form.key === 'initval') {
            if (this.state.dateoptions.hasOwnProperty(value)) {
              form.options = this.state.dateoptions[value]
              form.type = 'select'
            } else {
              form.type = 'text'
            }
            form.initVal = ''
            form.hidden = true
          }
          return form
        })
      }, () => {
        this.setState({
          formlist: this.state.formlist.map(form => {
            if (form.key === 'initval') {
              form.hidden = false
            }
            return form
          })
        })
      })
    }
@@ -74,12 +99,6 @@
      if (item.hidden) return
      if (item.type === 'text') { // 文本搜索
        let placeholder = ''
        if (item.key === 'initval' && this.state.openType === 'date') {
          placeholder = '例:' + moment().format('YYYY-MM-DD')
        } else if (item.key === 'initval' && this.state.openType === 'datetime') {
          placeholder = '例:' + moment().format('YYYY-MM-DD HH:mm:ss')
        }
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.label}>
@@ -91,7 +110,7 @@
                    message: this.props.dict['form.required.input'] + item.label + '!'
                  }
                ]
              })(<Input placeholder={placeholder} autoComplete="off" disabled={item.readonly} />)}
              })(<Input placeholder="" autoComplete="off" disabled={item.readonly} />)}
            </Form.Item>
          </Col>
        )
@@ -115,7 +134,7 @@
                  getPopupContainer={() => document.getElementById('commontable-search-form-box')}
                >
                  {item.options.map(option =>
                    <Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}>
                    <Select.Option id={option.value} title={option.text} key={option.value} value={option.value}>
                      {item.key === 'icon' && <Icon type={option.text} />} {option.text}
                    </Select.Option>
                  )}
@@ -141,7 +160,7 @@
                  {
                    item.options.map(option => {
                      return (
                        <Radio key={option.MenuID} value={option.MenuID}>{option.text}</Radio>
                        <Radio key={option.value} value={option.value}>{option.text}</Radio>
                      )
                    })
                  }
@@ -175,6 +194,7 @@
        )
      }
    })
    return fields
  }
@@ -241,6 +261,10 @@
      openType: type,
      resourceType: resourceType,
      formlist: formlist.map(form => {
        if (this.state.dateoptions.hasOwnProperty(type) && form.key === 'initval') {
          form.options = this.state.dateoptions[type]
          form.type = 'select'
        }
        form.hidden = !_options.includes(form.key)
        return form
      })