From 342d3498191f1683059fe586209ec920545e0bf9 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 28 九月 2021 13:38:09 +0800
Subject: [PATCH] 2021-09-28

---
 src/tabviews/zshare/topSearch/index.jsx |  896 ++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 574 insertions(+), 322 deletions(-)

diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx
index 8c1adb4..d2c6e39 100644
--- a/src/tabviews/zshare/topSearch/index.jsx
+++ b/src/tabviews/zshare/topSearch/index.jsx
@@ -1,66 +1,186 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-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 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锛岀敤浜庢煡璇笅鎷夐�夋嫨椤�
+    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,       // 鎼滅储椤�
-    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
   }
 
-  UNSAFE_componentWillMount () {
-    let searchlist = JSON.parse(JSON.stringify(this.props.searchlist))
-    let match = {}
-    let label = {}
-    let style = {}
-    let required = {}
-    let _list = []
-    let fieldMap = new Map()
+  record = {}
 
-    searchlist.forEach(item => {
+  UNSAFE_componentWillMount () {
+    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
+
+    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.type === 'select' || item.type === 'link') {
-        item.oriOptions = JSON.parse(JSON.stringify(item.options))
+      if (item.required) {
+        hasReqFields = true
       }
 
-      _list.push(item)
+      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.state.dict['main.all']
+          })
+        }
+
+        // 鏁版嵁婧愭煡璇㈣鍙�
+        if (item.resourceType === '1' && item.dataSource) {
+          let _option = Utils.getSelectQueryOptions(item)
+
+          // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
+          if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
+            deForms.push({
+              ...item,
+              arr_field: _option.field,
+              data_sql: Utils.formatOptions(_option.sql)
+            })
+          } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
+            if (item.database === 'sso') {
+              mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql))}' as LText`)
+            } else {
+              localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql))}' as LText`)
+            }
+          }
+        }
+        item.oriOptions = fromJS(item.options).toJS()
+      }
+
+      fieldMap.set(item.field, item)
     })
 
-    _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({
             top: 92,
             message: '鏈煡璇㈠埌鎼滅储鏉′欢銆�' + item.label + '銆嬪叧鑱斿瓧娈碉紒',
-            duration: 10
+            duration: 5
           })
+          item.type = 'select'
         } else {
-          item.options = item.oriOptions.filter(option => option.parentId === supItem.initval)
+          item.supInitVal = supItem.initval
+          item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval || option.Value === '')
         }
       }
 
@@ -68,364 +188,466 @@
     })
 
     this.setState({
-      match: match,
-      label: label,
-      style: style,
-      required: required,
+      float,
+      showButton,
+      searchStyle,
+      hasReqFields,
+      showAdvanced,
+      adModelWidth,
+      advanceValues,
       searchlist: _list
+    }, () => {
+      if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
+        this.improveSimpleSearch(deForms)
+      } else {
+        this.improveSearch(mainItems, localItems)
+      }
     })
   }
 
-  UNSAFE_componentWillReceiveProps(nextProps) {
-    let searchlist = JSON.parse(JSON.stringify(nextProps.searchlist))
-    let _list = []
-    let fieldMap = new Map()
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
 
-    searchlist.forEach(item => {
-      if (fieldMap.has(item.field)) {
-        item.field = item.field + '@tail@'
-      }
-      fieldMap.set(item.field, true)
+  // 鏌ヨ涓嬫媺鑿滃崟
+  improveSearch = (mainItems, localItems) => {
+    const { menuType, BID } = this.props
+    let deffers = []
 
-      if (item.type === 'select' || item.type === 'link') {
-        item.oriOptions = JSON.parse(JSON.stringify(item.options))
+    if (menuType !== 'HS' && window.GLOB.systemType !== 'production') {
+      localItems = [...localItems, ...mainItems]
+      mainItems = []
+    }
+
+    // 鏈湴璇锋眰
+    let param = {
+      func: 'sPC_Get_SelectedList',
+      LText: localItems.join(' union all '),
+      obj_name: '',
+      arr_field: '',
+      table_type: 'Y'
+    }
+
+    if (BID) {
+      param.BID = BID
+    }
+    
+    if (param.LText) {
+      param.LText = Utils.formatOptions(param.LText)
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+
+      if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
+        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
       }
 
-      _list.push(item)
+      deffers.push(
+        new Promise(resolve => {
+          Api.getSystemCacheConfig(param).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+            resolve(res)
+          })
+        })
+      )
+    }
+
+    // 绯荤粺璇锋眰
+    let mainparam = {
+      func: 'sPC_Get_SelectedList',
+      LText: mainItems.join(' union all '),
+      obj_name: '',
+      arr_field: '',
+      table_type: 'Y'
+    }
+
+    if (BID) {
+      mainparam.BID = BID
+    }
+
+    if (mainparam.LText) {
+      mainparam.LText = Utils.formatOptions(mainparam.LText)
+      mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp)
+
+      if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
+        mainparam.open_key = Utils.encryptOpenKey(mainparam.secretkey, mainparam.timestamp)
+        if (options.cloudServiceApi) {
+          mainparam.rduri = options.cloudServiceApi
+          mainparam.userid = sessionStorage.getItem('CloudUserID') || ''
+          mainparam.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
+        }
+      } else if (window.GLOB.mainSystemApi) {
+        mainparam.rduri = window.GLOB.mainSystemApi
+      }
+
+      deffers.push(
+        new Promise(resolve => {
+          Api.getSystemCacheConfig(mainparam).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+            resolve(res)
+          })
+        })
+      )
+    }
+
+    Promise.all(deffers).then(response => {
+      let result = {...response[0], ...(response[1] || {})}
+
+      delete result.ErrCode
+      delete result.ErrMesg
+      delete result.message
+      delete result.status
+
+      this.resetSearch(result)
+    })
+  }
+
+  // 娴嬭瘯绯荤粺鍗曚釜璇锋眰涓嬫媺閫夐」
+  improveSimpleSearch = (deForms) => {
+    if (deForms.length === 0) return
+
+    let deffers = deForms.map(item => {
+      let param = {
+        func: 'sPC_Get_SelectedList',
+        LText: item.data_sql,
+        obj_name: item.field,
+        arr_field: item.arr_field
+      }
+
+      if (this.props.BID) {
+        param.BID = this.props.BID
+      }
+
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+
+      return (
+        new Promise(resolve => {
+          Api.getSystemCacheConfig(param).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+            resolve(res)
+          })
+        })
+      )
     })
 
-    _list = _list.map(item => {
-      if (item.type === 'link') {
-        let supItem = _list.filter(form => form.field === item.linkField)[0]
-        
-        if (supItem) {
-          item.options = item.oriOptions.filter(option => option.parentId === supItem.initval)
-        }
-      }
+    Promise.all(deffers).then(response => {
+      let result = {}
 
+      response.forEach(res => {
+        result = {...result, ...res}
+      })
+
+      delete result.ErrCode
+      delete result.ErrMesg
+      delete result.message
+      delete result.status
+
+      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]
+          }
+
+          options.push(_item)
+        })
+
+        item.oriOptions = [...item.oriOptions, ...options]
+      }
       return item
     })
 
     this.setState({
-      searchlist: _list
-    })
-  }
-
-  resetform = (formlist, supfields, index) => {
-    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 : ''
-          item.hiden = true
-  
-          subfields.push(item)
+      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
       })
     })
+  }
 
-    if (subfields.length === 0 || index > 6) {
-      return formlist
+  recordChange = (val, defer, item) => {
+    this.record[item.field] = val
+
+    if (defer) return
+
+    if (item.linkFields) {
+      setTimeout(() => {
+        this.handleSubmit()
+      }, 1000)
     } else {
-      return this.resetform(formlist, subfields, index)
+      this.handleSubmit()
     }
   }
 
-  selectChange = (_field, value) => {
-    let formlist = JSON.parse(JSON.stringify(this.state.searchlist))
+  dateGroupChange = (val, type, item) => {
+    this.record[item.datefield] = val
+    this.record[item.field] = type
 
-    let subfields = []
-    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 : ''
-        item.hiden = true
-
-        subfields.push(item)
-      }
-      return item
-    })
-
-    if (subfields.length === 0) {
-      this.searchChange()
-      return
-    }
-
-    formlist = this.resetform(formlist, subfields, 0)
-
-    this.setState({
-      searchlist: formlist
-    }, () => {
-      this.setState({
-        searchlist: formlist.map(item => {
-          item.hiden = false
-          return item
-        })
-      }, () => {
-        this.searchChange()
-      })
-    })
+    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.hidden) return
+      if (item.hidden || item.advanced) 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"
-                  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.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 + '涓嶅彲涓虹┖!'
         }
+      ]
 
+      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 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)}
-                />
-              )}
+          <Col span={item.ratio || 6} key={index}>
+            <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
   }
 
-  handleSearch = (e) => {
-    // 鍥炶溅鎴栫偣鍑绘悳绱�
-    e.preventDefault()
-    this.props.form.validateFields((err, values) => {
-      let searches = this.getFieldsValues(values)
-      this.props.refreshdata(searches)
-    })
+  handleAdvance = () => {
+    this.setState({visible: true})
   }
 
-  searchChange = () => {
+  handleSubmit = () => {
     this.setState({}, () => {
       this.props.form.validateFields((err, values) => {
+        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)
       })
     })
   }
 
+  /**
+   * @description 鎼滅储鏉′欢閲嶇疆
+   */
   handleReset = () => {
-    // 閲嶇疆
-    this.props.form.resetFields()
-    this.props.form.validateFields((err, values) => {
-      let searches = this.getFieldsValues(values)
-      this.props.refreshdata(searches)
+    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.record = record
+
+    this.setState({searchlist: [], advanceValues}, () => {
+      this.setState({searchlist}, () => {
+        this.handleSubmit()
+      })
     })
   }
 
-  getFieldsValues = (values) => {
+  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) {
-          _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].replace(/(^\s*|\s*$)/ig, '')
+        let type = item.type
+        if (type === 'multiselect' || (type === 'checkcard' && item.multiple === 'true')) {
+          type = 'multi'
+        }
+        let val = values[item.field] !== undefined ? values[item.field] : ''
 
+        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]
-      })
     })
+
     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 },
@@ -438,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>
+      </>
     )
   }
 }

--
Gitblit v1.8.0