king
2022-08-19 3b103caa6bfc9ed410e67156c3ca1785bf1cecc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Row, Col, Button, notification, Modal, Drawer } from 'antd'
import { CloseOutlined, DownOutlined } from '@ant-design/icons'
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 MKInput from './mkInput'
import './index.scss'
 
const MutilForm = asyncSpinComponent(() => import('./advanceform'))
const MKCheckCard = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkCheckCard'))
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,用于查询下拉选择项
    searchlist: PropTypes.array, // 搜索条件列表
    config: PropTypes.object,    // 组件配置信息(自定义页面)
    setting: PropTypes.object,   // 组件配置信息(自定义页面)
    refreshdata: PropTypes.func  // 刷新数据
  }
 
  state = {
    searchlist: null,        // 搜索项
    setting: {},
    advanceValues: [],       // 高级搜索条件保存值
    visible: false,
    hasReqFields: false
  }
 
  record = {}
 
  UNSAFE_componentWillMount () {
    const { config, searchlist, setting } = this.props
 
    let _searchlist = []
    let fieldMap = new Map()
    let mainItems = []  // 云端或单点数据
    let localItems = [] // 本地数据
    let deForms = []    // 测试系统,单个请求
    let advanceValues = []
    let linkFields = {}
    let record = {}
    let hasReqFields = false
 
    let forbid = false // header中不设置高级搜索
    let _setting = {showAdv: false, show: false}
    
    if (setting) {
      _setting.show = setting.show !== 'false'
      _setting.float = setting.float || 'left'
      _setting.advanceType = setting.advanceType || 'modal'
      _setting.advWidth = setting.advanceWidth || 1000
      _setting.placement = setting.drawerPlacement || 'right'
      _setting.ratio = setting.searchRatio || 6
      _setting.labelwidth = setting.searchLwidth !== undefined ? setting.searchLwidth : 33.3
      _setting.labelCol = {style: {width: _setting.labelwidth + '%'}}
      _setting.wrapperCol = {style: {width: (100 - _setting.labelwidth) + '%'}}
      _setting.style = null
    } else if (config) {
      if (config.wrap) {
        _setting.show = config.wrap.show !== 'false'
        _setting.advanceType = config.wrap.advanceType || 'modal'
        _setting.advWidth = config.wrap.advanceWidth || 1000
        _setting.placement = config.wrap.drawerPlacement || 'right'
        _setting.ratio = config.wrap.searchRatio || 6
        _setting.labelwidth = config.wrap.searchLwidth !== undefined ? config.wrap.searchLwidth : 33.3
        _setting.labelCol = {style: {width: _setting.labelwidth + '%'}}
        _setting.wrapperCol = {style: {width: (100 - _setting.labelwidth) + '%'}}
      }
      _setting.style = null
      
      if (config.type === 'search') {
        _setting.float = config.wrap.float || 'left'
        _setting.style = config.style
      } else if (config.type === 'table' && (config.subtype === 'normaltable' || config.subtype === 'editable')) {
        _setting.float = 'left'
      } else {
        _setting.float = 'right'
        _setting.show = false
        forbid = true
      }
    }
 
    if (_setting.advanceType === 'drawer' && _setting.advWidth) {
      if (_setting.placement === 'top' || _setting.placement === 'bottom') {
        _setting.advHeight = _setting.advWidth > 100 ? _setting.advWidth + 'px' : _setting.advWidth + 'vh'
        _setting.advWidth = '100vw'
      } else {
        _setting.advWidth = _setting.advWidth > 100 ? _setting.advWidth + 'px' : _setting.advWidth + 'vw'
      }
    } else if (_setting.advanceType === 'modal' && _setting.advWidth) {
      if (_setting.advWidth < 100) {
        _setting.advWidth = _setting.advWidth + 'vw'
      } else {
        _setting.advWidth = _setting.advWidth + 'px'
      }
    }
 
    if (searchlist) {
      _searchlist = fromJS(searchlist).toJS()
    } else if (config) {
      _searchlist = fromJS(config.search).toJS()
    }
 
    _searchlist.forEach(item => {
      if (item.linkField) {
        linkFields[item.linkField] = linkFields[item.linkField] || []
        linkFields[item.linkField].push({field: item.field, uuid: item.uuid})
      }
 
      let labelwidth = item.labelwidth || 33.3
      if (item.labelShow === 'false') {
        labelwidth = 0
      }
      item.labelCol = {style: {width: labelwidth + '%'}}
      item.wrapperCol = {style: {width: (100 - labelwidth) + '%'}}
 
      if (fieldMap.has(item.field)) {
        item.field = item.field + '@tail@'
      }
 
      if (item.required) {
        hasReqFields = true
      }
 
      if (item.advanced && !forbid) {
        _setting.showAdv = true
      } else {
        item.advanced = false
      }
 
      if (item.advanced && item.initval) {
        let val = item.initval
        if (item.precision === 'hour') {
          if (/,/ig.test(val)) {
            val = val.split(',').map(m => m + ':00').join(',')
          } else {
            val = val + ':00'
          }
        }
        advanceValues.push({field: item.field, type: item.type, label: item.label, value: val})
      }
 
      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 || []
        item.options = item.options.filter(op => !op.Hide)
        if (item.setAll === 'true' && ['select', 'link'].includes(item.type)) {
          item.options.unshift({
            key: Utils.getuuid(),
            Value: '',
            Text: '全部',
            ParentID: ''
          })
        }
 
        // 数据源查询语句
        if (item.resourceType === '1' && item.dataSource) {
          let _option = Utils.getSelectQueryOptions(item)
 
          // 测试系统单个请求
          if (!window.GLOB.mkHS && 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)
    })
 
    this.record = record
 
    let _list = _searchlist.map(item => {
      if (item.hidden) return item
 
      if (linkFields[item.field] && (item.type === 'select' || item.type === 'link' || (item.type === 'checkcard' && item.multiple !== 'true'))) {
        item.linkFields = linkFields[item.field]
      }
 
      if (item.linkField) {
        let supItem = fieldMap.get(item.linkField)
        
        if (!supItem) {
          notification.warning({
            top: 92,
            message: '未查询到搜索条件《' + item.label + '》关联字段!',
            duration: 5
          })
          item.type = 'select'
        } else {
          item.supInitVal = supItem.initval
          item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval || option.Value === '')
        }
      }
 
      return item
    })
 
    this.setState({
      setting: _setting,
      hasReqFields,
      advanceValues,
      searchlist: _list
    }, () => {
      if (!window.GLOB.mkHS && options.sysType === 'local' && !window.GLOB.systemType) {
        this.improveSimpleSearch(deForms)
      } else {
        this.improveSearch(mainItems, localItems)
      }
    })
  }
 
  // 查询下拉菜单
  improveSearch = (mainItems, localItems) => {
    const { BID } = this.props
    let deffers = []
 
    if (!window.GLOB.mkHS && 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 (window.GLOB.mkHS) { // 云端数据验证
        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
      }
 
      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 (window.GLOB.mkHS) { // 云端数据验证
        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, index) => {
      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 => {
          setTimeout(() => {
            Api.getSystemCacheConfig(param).then(res => {
              if (!res.status) {
                notification.warning({
                  top: 92,
                  message: res.message,
                  duration: 5
                })
              }
              resolve(res)
            })
          }, index * 30)
        })
      )
    })
 
    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 = fromJS(this.state.searchlist).toJS().map(item => {
      if (['select', 'link', 'multiselect', 'checkcard'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
        let options = []
        let map = new Map()
        result[item.field].forEach(cell => {
          let _item = {
            key: Utils.getuuid(),
            ParentID: ''
          }
 
          if (item.linkField) {
            _item.ParentID = cell[item.linkField]
          }
 
          if (item.type !== 'checkcard') {
            _item.Value = cell[item.valueField]
            _item.Text = cell[item.valueText] + ''
            
            if (!_item.Text || map.has(_item.ParentID + _item.Value)) return
            
            map.set(_item.ParentID + _item.Value, 0)
          } else {
            _item.$value = cell[item.cardValField]
            _item = {..._item, ...cell}
 
            if (map.has(_item.ParentID + _item.$value)) return
            
            map.set(_item.ParentID + _item.$value, 0)
          }
 
          options.push(_item)
        })
 
        item.oriOptions = [...item.oriOptions, ...options]
      }
 
      if (item.linkField) {
        if (item.supInitVal) {
          item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.Value === '')
        } else {
          item.options = item.oriOptions
        }
      } else if (item.oriOptions) {
        item.options = item.oriOptions
      }
 
      return item
    })
 
    this.setState({
      searchlist: _searchlist
    })
  }
 
  recordChange = (val, defer, item) => {
    this.record[item.field] = val
 
    if (defer) return
 
    if (item.linkFields) {
      setTimeout(() => {
        this.handleSubmit()
      }, 1000)
    } else {
      setTimeout(() => {
        this.handleSubmit()
      }, 10)
    }
  }
 
  dateGroupChange = (val, type, item) => {
    this.record[item.datefield] = val
    this.record[item.field] = type
 
    this.handleSubmit()
  }
 
  cardChange = (val, item) => {
    this.record[item.field] = val
 
    if (!item.linkFields) {
      setTimeout(() => {
        this.handleSubmit()
      }, 10)
    }
  }
 
  getFields() {
    const { getFieldDecorator } = this.props.form
    const { visible, setting } = this.state
    const fields = []
 
    this.state.searchlist.forEach((item, index) => {
      if (item.hidden || (item.advanced && (setting.advanceType !== 'pulldown' || !visible))) return
 
      const _rules = [
        {
          required: item.required,
          message: item.label + '不可为空!'
        }
      ]
 
      let content = null
      let field = item.field
 
      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') {
        content = <MKCheckCard config={item} onChange={(val) => this.cardChange(val, item)} />
      }
 
      if (content) {
        fields.push(
          <Col className="mk-search-col" span={item.ratio || 6} key={index}>
            <Form.Item
              label={item.labelShow !== 'false' ? item.label : ''}
              labelCol={item.labelCol}
              wrapperCol={item.wrapperCol}
            >
              {getFieldDecorator(field, {
                initialValue: item.initval,
                rules: _rules
              })(content)}
            </Form.Item>
          </Col>
        )
      }
    })
 
    if (setting.show || setting.showAdv) {
      fields.push(
        <Col span={setting.ratio} style={{ whiteSpace: 'nowrap' }} className="mk-search-col search-button" key="actions">
          <Form.Item
            label={' '}
            colon={false}
            labelCol={setting.labelCol}
            wrapperCol={setting.wrapperCol}
          >
            {setting.show ? <Button type="primary" onClick={this.handleSubmit}>
              搜索
            </Button> : null}
            {setting.show ? <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
              重置
            </Button> : null}
            {setting.showAdv ? <Button className={visible ? 'visible' : ''} type="link" onClick={this.handleAdvance}>
              高级{setting.advanceType === 'pulldown' ? <DownOutlined /> : null}
            </Button> : null}
          </Form.Item>
        </Col>
      )
    }
    
    return fields
  }
 
  handleAdvance = () => {
    const { setting, visible } = this.state
 
    if (setting.advanceType !== 'pulldown' && visible) {
      return
    }
 
    this.setState({visible: !visible})
 
    if (setting.advanceType === 'pulldown') {
      if (visible) {
        let advanceValues = []
        this.state.searchlist.forEach(item => {
          if (!item.advanced) return
    
          let val = this.record[item.field]
          if (val || val === 0) {
            if (item.precision === 'hour') {
              if (/,/ig.test(val)) {
                val = val.split(',').map(m => m + ':00').join(',')
              } else {
                val = val + ':00'
              }
            }
            advanceValues.push({field: item.field, type: item.type, label: item.label, value: val})
          }
        })
        this.setState({advanceValues})
      } else {
        let list = this.state.searchlist.map(item => {
          if (!item.advanced) return item
    
          item.initval = this.record[item.field]
          
          return item
        })
        this.setState({searchlist: list})
      }
    }
  }
 
  handleSubmit = () => {
    this.setState({}, () => {
      this.props.form.validateFields((err, values) => {
        if (err) return
 
        let { searches, error } = this.getFieldsValues(values)
  
        if (error) {
          notification.warning({
            top: 92,
            message: error,
            duration: 3
          })
          return
        } else 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: '请输入' + labels.join('、') + ' !',
              duration: 3
            })
            return
          }
        }
 
        this.props.refreshdata(searches)
      })
    })
  }
 
  /**
   * @description 搜索条件重置
   */
  handleReset = () => {
    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) {
        let val = item.initval
        if (item.precision === 'hour') {
          if (/,/ig.test(val)) {
            val = val.split(',').map(m => m + ':00').join(',')
          } else {
            val = val + ':00'
          }
        }
        advanceValues.push({field: item.field, type: item.type, label: item.label, value: val})
      }
 
      return item
    })
 
    this.record = record
 
    this.setState({searchlist: [], advanceValues}, () => {
      this.setState({searchlist}, () => {
        this.handleSubmit()
      })
    })
  }
 
  getFieldsValues = (vals) => {
    const { searchlist } = this.state
    let values = {...this.record, ...vals}
    this.record = values
 
    // 获取搜索条件值
    let search = []
    let error = null
    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,
          precision: 'day',
          forbid: item.$forbid
        }, {
          type: 'group',
          key: item.field,
          value: values[item.field] || '',
          label: item.label,
          match: '=',
          forbid: true,
          required: item.required
        })
      } else {
        let type = item.type
        let val = values[item.field] !== undefined ? values[item.field] : ''
 
        if (type === 'multiselect' || (type === 'checkcard' && item.multiple === 'true')) {
          type = 'multi'
        } else if (type === 'text' && !error) {
          if (/'/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用英文状态的单引号。`
          } else if (/--/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用 -- 。`
          } else if (/(^|\s)select\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字select。`
          } else if (/\sfrom(\s|\()/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字from。`
          } else if (/(^|\s)insert\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字insert。`
          } else if (/(^|\s)delete\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字delete。`
          } else if (/(^|\s)update\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字update。`
          } else if (/(^|\s)where\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字where。`
          } else if (/(^|\s)drop\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字drop。`
          } else if (/(^|\s)exec\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字exec。`
          } else if (/(^|\s)truncate\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字truncate。`
          } else if (/(^|\s)while\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字while。`
          } else if (/(^|\s)for\s/ig.test(val)) {
            error = `搜索条件${item.label}中,不可使用关键字for。`
          }
        }
 
        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,
          precision: item.precision || 'day',
          forbid: item.$forbid
        })
      }
    })
 
    return {searches: search, error}
  }
 
  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) {
        if (item.precision === 'hour') {
          if (/,/ig.test(val)) {
            val = val.split(',').map(m => m + ':00').join(',')
          } else {
            val = val + ':00'
          }
        }
        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 { visible, searchlist, advanceValues, setting } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
 
    return (
      <>
        <Form {...formItemLayout} className={`top-search mk-float-${setting.float}`} style={setting.style}>
          <Row gutter={24}>{this.getFields()}</Row>
          {advanceValues.length && (setting.advanceType !== 'pulldown' || (setting.advanceType === 'pulldown' && !visible)) ? <Row gutter={24}>
            <div className="advanced-list">
              {advanceValues.map((item, index) => {
                return (
                  <div key={index}>
                    <span>{item.label}: </span>
                    <span className="advance-value">{item.value}</span>
                    <CloseOutlined onClick={() => this.closeAdvanceForm(item)} />
                  </div>)
              })}
            </div>
          </Row> : null}
        </Form>
        {setting.advanceType === 'modal' ? <Modal
          title="高级搜索"
          maskClosable={false}
          visible={visible}
          width={setting.advWidth}
          closable={false}
          footer={null}
          destroyOnClose
        >
          <MutilForm
            searchlist={searchlist}
            record={this.record}
            advanceSubmit={this.handleOk}
            handleClose={() => this.setState({visible: false})}
          />
        </Modal> : null}
        {setting.advanceType === 'drawer' ? <Drawer
          title="高级搜索"
          className="mk-search-drawer"
          width={setting.advWidth}
          height={setting.advHeight}
          maskClosable={false}
          onClose={() => this.setState({visible: false})}
          visible={visible}
          placement={setting.placement}
          destroyOnClose
        >
          <MutilForm
            searchlist={searchlist}
            record={this.record}
            advanceSubmit={this.handleOk}
            handleClose={() => this.setState({visible: false})}
          />
        </Drawer> : null}
      </>
    )
  }
}
 
export default Form.create()(MainSearch)