king
2021-06-27 69cd43786253e299f6856a200554ae7fc0621877
src/tabviews/zshare/topSearch/index.jsx
@@ -1,12 +1,11 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Row, Col, Input, Button, Select, DatePicker, notification, Modal, Icon } from 'antd'
import { Form, Row, Col, Input, Button, notification, Modal, Icon } from 'antd'
import moment from 'moment'
import Api from '@/api'
import options from '@/store/options.js'
import DateGroup from '@/tabviews/zshare/dategroup'
import asyncComponent from '@/utils/asyncComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import Utils from '@/utils/utils.js'
@@ -14,11 +13,13 @@
import enUS from '@/locales/en-US/main.js'
import './index.scss'
const { MonthPicker, WeekPicker, RangePicker } = DatePicker
const { Search } = Input
const MutilForm = asyncSpinComponent(() => import('./advanceform'))
const CheckCard = asyncComponent(() => import('@/tabviews/zshare/mutilform/checkCard'))
const MKCheckCard = asyncComponent(() => import('@/tabviews/zshare/mutilform/checkCard'))
const MKSelect = asyncComponent(() => import('./mkSelect'))
const DateGroup = asyncComponent(() => import('./dategroup'))
const MKDatePicker = asyncComponent(() => import('./mkDatePicker'))
class MainSearch extends Component {
  static propTpyes = {
@@ -32,25 +33,24 @@
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    oriId: Utils.getuuid(),  // 搜索表单Id
    formId: '',              // 搜索表单Id
    searchlist: null,        // 搜索项
    reset: true,             // 控制组合搜索项重置
    float: '',               // 浮动
    showButton: true,        // 是否显示搜索按钮
    showAdvanced: false,     // 是否显示高级搜索
    searchStyle: null,       // 搜索条件样式
    searchValues: {},        // 搜索条件保存值
    advanceValues: [],       // 高级搜索条件保存值
    visible: false,
    adModelWidth: '1000px',
    hasReqFields: false
  }
  record = {}
  UNSAFE_componentWillMount () {
    const { config, menuType, searchlist, setting } = this.props
    let _searchlist = []
    let _list = []
    let fieldMap = new Map()
    let mainItems = []  // 云端或单点数据
    let localItems = [] // 本地数据
@@ -58,11 +58,12 @@
    let float = ''
    let showButton = true
    let searchStyle = null
    let searchValues = {}
    let advanceValues = []
    let showAdvanced = false
    let adModelWidth = 1000
    let formId = Utils.getuuid()
    let linkFields = {}
    let record = {}
    let hasReqFields = false
    if (setting && setting.advanceWidth) {
      adModelWidth = setting.advanceWidth
@@ -85,21 +86,44 @@
        showButton = config.wrap.show !== 'false'
        searchStyle = config.style
      } else {
        formId = ''
        showButton = false
        float = 'right'
      }
    }
    _searchlist.forEach(item => {
      if (item.type === 'link') {
        linkFields[item.linkField] = linkFields[item.linkField] || []
        linkFields[item.linkField].push({field: item.field, uuid: item.uuid})
      }
      if (fieldMap.has(item.field)) {
        item.field = item.field + '@tail@'
      }
      fieldMap.set(item.field, item)
      item.required = item.required === 'true'
      if (item.required) {
        hasReqFields = true
      }
      if (showButton && item.advanced) {
        showAdvanced = true
      } else {
        item.advanced = false
      }
      if (item.advanced && item.initval) {
        advanceValues.push({field: item.field, type: item.type, label: item.label, value: item.initval})
      }
      if (item.type === 'group') {
        record[item.field] = item.initType
        record[item.datefield] = item.initval
      } else {
        record[item.field] = item.initval
      }
      if (['select', 'link', 'multiselect', 'checkcard'].includes(item.type)) {
        item.options = item.options || []
        if (item.setAll === 'true' && ['select', 'link'].includes(item.type)) {
          item.options.unshift({
            key: Utils.getuuid(),
@@ -134,24 +158,16 @@
        item.oriOptions = fromJS(item.options).toJS()
      }
      _list.push(item)
      fieldMap.set(item.field, item)
    })
    _list = _list.map(item => {
      if (item.Hide === 'true') {
        searchValues[item.field] = this.getInitValue(item)
      } else if (showButton && item.advanced === 'true') {
        showAdvanced = true
        let _value = this.getInitValue(item)
        searchValues[item.field] = _value
    this.record = record
        let _val = this.getAdvanceValue(item, _value)
        if (_val) {
          advanceValues.push({field: item.field, type: item.type, label: item.label, value: _val})
        }
      } else if (item.type === 'group') {
        searchValues[item.datefield] = this.getInitValue(item)
        searchValues[item.field] = item.initval && item.initval[0] ? item.initval[0] : ''
    let _list = _searchlist.map(item => {
      if (item.hidden) return item
      if (linkFields[item.field] && (item.type === 'select' || item.type === 'link')) {
        item.linkFields = linkFields[item.field]
      }
      if (item.type === 'link') {
@@ -163,7 +179,7 @@
            message: '未查询到搜索条件《' + item.label + '》关联字段!',
            duration: 5
          })
          item.supInitVal = ''
          item.type = 'select'
        } else {
          item.supInitVal = supItem.initval
          item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval || option.Value === '')
@@ -175,10 +191,9 @@
    this.setState({
      float,
      formId,
      showButton,
      searchStyle,
      searchValues,
      hasReqFields,
      showAdvanced,
      adModelWidth,
      advanceValues,
@@ -190,98 +205,6 @@
        this.improveSearch(mainItems, localItems)
      }
    })
  }
  getInitValue = (item) => {
    let value = item.initval || ''
    if (item.type === 'multiselect') { // 下拉多选
      value = item.initval ? item.initval.split(',').filter(Boolean) : []
    } else if (item.type === 'date') { // 时间搜索
      value = item.initval ? moment().subtract(item.initval, 'days') : ''
    } else if (item.type === 'datemonth') {
      value = item.initval ? moment().subtract(item.initval, 'month') : ''
    } else if (item.type === 'dateweek') {
      value = item.initval ? moment().subtract(item.initval * 7, 'days') : ''
    } else if (item.type === 'daterange') {
      if (item.initval) {
        try {
          let _initval = JSON.parse(item.initval)
          value = [moment().subtract(_initval[0], 'days'), moment().subtract(_initval[1], 'days')]
        } catch {
          value = ''
        }
      }
    } else if (item.type === 'group' && item.initval && item.initval.length > 0) {
      let _type = item.initval[0]
      let _val = item.initval[1]
      if (_type === 'day') {
        value = [moment().subtract(_val, 'days').format('YYYY-MM-DD'), moment().subtract(_val, 'days').format('YYYY-MM-DD')]
      } else if (_type === 'week') {
        value = [moment().subtract(_val * 7, 'days').startOf('week').format('YYYY-MM-DD'), moment().subtract(_val * 7, 'days').endOf('week').format('YYYY-MM-DD')]
      } else if (_type === 'month') {
        value = [moment().subtract(_val, 'month').startOf('month').format('YYYY-MM-DD'), moment().subtract(_val, 'month').endOf('month').format('YYYY-MM-DD')]
      } else if (_type === 'quarter') {
        let _differ = parseInt(moment().format('MM')) % 3
        let _pdiffer = 0
        let _ndiffer = 0
        // 差值计算
        switch(_differ) {
          case 0:
            _pdiffer = 2
            _ndiffer = 0
            break
          case 1:
            _pdiffer = 0
            _ndiffer = -2
            break
          case 2:
            _pdiffer = 1
            _ndiffer = -1
            break
          default:
        }
        value = [moment().subtract(_pdiffer + _val * 3, 'month').startOf('month').format('YYYY-MM-DD'), moment().subtract(_ndiffer + _val * 3, 'month').endOf('month').format('YYYY-MM-DD')]
      } else if (_type === 'year') {
        let _year = parseInt(moment().format('YYYY')) - _val
        value = [_year + '-01-01', _year + '-12-31']
      } else if (_type === 'customized') {
        try {
          _val = JSON.parse(_val)
        } catch {
          _val = [0, 0]
        }
        value = [moment().subtract(_val[0], 'days').format('YYYY-MM-DD'), moment().subtract(_val[1], 'days').format('YYYY-MM-DD')]
      }
    }
    return value
  }
  getAdvanceValue = (item, value) => {
    if (!value || (Array.isArray(value) && value.length === 0)) return ''
    let val = ''
    if (item.type === 'multiselect') {
      val = value.join(', ')
    } else if (item.type === 'daterange') {
      if (value[0] && value[1]) {
        val = `${moment(value[0]).format('YYYY-MM-DD')} ~ ${moment(value[1]).format('YYYY-MM-DD')}`
      }
    } else if (item.type === 'dateweek') {
      val = `${moment(value).startOf('week').format('YYYY-MM-DD')} ~ ${moment(value).endOf('week').format('YYYY-MM-DD')}`
    } else if (item.type === 'date') {
      val = moment(value).format('YYYY-MM-DD')
    } else if (item.type === 'datemonth') {
      val = moment(value).format('YYYY-MM')
    } else {
      val = value.replace(/(^\s*|\s*$)/ig, '')
    }
    return val
  }
  // 查询下拉菜单
@@ -389,51 +312,6 @@
    })
  }
  resetSearch = (result) => {
    let _searchlist = this.state.searchlist.map(item => {
      if (['select', 'link', 'multiselect', 'checkcard'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
        let options = result[item.field].map(cell => {
          let _item = {
            key: Utils.getuuid()
          }
          if (item.type !== 'checkcard') {
            _item.Value = cell[item.valueField]
            _item.Text = cell[item.valueText]
          } else {
            _item.$value = cell[item.cardValField]
            _item = {..._item, ...cell}
          }
          if (item.type === 'link') {
            _item.ParentID = cell[item.linkField]
          }
          return _item
        })
        item.oriOptions = [...item.oriOptions, ...options]
      }
      return item
    })
    this.setState({
      searchlist: _searchlist.map(item => {
        if (item.type === 'link') {
          if (item.supInitVal) {
            item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.Value === '')
          } else {
            item.options = item.oriOptions
          }
        } else if (item.type === 'select' || item.type === 'multiselect' || item.type === 'checkcard') {
          item.options = item.oriOptions
        }
        return item
      })
    })
  }
  // 测试系统单个请求下拉选项
  improveSimpleSearch = (deForms) => {
    if (deForms.length === 0) return
@@ -485,264 +363,115 @@
    })
  }
  resetform = (formlist, supfields, index, fieldsvalue) => {
    index++
    let subfields = []
    supfields.forEach(supfield => {
      formlist = formlist.map(item => {
        if (item.type === 'link' && item.linkField === supfield.field) {
          item.options = item.oriOptions.filter(option => option.ParentID === supfield.initval || option.Value === '')
          item.initval = item.options[0] ? item.options[0].Value : ''
          if (this.props.form.getFieldValue(item.field) !== undefined) {
            fieldsvalue[item.field] = item.initval
  resetSearch = (result) => {
    let _searchlist = this.state.searchlist.map(item => {
      if (['select', 'link', 'multiselect', 'checkcard'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
        let options = result[item.field].map(cell => {
          let _item = {
            key: Utils.getuuid()
          }
  
          subfields.push(item)
        }
        return item
      })
    })
    if (subfields.length === 0 || index > 6) {
      return formlist
          if (item.type !== 'checkcard') {
            _item.Value = cell[item.valueField]
            _item.Text = cell[item.valueText]
    } else {
      return this.resetform(formlist, subfields, index, fieldsvalue)
    }
            _item.$value = cell[item.cardValField]
            _item = {..._item, ...cell}
  }
  selectChange = (_field, value) => {
    let formlist = fromJS(this.state.searchlist).toJS()
    let subfields = []
    let fieldsvalue = {}
    formlist = formlist.map(item => {
      if (item.type === 'link' && item.linkField === _field.field) {
        item.options = item.oriOptions.filter(option => option.ParentID === value || option.Value === '')
        item.initval = item.options[0] ? item.options[0].Value : ''
        if (this.props.form.getFieldValue(item.field) !== undefined) {
          fieldsvalue[item.field] = item.initval
          if (item.type === 'link') {
            _item.ParentID = cell[item.linkField]
        }
        subfields.push(item)
          return _item
        })
        item.oriOptions = [...item.oriOptions, ...options]
      }
      return item
    })
    if (subfields.length === 0) {
      this.searchChange()
      return
    }
    formlist = this.resetform(formlist, subfields, 0, fieldsvalue)
    if (Object.keys(fieldsvalue).length > 0) {
      this.props.form.setFieldsValue(fieldsvalue)
    }
    this.setState({
      searchlist: formlist
    }, () => {
      this.searchChange()
      searchlist: _searchlist.map(item => {
        if (item.type === 'link') {
          if (item.supInitVal) {
            item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.Value === '')
          } else {
            item.options = item.oriOptions
          }
        } else if (item.type === 'select' || item.type === 'multiselect' || item.type === 'checkcard') {
          item.options = item.oriOptions
        }
        return item
    })
    })
  }
  recordChange = (val, defer, item) => {
    this.record[item.field] = val
    if (defer) return
    if (item.linkFields) {
      setTimeout(() => {
        this.handleSubmit()
      }, 1000)
    } else {
      this.handleSubmit()
    }
  }
  dateGroupChange = (val, type, item) => {
    this.record[item.datefield] = val
    this.record[item.field] = type
    this.handleSubmit()
  }
  getFields() {
    const { getFieldDecorator } = this.props.form
    const { dict, showButton, formId, showAdvanced, float } = this.state
    const { dict, showButton, showAdvanced, float } = this.state
    const fields = []
    this.state.searchlist.forEach((item, index) => {
      if (item.Hide === 'true' || (showAdvanced && item.advanced === 'true')) return
      if (item.hidden || item.advanced) return
      
      if (item.type === 'text') { // 文本搜索
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval,
                rules: [
      const _rules = [
                  {
                    required: item.required,
                    message: dict['form.required.input'] + item.label + '!'
          message: item.label + '不可为空!'
                  }
                ]
              })(item.inputType === 'search' ?
                <Search placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onSearch={this.handleSearch} enterButton/> :
                <Input placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onPressEnter={this.handleSearch} />)}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'select' || item.type === 'link') { // 下拉搜索
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval,
                rules: [
                  {
                    required: item.required,
                    message: dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <Select
                  showSearch
                  onChange={(value) => {this.selectChange(item, value)}}
                  filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 || option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                  getPopupContainer={() => formId ? document.getElementById(formId) : document.body}
                >
                  {item.options.map((option, i) =>
                    <Select.Option id={`${i}`} title={option.Text} key={`${i}`} value={option.Value}>{option.Text}</Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'multiselect') { // 下拉多选
        let _initval = item.initval ? item.initval.split(',').filter(Boolean) : []
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
                initialValue: _initval,
                rules: [
                  {
                    required: item.required,
                    message: dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <Select
                  showSearch
                  mode="multiple"
                  onChange={this.searchChange}
                  filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                  getPopupContainer={() => formId ? document.getElementById(formId) : document.body}
                >
                  {item.options.map((option, i) =>
                    <Select.Option id={`${i}`} title={option.Text} key={`${i}`} value={option.Value}>{option.Text}</Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'date') { // 时间搜索
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval ? moment().subtract(item.initval, 'days') : null,
                rules: [
                  {
                    required: item.required,
                    message: dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <DatePicker onChange={this.searchChange} getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'datemonth') {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval ? moment().subtract(item.initval, 'month') : null,
                rules: [
                  {
                    required: item.required,
                    message: dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <MonthPicker onChange={this.searchChange} getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'dateweek') {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null,
                rules: [
                  {
                    required: item.required,
                    message: dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <WeekPicker onChange={this.searchChange} getCalendarContainer={() => formId ? document.getElementById(formId) : document.body} />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'daterange') {
        let _defaultValue = [null, null]
        if (item.initval) {
          try {
            let _initval = JSON.parse(item.initval)
            _defaultValue = [moment().subtract(_initval[0], 'days'), moment().subtract(_initval[1], 'days')]
          } catch {
            _defaultValue = [null, null]
          }
        }
      let content = null
      let field = item.field
        fields.push(
          <Col className="daterange" span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field,
                {
                  initialValue: _defaultValue,
                  rules: [
                    {
                      required: item.required,
                      message: dict['form.required.select'] + item.label + '!'
      if (item.type === 'text') {
        if (item.inputType === 'search') {
          content = <Search placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onSearch={this.handleSubmit} enterButton/>
        } else {
          content = <Input placeholder={item.labelShow === 'false' ? item.label : ''} autoComplete="off" onPressEnter={this.handleSubmit} />
                    }
                  ]
                })(
                <RangePicker
                  placeholder={['开始日期', '结束日期']}
                  renderExtraFooter={() => 'extra footer'}
                  onChange={this.searchChange}
                  getCalendarContainer={() => formId ? document.getElementById(formId) : document.body}
                />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') {
        content = (<MKSelect config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />)
      } else if (item.type === 'date' || item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') {
        content = (<MKDatePicker config={item} onChange={(val) => this.recordChange(val, false, item)} />)
      } else if (item.type === 'group') {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''} className={item.required ? 'group-required' : ''}>
              <DateGroup reset={this.state.reset} position={index} card={item} onGroupChange={this.onGroupChange} />
            </Form.Item>
          </Col>
        )
        field = item.datefield
        content = <DateGroup position={index} config={item} onChange={(val, type) => this.dateGroupChange(val, type, item)} />
      } else if (item.type === 'checkcard') {
        content = <MKCheckCard card={item} onChange={this.handleSubmit} />
      }
      if (content) {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(item.field, {
              {getFieldDecorator(field, {
                initialValue: item.initval,
                rules: [
                  {
                    required: item.required,
                    message: dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <CheckCard card={item} onChange={this.searchChange} />
              )}
                rules: _rules
              })(content)}
            </Form.Item>
          </Col>
        )
@@ -753,7 +482,7 @@
      let action = (
        <Col span={6} style={{ whiteSpace: 'nowrap' }} className="search-button" key="actions">
          <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}>
            <Button type="primary" onClick={this.handleSearch}>
            <Button type="primary" onClick={this.handleSubmit}>
              {dict['main.search']}
            </Button>
            <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
@@ -779,12 +508,14 @@
    this.setState({visible: true})
  }
  handleSearch = () => {
    // 回车或点击搜索
  handleSubmit = () => {
    this.setState({}, () => {
    this.props.form.validateFields((err, values) => {
      if (!err) {
        if (err) return
        let searches = this.getFieldsValues(values)
        if (this.state.hasReqFields) {
        let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
        if (requireFields.length > 0) {
          let labels = requireFields.map(item => item.label)
@@ -797,34 +528,9 @@
          })
          return
        }
        this.props.refreshdata(searches)
      }
    })
  }
  onGroupChange = (values) => {
    const { searchValues } = this.state
    this.setState({
      searchValues: {...searchValues, ...values}
    })
    this.searchChange()
  }
  searchChange = () => {
    this.setState({}, () => {
      this.props.form.validateFields((err, values) => {
        if (!err) {
          let searches = this.getFieldsValues(values)
          let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
          if (requireFields.length > 0) {
            return
          }
          this.props.refreshdata(searches)
        }
      })
    })
  }
@@ -833,161 +539,109 @@
   * @description 搜索条件重置
   */
  handleReset = () => {
    const { showAdvanced } = this.state
    let searchValues = {}
    let record = {}
    let advanceValues = []
    let searchlist = this.state.searchlist.map(item => {
      item.initval = item.oriInitval
      
      if (item.Hide === 'true') {
        searchValues[item.field] = this.getInitValue(item)
      } else if (showAdvanced && item.advanced === 'true') {
        let _value = this.getInitValue(item)
        searchValues[item.field] = _value
      if (item.type === 'group') {
        record[item.datefield] = item.initval
        record[item.field] = item.initType
      } else {
        record[item.field] = item.initval
      }
      if (item.advanced && item.initval) {
        advanceValues.push({field: item.field, type: item.type, label: item.label, value: item.initval})
      }
        let _val = this.getAdvanceValue(item, _value)
        if (_val) {
          advanceValues.push({field: item.field, type: item.type, label: item.label, value: _val})
        }
      } else if (item.type === 'group') {
        searchValues[item.datefield] = this.getInitValue(item)
        searchValues[item.field] = item.initval && item.initval[0] ? item.initval[0] : ''
      }
      return item
    })
    this.setState({searchlist, searchValues, advanceValues, reset: !this.state.reset}, () => {
      this.props.form.resetFields()
      this.props.form.validateFields((err, values) => {
        if (!err) {
          let searches = this.getFieldsValues(values)
    this.record = record
          let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
          if (requireFields.length > 0) {
            let labels = requireFields.map(item => item.label)
            labels = Array.from(new Set(labels))
            notification.warning({
              top: 92,
              message: this.state.dict['form.required.input'] + labels.join('、') + ' !',
              duration: 3
            })
            return
          }
          this.props.refreshdata(searches)
        }
    this.setState({searchlist: [], advanceValues}, () => {
      this.setState({searchlist}, () => {
        this.handleSubmit()
      })
    })
  }
  getFieldsValues = (values) => {
    const { searchValues, searchlist } = this.state
  getFieldsValues = (vals) => {
    const { searchlist } = this.state
    let values = {...this.record, ...vals}
    this.record = values
    // 获取搜索条件值
    let search = []
    searchlist.forEach(item => {
      let cell = {
        type: item.type,
        key: item.field.replace(/@tail@$/, ''),
        label: item.label,
        match: item.match || '=',
        required: item.required,
        value: ''
      }
      if ((item.Hide === 'true' || item.advanced === 'true')) {
        cell.value = searchValues[item.field] || ''
      }
      if (item.type === 'group') {
        cell.type = 'daterange'
        cell.key = item.datefield
        cell.value = searchValues[item.datefield] || ''
        cell.match = 'between'
        search.push(cell)
        let copy = fromJS(cell).toJS()
        copy.type = 'group'
        copy.key = item.field.replace(/@tail@$/, '')
        copy.value = searchValues[item.field] || ''
        copy.match = '='
        copy.forbid = true
        search.push(copy)
        search.push({
          type: 'daterange',
          key: item.datefield,
          value: values[item.datefield] || '',
          label: item.label,
          match: 'between',
          required: item.required
        }, {
          type: 'group',
          key: item.field,
          value: values[item.field] || '',
          label: item.label,
          match: '=',
          forbid: true,
          required: item.required
        })
      } else {
        let _value = values[item.field] || cell.value || ''
        if (!_value) {
          if (item.type === 'multiselect') {
            cell.value = []
        let type = item.type
        if (type === 'multiselect' || (type === 'checkcard' && item.multiple === 'true')) {
          type = 'multi'
          }
          search.push(cell)
        } else {
          if (item.type === 'daterange') {
            if (_value[0] && _value[1]) {
              _value = [moment(_value[0]).format('YYYY-MM-DD'), moment(_value[1]).format('YYYY-MM-DD')]
            } else {
              _value = ''
            }
          } else if (item.type === 'dateweek') {
            _value = [moment(_value).startOf('week').format('YYYY-MM-DD'), moment(_value).endOf('week').format('YYYY-MM-DD')]
          } else if (item.type === 'date') {
            _value = moment(_value).format('YYYY-MM-DD')
          } else if (item.type === 'datemonth') {
            _value = moment(_value).format('YYYY-MM')
          } else if (item.type === 'multiselect') {
        let val = values[item.field] !== undefined ? values[item.field] : ''
    
          } else {
            _value = _value.replace(/(^\s*|\s*$)/ig, '')
        if (typeof(val) === 'string') {
          val = val.replace(/(^\s*|\s*$)/ig, '')
          }
          cell.value = _value
          search.push(cell)
        }
        search.push({
          type: type,
          key: item.field.replace(/@tail@$/, ''),
          value: val,
          label: item.label,
          match: item.match,
          required: item.required
        })
      }
    })
    return search
  }
  handleOk = () => {
    const { searchValues, searchlist } = this.state
  handleOk = (values) => {
    this.record = {...this.record, ...values}
    this.formRef.handleConfirm().then(res => {
      let values = {}
      let advanceValues = []
      searchlist.forEach(item => {
        if (item.advanced === 'true' && item.Hide !== 'true') {
          let _value = res[item.field] || ''
    this.state.searchlist.forEach(item => {
      if (!item.advanced) return
          
          if (!_value && item.type === 'multiselect') {
            _value = []
          } else if (typeof(_value) === 'string') {
            _value = _value.replace(/(^\s*|\s*$)/ig, '')
      let val = this.record[item.field]
      if (val || val === 0) {
        advanceValues.push({field: item.field, type: item.type, label: item.label, value: val})
          }
          values[item.field] = _value
    })
          let _val = this.getAdvanceValue(item, _value)
          if (_val) {
            advanceValues.push({field: item.field, type: item.type, label: item.label, value: _val})
          }
        }
      })
      this.setState({searchValues: {...searchValues, ...values}, advanceValues, visible: false}, () => {
        this.handleSearch()
      })
    })
    this.setState({advanceValues, visible: false})
    this.handleSubmit()
  }
  closeAdvanceForm = (cell) => {
    const { searchValues, advanceValues } = this.state
    this.record[cell.field] = ''
    this.setState({searchValues: {...searchValues, [cell.field]: ''}, advanceValues: advanceValues.filter(item => item.field !== cell.field)}, () => {
      this.handleSearch()
    })
    this.setState({advanceValues: this.state.advanceValues.filter(item => item.field !== cell.field)})
    this.handleSubmit()
  }
  render() {
    const { float, searchStyle, visible, searchlist, searchValues, showAdvanced, advanceValues, adModelWidth } = this.state
    const { float, searchStyle, visible, searchlist, showAdvanced, advanceValues, adModelWidth } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -1001,7 +655,7 @@
    return (
      <>
        <Form {...formItemLayout} className={`top-search ${float}`} style={searchStyle} id={this.state.formId || this.state.oriId}>
        <Form {...formItemLayout} className={`top-search ${float}`} style={searchStyle}>
          <Row gutter={24}>{this.getFields()}</Row>
          <Row gutter={24}>
            {showAdvanced ? <div className="advanced-list">
@@ -1022,17 +676,14 @@
          visible={visible}
          width={adModelWidth}
          closable={false}
          onOk={this.handleOk}
          cancelText={'关闭'}
          onCancel={() => this.setState({visible: false})}
          footer={null}
          destroyOnClose
        >
          <MutilForm
            dict={this.state.dict}
            searchlist={searchlist}
            searchValues={searchValues}
            handleSearch={this.handleOk}
            wrappedComponentRef={(inst) => this.formRef = inst}
            record={this.record}
            advanceSubmit={this.handleOk}
            handleClose={() => this.setState({visible: false})}
          />
        </Modal>
      </>