king
2021-09-28 342d3498191f1683059fe586209ec920545e0bf9
src/tabviews/zshare/topSearch/index.jsx
@@ -1,65 +1,136 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Row, Col, Input, Button, Select, DatePicker, notification } from 'antd'
import { is, fromJS } from 'immutable'
import { Form, Row, Col, 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'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import MKInput from './mkInput'
import './index.scss'
const {MonthPicker, WeekPicker, RangePicker} = DatePicker
const MutilForm = asyncSpinComponent(() => import('./advanceform'))
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 = {
    BID: PropTypes.any,          // 父级Id,用于查询下拉选择项
    dataManager: PropTypes.any,  // 数据权限
    menuType: PropTypes.any,     // 菜单权限,是否为HS
    searchlist: PropTypes.array, // 搜索条件列表
    dict: PropTypes.object       // 字典项
    config: PropTypes.object,    // 组件配置信息(自定义页面)
    setting: PropTypes.object,   // 组件配置信息(自定义页面)
    refreshdata: PropTypes.func  // 刷新数据
  }
  state = {
    match: null,            // 搜索条件匹配规则
    style: null,            // 搜索条件类型
    label: null,            // 提示文字
    required: null,         // 是否必填
    searchlist: null,       // 搜索项
    groups: null,           // 组合搜索项
    formId: Utils.getuuid() // 搜索表单Id
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    searchlist: null,        // 搜索项
    reset: true,             // 控制组合搜索项重置
    float: '',               // 浮动
    showButton: true,        // 是否显示搜索按钮
    showAdvanced: false,     // 是否显示高级搜索
    searchStyle: null,       // 搜索条件样式
    advanceValues: [],       // 高级搜索条件保存值
    visible: false,
    adModelWidth: '1000px',
    hasReqFields: false
  }
  record = {}
  UNSAFE_componentWillMount () {
    let searchlist = fromJS(this.props.searchlist).toJS()
    let match = {}
    let label = {}
    let style = {}
    let required = {}
    let _list = []
    const { config, menuType, searchlist, setting } = this.props
    let _searchlist = []
    let fieldMap = new Map()
    let mainItems = []  // 云端或单点数据
    let localItems = [] // 本地数据
    let deForms = []    // 测试系统,单个请求
    let float = ''
    let showButton = true
    let searchStyle = null
    let advanceValues = []
    let showAdvanced = false
    let adModelWidth = 1000
    let linkFields = {}
    let record = {}
    let hasReqFields = false
    searchlist.forEach(item => {
    if (setting && setting.advanceWidth) {
      adModelWidth = setting.advanceWidth
    } else if (config && config.wrap && config.wrap.advanceWidth) {
      adModelWidth = config.wrap.advanceWidth
    }
    if (adModelWidth < 100) {
      adModelWidth = adModelWidth + 'vw'
    } else {
      adModelWidth = adModelWidth + 'px'
    }
    if (searchlist) {
      if (setting && setting.show === 'false') {
        showButton = false
      }
      _searchlist = fromJS(searchlist).toJS()
    } else if (config) {
      _searchlist = fromJS(config.search).toJS()
      if (config.type === 'search' && config.subtype === 'mainsearch') {
        float = config.wrap.float
        showButton = config.wrap.show !== 'false'
        searchStyle = config.style
      } else {
        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, true)
      match[item.field] = item.match
      label[item.field] = item.label
      style[item.field] = item.type
      required[item.field] = item.required === 'true'
      if (item.required) {
        hasReqFields = true
      }
      if (['select', 'link', 'multiselect'].includes(item.type)) {
        if (item.setAll === 'true' && item.type !== 'multiselect') {
      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(),
            Value: '',
            Text: this.props.dict['main.all']
            Text: this.state.dict['main.all']
          })
        }
@@ -67,15 +138,8 @@
        if (item.resourceType === '1' && item.dataSource) {
          let _option = Utils.getSelectQueryOptions(item)
          if (this.props.dataManager) { // 数据权限
            _option.sql = _option.sql.replace(/\$@/ig, '/*')
            _option.sql = _option.sql.replace(/@\$/ig, '*/')
          } else {
            _option.sql = _option.sql.replace(/@\$|\$@/ig, '')
          }
          // 测试系统单个请求
          if (this.props.menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
          if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
            deForms.push({
              ...item,
              arr_field: _option.field,
@@ -92,13 +156,20 @@
        item.oriOptions = fromJS(item.options).toJS()
      }
      _list.push(item)
      fieldMap.set(item.field, item)
    })
    let _groups = []
    _list = _list.map(item => {
    this.record = record
    let _list = _searchlist.map(item => {
      if (item.hidden) return item
      if (linkFields[item.field]) {
        item.linkFields = linkFields[item.field]
      }
      if (item.type === 'link') {
        let supItem = _list.filter(form => form.field === item.linkField)[0]
        let supItem = fieldMap.get(item.linkField)
        
        if (!supItem) {
          notification.warning({
@@ -106,32 +177,36 @@
            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)
          item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval || option.Value === '')
        }
      } else if (item.type === 'group' && item.Hide !== 'true') {
        _groups.push(fromJS(item).toJS())
      }
      return item
    })
    this.setState({
      match: match,
      label: label,
      style: style,
      required: required,
      searchlist: _list,
      groups: _groups
      float,
      showButton,
      searchStyle,
      hasReqFields,
      showAdvanced,
      adModelWidth,
      advanceValues,
      searchlist: _list
    }, () => {
      if (this.props.menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
      if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
        this.improveSimpleSearch(deForms)
      } else {
        this.improveSearch(mainItems, localItems)
      }
    })
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  // 查询下拉菜单
@@ -235,42 +310,7 @@
      delete result.message
      delete result.status
      let _searchlist = this.state.searchlist.map(item => {
        if (['select', 'link', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
          let options = result[item.field].map(cell => {
            let _item = {
              key: Utils.getuuid(),
              Value: cell[item.valueField],
              Text: cell[item.valueText]
            }
            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)
            } else {
              item.options = item.oriOptions
            }
          } else if (item.type === 'select' || item.type === 'multiselect') {
            item.options = item.oriOptions
          }
          return item
        })
      })
      this.resetSearch(result)
    })
  }
@@ -321,359 +361,182 @@
      delete result.message
      delete result.status
      let _searchlist = this.state.searchlist.map(item => {
        if (['select', 'link', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
          let options = result[item.field].map(cell => {
            let _item = {
              key: Utils.getuuid(),
              Value: cell[item.valueField],
              Text: cell[item.valueText]
      this.resetSearch(result)
    })
  }
  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].forEach(cell => {
          let _item = {
            key: Utils.getuuid()
          }
          if (item.type !== 'checkcard') {
            _item.Value = cell[item.valueField]
            _item.Text = cell[item.valueText]
            if (!_item.Text && _item.Text !== 0) {
              return
            }
          } 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)
            } else {
              item.options = item.oriOptions
            }
          } else if (item.type === 'select' || item.type === 'multiselect') {
            item.options = item.oriOptions
            _item.ParentID = cell[item.linkField]
          }
          return item
          options.push(_item)
        })
      })
    })
  }
  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)
          item.initval = item.options[0] ? item.options[0].Value : ''
          if (this.props.form.getFieldValue(item.field) !== undefined) {
            fieldsvalue[item.field] = item.initval
          }
          subfields.push(item)
        }
        return item
      })
    })
    if (subfields.length === 0 || index > 6) {
      return formlist
    } else {
      return this.resetform(formlist, subfields, index, fieldsvalue)
    }
  }
  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)
        item.initval = item.options[0] ? item.options[0].Value : ''
        if (this.props.form.getFieldValue(item.field) !== undefined) {
          fieldsvalue[item.field] = item.initval
        }
        subfields.push(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, showAdvanced, float, visible } = this.state
    const fields = []
    let lastRadio = 6
    this.state.searchlist.forEach((item, index) => {
      if (item.Hide === 'true') return
      if (item.type === 'text') { // 文本搜索
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval,
                rules: [
                  {
                    required: item.required === 'true',
                    message: this.props.dict['form.required.input'] + item.label + '!'
                  }
                ]
              })(<Input placeholder="" autoComplete="off" />)}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'select') { // 下拉搜索
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval,
                rules: [
                  {
                    required: item.required === 'true',
                    message: this.props.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}
                  getPopupContainer={() => document.getElementById(this.state.formId)}
                >
                  {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.label}>
              {getFieldDecorator(item.field, {
                initialValue: _initval,
                rules: [
                  {
                    required: item.required === 'true',
                    message: this.props.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={() => document.getElementById(this.state.formId)}
                >
                  {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.label}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval ? moment().subtract(item.initval, 'days') : null,
                rules: [
                  {
                    required: item.required === 'true',
                    message: this.props.dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <DatePicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'datemonth') {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval ? moment().subtract(item.initval, 'month') : null,
                rules: [
                  {
                    required: item.required === 'true',
                    message: this.props.dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <MonthPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'dateweek') {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null,
                rules: [
                  {
                    required: item.required === 'true',
                    message: this.props.dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <WeekPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'daterange') {
        let _defaultValue = [null, null]
      if (item.hidden || item.advanced) return
        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]
          }
      const _rules = [
        {
          required: item.required,
          message: item.label + '不可为空!'
        }
      ]
        fields.push(
          <Col className="daterange" span={item.ratio || 6} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.field,
                {
                  initialValue: _defaultValue,
                  rules: [
                    {
                      required: item.required === 'true',
                      message: this.props.dict['form.required.select'] + item.label + '!'
                    }
                  ]
                })(
                <RangePicker
                  placeholder={['开始日期', '结束日期']}
                  renderExtraFooter={() => 'extra footer'}
                  onChange={this.searchChange}
                  getCalendarContainer={() => document.getElementById(this.state.formId)}
                />
              )}
            </Form.Item>
          </Col>
        )
      let content = null
      let className = ''
      let field = item.field
      lastRadio = item.ratio || 6
      if (item.type === 'text') {
        content = (<MKInput config={item} onInputSubmit={this.handleSubmit} />)
      } 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') {
        field = item.datefield
        content = <DateGroup position={index} config={item} onChange={(val, type) => this.dateGroupChange(val, type, item)} />
      } else if (item.type === 'checkcard') {
        className = 'checkcard'
        content = <MKCheckCard card={item} onChange={this.handleSubmit} />
      }
      if (content) {
        fields.push(
          <Col span={item.ratio || 6} key={index}>
            <Form.Item label={item.label} className={item.required === 'true' ? 'group-required' : ''}>
              <DateGroup ref={item.uuid} position={index} card={item} onGroupChange={this.searchChange} />
            <Form.Item className={className} label={item.labelShow !== 'false' ? item.label : ''}>
              {getFieldDecorator(field, {
                initialValue: item.initval,
                rules: _rules
              })(content)}
            </Form.Item>
          </Col>
        )
      }
    })
    fields.push(
      <Col span={6} style={{ whiteSpace: 'nowrap' }} key="actions">
        <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}>
          <Button type="primary" htmlType="submit">
            {this.props.dict['main.search']}
          </Button>
          <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
            {this.props.dict['main.reset']}
          </Button>
        </Form.Item>
      </Col>
    )
    if (showButton) {
      let action = (
        <Col span={lastRadio < 6 ? 6 : lastRadio} style={{ whiteSpace: 'nowrap' }} className="search-button" key="actions">
          <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}>
            <Button type="primary" onClick={this.handleSubmit}>
              {dict['main.search']}
            </Button>
            <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
              {dict['main.reset']}
            </Button>
            {showAdvanced && !visible ? <Button type="link" onClick={this.handleAdvance}>
              高级
            </Button> : null}
          </Form.Item>
        </Col>
      )
      if (float === 'right') {
        fields.unshift(action)
      } else {
        fields.push(action)
      }
    }
    
    return fields
  }
  addHideFieldValue = (values) => {
    const { searchlist } = this.state
    let hideValue = {}
    searchlist.forEach(item => {
      if (item.Hide === 'true') {
        let value = ''
        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') {
          value = item.initval
        }
        hideValue[item.field] = value
      }
    })
    return {...hideValue, ...values}
  handleAdvance = () => {
    this.setState({visible: true})
  }
  handleSearch = (e) => {
    // 回车或点击搜索
    e.preventDefault()
    this.props.form.validateFields((err, values) => {
      if (!err) {
        values = this.addHideFieldValue(values)
        let searches = this.getFieldsValues(values)
        this.props.refreshdata(searches)
      }
    })
  }
  searchChange = () => {
  handleSubmit = () => {
    this.setState({}, () => {
      this.props.form.validateFields((err, values) => {
        if (!err) {
          values = this.addHideFieldValue(values)
          let searches = this.getFieldsValues(values)
          this.props.refreshdata(searches)
        if (err) return
        let searches = this.getFieldsValues(values)
        if (this.state.hasReqFields) {
          let requireFields = searches.filter(item => item.required && item.value === '')
          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)
      })
    })
  }
@@ -682,86 +545,109 @@
   * @description 搜索条件重置
   */
  handleReset = () => {
    const { groups } = this.state
    if (groups.length > 0) {
      groups.forEach(item => {
        this.refs[item.uuid].reset()
      })
    }
    let record = {}
    let advanceValues = []
    let searchlist = this.state.searchlist.map(item => {
      item.initval = item.oriInitval
      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})
      }
      return item
    })
    this.setState({searchlist}, () => {
      this.props.form.resetFields()
      this.props.form.validateFields((err, values) => {
        if (!err) {
          // 异步获取更新后的时间组
          this.setState({}, () => {
            values = this.addHideFieldValue(values)
            let searches = this.getFieldsValues(values)
            this.props.refreshdata(searches)
          })
        }
    this.record = record
    this.setState({searchlist: [], advanceValues}, () => {
      this.setState({searchlist}, () => {
        this.handleSubmit()
      })
    })
  }
  getFieldsValues = (values) => {
    const { groups } = this.state
  getFieldsValues = (vals) => {
    const { searchlist } = this.state
    let values = {...this.record, ...vals}
    this.record = values
    // 获取搜索条件值
    let search = []
    Object.keys(values).forEach(key => {
      let _value = ''
      if (this.state.style[key] === 'daterange') {
        if (values[key].length > 0 && values[key][0] && values[key][1]) {
          _value = [moment(values[key][0]).format('YYYY-MM-DD'), moment(values[key][1]).format('YYYY-MM-DD')]
        }
      } else if (this.state.style[key] === 'dateweek') {
        if (values[key]) {
          _value = [moment(values[key]).startOf('week').format('YYYY-MM-DD'), moment(values[key]).endOf('week').format('YYYY-MM-DD')]
        }
      } else if (this.state.style[key] === 'date') {
        if (values[key]) {
          _value = moment(values[key]).format('YYYY-MM-DD')
        }
      } else if (this.state.style[key] === 'datemonth') {
        if (values[key]) {
          _value = moment(values[key]).format('YYYY-MM')
        }
      } else if (this.state.style[key] === 'multiselect') {
        _value = values[key] || []
    searchlist.forEach(item => {
      if (item.type === 'group') {
        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 {
        _value = (values[key] || values[key] === 0) ? values[key] : ''
        let type = item.type
        if (type === 'multiselect' || (type === 'checkcard' && item.multiple === 'true')) {
          type = 'multi'
        }
        let val = values[item.field] !== undefined ? values[item.field] : ''
        _value = _value.replace(/(^\s*|\s*$)/ig, '')
        if (typeof(val) === 'string') {
          val = val.replace(/(^\s*|\s*$)/ig, '')
        }
        search.push({
          type: type,
          key: item.field.replace(/@tail@$/, ''),
          value: val,
          label: item.label,
          match: item.match,
          required: item.required
        })
      }
      search.push({
        type: this.state.style[key],
        key: key.replace(/@tail@$/, ''),
        value: _value,
        label: this.state.label[key],
        match: this.state.match[key],
        required: this.state.required[key]
      })
    })
    if (groups.length > 0) {
      groups.forEach(item => {
        let items = this.refs[item.uuid].getSearchItems()
        search.push(...items)
      })
    }
    return search
  }
  handleOk = (values) => {
    this.record = {...this.record, ...values}
    let advanceValues = []
    this.state.searchlist.forEach(item => {
      if (!item.advanced) return
      let val = this.record[item.field]
      if (val || val === 0) {
        advanceValues.push({field: item.field, type: item.type, label: item.label, value: val})
      }
    })
    this.setState({advanceValues, visible: false})
    this.handleSubmit()
  }
  closeAdvanceForm = (cell) => {
    this.record[cell.field] = ''
    this.setState({advanceValues: this.state.advanceValues.filter(item => item.field !== cell.field)})
    this.handleSubmit()
  }
  render() {
    const { float, searchStyle, visible, searchlist, showAdvanced, advanceValues, adModelWidth } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -774,9 +660,39 @@
    }
    return (
      <Form {...formItemLayout} className="ant-advanced-search-form top-search" id={this.state.formId} onSubmit={this.handleSearch}>
        <Row gutter={24}>{this.getFields()}</Row>
      </Form>
      <>
        <Form {...formItemLayout} className={`top-search ${float}`} style={searchStyle}>
          <Row gutter={24}>{this.getFields()}</Row>
          <Row gutter={24}>
            {showAdvanced ? <div className="advanced-list">
              {advanceValues.map((item, index) => {
                return (
                  <div key={index}>
                    <span>{item.label}: </span>
                    <span className="advance-value">{item.value}</span>
                    <Icon type="close" onClick={() => this.closeAdvanceForm(item)} />
                  </div>)
              })}
            </div> : null}
          </Row>
        </Form>
        <Modal
          title="高级搜索"
          maskClosable={false}
          visible={visible}
          width={adModelWidth}
          closable={false}
          footer={null}
          destroyOnClose
        >
          <MutilForm
            searchlist={searchlist}
            record={this.record}
            advanceSubmit={this.handleOk}
            handleClose={() => this.setState({visible: false})}
          />
        </Modal>
      </>
    )
  }
}