king
2024-06-28 c8804ceb1fe2dea76f9949c5ea04423876ee2c81
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Row, Col, Input, Select, Radio, notification, Tooltip, InputNumber, Checkbox, Cascader, AutoComplete } from 'antd'
import { QuestionCircleOutlined } from '@ant-design/icons'
 
import { dateOptions, matchReg, formRule } from '@/utils/option.js'
import Utils from '@/utils/utils.js'
import { checkSQL } from '@/utils/utils-custom.js'
import CodeMirror from '@/templates/zshare/codemirror'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
 
const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
const EditTable = asyncComponent(() => import('@/templates/zshare/modalform/modaleditable'))
const FieldsTable = asyncComponent(() => import('@/templates/zshare/editTable'))
 
const groupOptions = [
  {
    value: 'day',
    label: '日',
    children: [
      {value: '0', label: '当天'},
      {value: 1, label: '昨天'},
      {value: 2, label: '前天'},
      {value: 3, label: '前三天'},
      {value: 7, label: '前七天'},
      {value: 30, label: '前30天'},
      {value: 90, text: '前90天'},
      {value: -1, text: '明天'},
      {value: -2, text: '后天'},
      {value: -3, text: '后三天'},
      {value: -7, text: '后七天'},
      {value: -30, text: '后30天'},
      {value: -90, text: '后90天'},
    ]
  },
  {
    value: 'week',
    label: '周',
    children: [
      {value: '0', label: '本周'},
      {value: 1, label: '上周'},
      {value: 3, label: '前三周'},
      {value: 7, label: '前七周'},
      {value: -1, label: '下周'}
    ]
  },
  {
    value: 'month',
    label: '月',
    children: [
      {value: '0', label: '本月'},
      {value: 1, label: '上月'},
      {value: 3, label: '前三月'},
      {value: 7, label: '前七月'},
      {value: -1, label: '下月'}
    ]
  },
  {
    value: 'quarter',
    label: '季',
    children: [
      {value: '0', label: '本季度'},
      {value: 1, label: '上季度'},
      {value: -1, label: '下季度'}
    ]
  },
  {
    value: 'year',
    label: '年',
    children: [
      {value: '0', label: '本年'},
      {value: 1, label: '去年'},
      {value: -1, label: '明年'}
    ]
  },
  {
    value: 'customized',
    label: '自定义',
    children: [
      {value: '[0, 0]', label: '今天'},
      {value: '[1, 1]', label: '昨天'},
      {value: '[3, 0]', label: '近三天'},
      {value: '[7, 0]', label: '近七天'},
      {value: '[30, 0]', label: '近30天'},
      {value: '[90, 0]', label: '近90天'},
      {value: '[7, -7]', label: '前后七天'},
      {value: '[30, -30]', label: '前后30天'},
      {value: '[90, -90]', label: '前后90天'},
      {value: '[180, -180]', label: '前后180天'},
      {value: '[365, -365]', label: '前后365天'},
      {value: '[-1, -1]', label: '明天'},
      {value: '[-2, -2]', label: '后天'}
    ]
  },
]
 
const searchTypeOptions = {
  text: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'inputType', 'advanced', 'query', 'labelwidth'],
  select: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'dropdown', 'query', 'labelwidth'],
  radio: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  multiselect: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  link: ['label', 'field', 'resourceType', 'initval', 'type', 'linkField', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'dropdown', 'query', 'labelwidth'],
  date: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'precision', 'labelwidth'],
  checkcard: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'resourceType', 'display', 'width', 'multiple', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  dateweek: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  datemonth: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  daterange: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'query', 'precision', 'labelwidth'],
  group: ['label', 'type', 'field', 'datefield', 'initval', 'blacklist', 'ratio', 'items', 'required', 'labelShow', 'query', 'labelwidth'],
  switch: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'openVal', 'closeVal', 'openText', 'closeText', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  check: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'openVal', 'closeVal', 'checkTip', 'Hide', 'labelShow', 'advanced', 'query', 'labelwidth'],
  range: ['label', 'type', 'field', 'initval', 'match', 'ratio', 'blacklist', 'Hide', 'required', 'maxValue', 'minValue', 'step', 'labelShow', 'query', 'labelwidth', 'advanced']
}
 
class MainSearch extends Component {
  static propTpyes = {
    formlist: PropTypes.any,    // 表单
    card: PropTypes.object,     // 搜索条件信息
    inputSubmit: PropTypes.any  // 回车提交事件
  }
 
  state = {
    formlist: null
  }
 
  record = {}
 
  UNSAFE_componentWillMount () {
    this.props.formlist.forEach(item => {
      this.record[item.key] = item.initVal
    })
 
    let { shows, reOptions, reTypes, reTooltip, reLabel, reRequired } = this.getMutilOptions()
 
    this.setState({
      formlist: this.props.formlist.map(item => {
        item.hidden = !shows.includes(item.key)
        item.initVal = this.record[item.key]
 
        if (reOptions[item.key]) {
          item.options = reOptions[item.key]
        }
        if (reTypes[item.key]) {
          item.type = reTypes[item.key]
        }
        if (reTooltip[item.key] !== undefined) {
          item.tooltip = reTooltip[item.key]
        }
        if (reLabel[item.key] !== undefined) {
          item.label = reLabel[item.key]
        }
        if (reRequired[item.key] !== undefined) {
          item.required = reRequired[item.key]
        }
 
        return item
      })
    })
  }
 
  componentDidMount () {
    const { card } = this.props
 
    if (card.focus) {
      try {
        let _form = document.getElementById('label')
        _form.select()
      } catch (e) {
        console.warn('表单focus失败!')
      }
    }
  }
 
  getMutilOptions = () => {
    let type = this.record.type
    let shows = fromJS(searchTypeOptions[type]).toJS()
    let reOptions = {}
    let reTypes = {}
    let reTooltip = {}
    let reRequired = {}
    let reLabel = {}
 
    if (['multiselect', 'select', 'link', 'radio'].includes(type)) {
      reRequired.linkField = true
      if (this.record.resourceType === '0') {        // 自定义资源
        shows.push('options')
      } else if (this.record.resourceType === '1') { // 数据源
        shows.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database')
      }
    } else if (type === 'checkcard') {
      reRequired.fields = false
      reOptions.multiple = [{
        value: 'false',
        text: '单选'
      }, {
        value: 'true',
        text: '多选'
      }]
 
      if (this.record.display === 'picture') {
        if (this.record.resourceType === '0') {        // 自定义资源
          shows.push('options', 'fields', 'picratio')
        } else if (this.record.resourceType === '1') { // 数据源
          shows.push('dataSource', 'cardValField', 'fields', 'urlField', 'orderBy', 'orderType', 'database', 'picratio')
        }
      } else if (this.record.display === 'color') {
        if (this.record.resourceType === '0') {        // 自定义资源
          shows.push('options', 'fields')
        } else if (this.record.resourceType === '1') { // 数据源
          shows.push('dataSource', 'cardValField', 'colorField', 'fields', 'orderBy', 'orderType', 'database')
        }
      } else {
        let appType = sessionStorage.getItem('appType')
        if (appType === '') {
          reOptions.multiple = [{
            value: 'false',
            text: '单选'
          }, {
            value: 'true',
            text: '多选'
          }, {
            value: 'dropdown',
            text: '下拉菜单'
          }]
        }
 
        reRequired.fields = true
        if (this.record.resourceType === '0') {        // 自定义资源
          shows.push('options', 'fields', 'selectStyle', 'border')
        } else if (this.record.resourceType === '1') { // 数据源
          shows.push('dataSource', 'cardValField', 'fields', 'orderBy', 'orderType', 'database', 'selectStyle', 'border')
        }
        if (this.record.selectStyle === 'custom') {
          shows.push('backgroundColor')
        }
        if (this.record.multiple === 'dropdown') {
          shows.push('mark')
          if (this.record.resourceType === '1') {
            shows.push('parentField')
          }
        }
      }
      shows.push('linkField')
      reRequired.linkField = false
    } else if (type === 'daterange' || type === 'datemonth') {
      if (this.record.initval) {
        shows.push('dateShift')
      }
    }
 
    if (dateOptions.hasOwnProperty(type)) { // 根据搜索条件类型,选择初始值的类型及数据
      reOptions.initval = dateOptions[type]
      reTypes.initval = 'select'
    } else if (type === 'group') {
      reOptions.initval = groupOptions.filter(op => this.record.items.includes(op.value))
      reTypes.initval = 'cascader'
    } else {
      reTypes.initval = 'text'
    }
 
    reTooltip.match = ''
    if (type === 'text') {
      reOptions.match = matchReg.class1
    } else if (type === 'multiselect') {
      reOptions.match = matchReg.class3
    } else if (type === 'select' || type === 'link') {
      reOptions.match = matchReg.class1
    } else if (type === 'switch' || type === 'check') {
      reOptions.match = matchReg.class2
      if (type === 'switch') {
        reLabel.openVal = '开启值'
        reLabel.closeVal = '关闭值'
      } else {
        reLabel.openVal = '勾选值'
        reLabel.closeVal = '不勾选值'
      }
    } else if (type === 'date') {
      reOptions.match = matchReg.class4
    } else if (type === 'datemonth') {
      reTooltip.match = '匹配模式为 between 时,搜索条件为大于月初小于月末,匹配模式为 = 时,搜索条件为等于当前月(YYYY-MM)。'
      reOptions.match = matchReg.class6
    } else if (type === 'dateweek' || type === 'daterange' || type === 'range') {
      reOptions.match = matchReg.class5
    } else if (type === 'checkcard') {
      if (this.record.multiple === 'false') {
        reOptions.match = matchReg.class1
      } else if (this.record.multiple === 'true') {
        reOptions.match = matchReg.class3
      }
    }
 
    reTooltip.field = ''
    reLabel.field = '字段'
 
    if (type === 'text' || type === 'select') {
      reTooltip.field = '字段名可以使用逗号分隔,进行综合搜索。'
    } else if (type === 'daterange') {
      reTooltip.field = '字段名可以使用逗号分隔,例如startTime,endTime。'
    } else if (type === 'group') {
      reTooltip.field = '查询数据时(自定义脚本或统计数据源),类型字段将用作替换脚本中的 @字段@ ,类型字段对应值为:日 -> day;周 -> week;月 -> month;季 -> quarter;年 -> year;自定义 -> customized'
      reLabel.field = '类型字段'
    }
 
    reTooltip.initval = ''
    if (type === 'select') {
      if (this.record.resourceType === '0') {
        reTooltip.initval = '初始值应为数据的Value值,可使用@username@、@fullName@'
      } else if (this.record.resourceType === '1') {
        reTooltip.initval = '初始值应为《值·字段》的值,可使用@username@、@fullName@、$first。注:使用$first时,搜索条件应为必填。'
      }
    } else if (type === 'link') {
      if (this.record.resourceType === '0') {
        reTooltip.initval = '初始值应为数据的Value值。'
      } else if (this.record.resourceType === '1') {
        reTooltip.initval = '初始值应为《值·字段》的值,可使用$first。注:使用$first时,搜索条件应为必填。'
      }
    } else if (type === 'text') {
      reTooltip.initval = '可使用@username@、@fullName@。'
    } else if (type === 'range') {
      reTooltip.initval = '使用逗号拼接,例如 3,10'
    }
 
    return {
      shows,
      reOptions,
      reTypes,
      reTooltip,
      reRequired,
      reLabel
    }
  }
 
  optionChange = (key, value) => {
    this.record[key] = value
    let _fieldval = {}
 
    if (key === 'type') {
      this.record.initval = ''
      _fieldval.initval = ''
 
      if (value === 'text' || value === 'multiselect') {
        this.record.match = 'like'
        _fieldval.match = 'like'
      } else if (value === 'select' || value === 'link' || value === 'checkcard') {
        this.record.match = '='
        _fieldval.match = '='
      } else if (value === 'date') {
        this.record.match = '>='
        _fieldval.match = '>='
      } else if (value === 'datemonth' || value === 'dateweek' || value === 'daterange' || value === 'range') {
        this.record.match = 'between'
        _fieldval.match = 'between'
      }
 
      if (value === 'checkcard') {
        this.record.multiple = 'false'
        _fieldval.multiple = 'false'
      }
 
      if (this.record.options.length > 0) {
        if (value === 'checkcard') {
          this.record.options = this.record.options.map(cell => {
            cell.$value = cell.Value || ''
            delete cell.Value
            return cell
          })
  
          if (this.record.options[0].Text) {
            let key = Utils.getuuid()
    
            this.record.fields = [{
              $index: 1,
              align: 'left',
              color: 'rgba(0, 0, 0, 0.85)',
              field: 'Text',
              fontSize: 14,
              key: key,
              uuid: key
            }]
          }
        } else if (['multiselect', 'select', 'link', 'radio'].includes(value)) {
          if (!this.record.options[0].Text && this.record.fields.length > 0) {
            let field = this.record.fields[0].field
    
            this.record.options = this.record.options.map(cell => {
              cell.Value = cell.Value || cell.$value || ''
              cell.Text = cell[field] || ''
    
              return cell
            })
          } else {
            this.record.options = this.record.options.map(cell => {
              cell.Value = cell.Value || cell.$value || ''
    
              return cell
            })
          }
        }
      }
    } else if (key === 'multiple') {
      if (value === 'false') {
        this.record.match = '='
        _fieldval.match = '='
      } else if (value === 'true') {
        this.record.match = 'like'
        _fieldval.match = 'like'
      }
    } else if (key === 'display') {
      this.record.multiple = 'false'
      _fieldval.multiple = 'false'
    } else if (key === 'items') {
      let _initval = this.props.form.getFieldValue('initval')
      if (_initval && !value.includes(_initval[0])) {
        this.record.initval = ''
        _fieldval.initval = ''
      }
    }
 
    let { shows, reOptions, reTypes, reLabel, reTooltip, reRequired } = this.getMutilOptions()
 
    this.setState({
      formlist: this.state.formlist.map(item => {
        item.hidden = !shows.includes(item.key)
        item.initVal = this.record[item.key]
 
        if (reOptions[item.key]) {
          item.options = reOptions[item.key]
        }
        if (reTypes[item.key]) {
          item.type = reTypes[item.key]
        }
        if (reTooltip[item.key] !== undefined) {
          item.tooltip = reTooltip[item.key]
        }
        if (reLabel[item.key] !== undefined) {
          item.label = reLabel[item.key]
        }
        if (reRequired[item.key] !== undefined) {
          item.required = reRequired[item.key]
        }
 
        return item
      })
    }, () => {
      this.props.form.setFieldsValue(_fieldval)
    })
  }
 
  changeField = (data) => {
    this.record.fields = data || []
  }
 
  changeOptions = (data) => {
    this.record.options = data || []
  }
 
  handleSubmit = (e) => {
    e.preventDefault()
 
    if (this.props.inputSubmit) {
      this.props.inputSubmit()
    }
  }
 
  handleEmpty = () => {
    let field = this.props.form.getFieldValue('valueField')
 
    if (!field) {
      notification.warning({
        top: 92,
        message: '请填写值·字段。',
        duration: 5
      })
      return
    }
 
    let text = this.props.form.getFieldValue('valueText')
 
    if (!text) {
      notification.warning({
        top: 92,
        message: '请填写文本·字段。',
        duration: 5
      })
      return
    }
 
    let resource = this.props.form.getFieldValue('dataSource') || ''
 
    if (field === text) {
      resource = `select '' as ${field} union all \n${resource}`
    } else {
      resource = `select '' as ${field},'全部' as ${text} union all \n${resource}`
    }
 
    this.props.form.setFieldsValue({dataSource: resource})
  }
 
  complete = (key, option) => {
    let label = option.props.label
 
    this.props.form.setFieldsValue({label: label})
  }
 
  getFields() {
    const { getFieldDecorator } = this.props.form
    const { formlist } = this.state
    const fields = []
    
    formlist.forEach((item, index) => {
      if (item.hidden || item.forbid) return
 
      let span = 12
      let rules = []
      let className = ''
      let content = null
      let extra = null
      let initVal = item.initVal || ''
 
      if (item.type === 'text') {
        let type = this.record.type
        rules = [
          { required: item.required, message: '请输入' + item.label + '!' }
        ]
        if (item.key === 'field' || item.key === 'datefield' || item.key === 'dateShift') {
          rules.push({
            pattern: (type === 'text' || type === 'select' || type === 'daterange') ? formRule.field.multipattern : formRule.field.pattern,
            message: formRule.field.message
          }, {
            max: formRule.field.max,
            message: formRule.field.maxMessage
          })
        } else {
          rules.push({
            max: formRule.input.max,
            message: formRule.input.message
          })
        }
 
        if (item.key === 'field' && item.options && item.options.length > 0) {
          content = <AutoComplete
            dataSource={item.options.map((cell) => <AutoComplete.Option label={cell.label} value={cell.value} key={cell.key}>
              {cell.text}
            </AutoComplete.Option>)}
            filterOption={(input, option) => option.props.children.indexOf(input) > -1}
            onSelect={this.complete}
            placeholder=""
          >
            <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />
          </AutoComplete>
        } else {
          content = <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} onChange={(e) => {this.optionChange(item.key, e.target.value)}}/>
        }
      } else if (item.type === 'number') {
        rules = [
          { required: item.required, message: '请输入' + item.label + '!' }
        ]
        initVal = item.initVal
 
        if (item.max) {
          content = <InputNumber min={item.min} max={item.max} precision={item.precision || 0} onPressEnter={this.handleSubmit}/>
        } else {
          content = <InputNumber onPressEnter={this.handleSubmit}/>
        }
      } else if (item.type === 'select') { // 下拉搜索
        rules = [
          { required: item.required, message: '请选择' + item.label + '!' }
        ]
 
        content = <Select
          showSearch
          allowClear={item.allowClear === true}
          filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
          onChange={(value) => {this.optionChange(item.key, value)}}
          getPopupContainer={() => document.getElementById('commontable-search-form-box')}
        >
          {item.options.map((option, i) =>
            <Select.Option key={`${i}`} value={option.value}>
              {option.text || option.label}
            </Select.Option>
          )}
        </Select>
      } else if (item.type === 'radio') {
        rules = [
          { required: item.required, message: '请选择' + item.label + '!' }
        ]
 
        content = <Radio.Group style={{whiteSpace: 'nowrap'}} onChange={(e) => {this.optionChange(item.key, e.target.value)}}>
          {item.options.map(option => {
            return (
              <Radio key={option.value} value={option.value}>{option.text}</Radio>
            )
          })}
        </Radio.Group>
      } else if (item.type === 'codemirror') {
        rules = [
          { required: item.required, message: '请输入' + item.label + '!' }
        ]
        span = 24
 
        if (this.record.type === 'select' || this.record.type === 'link') {
          extra = <span className="add-resource-empty" onClick={this.handleEmpty}>全部</span>
        }
        if (item.placeholder) {
          className = 'show-public-var'
          extra = <><span className="resource-public-var">{item.placeholder}</span>{extra}</>
        }
 
        content = <CodeMirror />
      } else if (item.type === 'options') {
        span = 24
 
        let type = this.record.type
        
        if (type !== 'checkcard') {
          let columns = []
 
          if (type === 'link') {
            columns.push({ title: 'ParentID', key: 'ParentID', strict: true })
          }
 
          columns.push({ title: 'Value', key: 'Value', strict: true })
          columns.push({ title: 'Text', key: 'Text' })
 
          content = <EditTable columns={columns} module="search" onChange={this.changeOptions}/>
        } else {
          if (this.record.linkField) {
            type = 'link'
          }
 
          let columns = []
          let fields = this.record.fields || []
          let keys = ['ParentID', 'pid']
 
          if (type === 'link') {
            columns.push({ title: 'ParentID', key: 'ParentID', strict: true })
          } else if (this.record.multiple === 'dropdown' && this.record.display === 'text') {
            columns.push({ title: 'pid', key: 'pid', strict: true })
          }
          columns.push({ title: 'Value', key: '$value', strict: true })
 
          if (this.record.display === 'picture') {
            columns.push({ title: 'url', key: '$url', type: 'file' })
          } else if (this.record.display === 'color') {
            columns.push({ title: 'Color', key: '$color' })
            extra = <span>使用十六进制色彩代码(HEX)时,请在色值前添加 #</span>
          }
 
          fields.forEach(item => {
            keys.push(item.field)
            columns.push({ title: item.field, key: item.field })
          })
 
          content = <EditTable columns={columns} onChange={this.changeOptions}/>
        }
      } else if (item.type === 'fields') {
        span = 24
 
        rules = [
          { required: item.required, message: '请添加' + item.label + '!' }
        ]
 
        content = <FieldsTable indexShow={false} actions={['edit', 'move', 'del', 'add']} columns={item.columns} data={this.record.fields || []} onChange={this.changeField}/>
      } else if (item.type === 'checkbox') {
        rules = [
          { required: item.required, message: '请选择' + item.label + '!' }
        ]
 
        content = <Checkbox.Group style={{width: '105%'}} options={item.options} onChange={(values) => this.optionChange(item.key, values)}/>
      } else if (item.type === 'multiselect') {
        content = <Select
          showSearch
          mode="multiple"
          filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
        >
          {item.options.map((option, i) =>
            <Select.Option id={i} key={i} value={option.value}>{option.text}</Select.Option>
          )}
        </Select>
      } else if (item.type === 'cascader') {
        content = <Cascader options={item.options} />
      } else if (item.type === 'color') {
        className = 'color-form-item'
        rules = [
          { required: item.required, message: '请选择' + item.label + '!' }
        ]
        
        content = <ColorSketch allowClear={true}/>
      }
 
      fields.push(
        <Col span={span} key={index}>
          <Form.Item className={className} extra={extra} label={item.tooltip ?
            <Tooltip placement="topLeft" title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}>
              <QuestionCircleOutlined className="mk-form-tip" />
              {item.label}
            </Tooltip> : item.label
          }>
            {getFieldDecorator(item.key, {
              initialValue: initVal,
              rules: rules
            })(content)}
          </Form.Item>
        </Col>
      )
    })
 
    return fields
  }
 
  handleConfirm = () => {
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          values.uuid = this.props.card.uuid
 
          if (/,/.test(values.field)) {
            values.field = values.field.split(',').filter(Boolean)
            if (values.type === 'daterange' && values.field.length > 2) {
              values.field.length = 2
            }
            values.field = values.field.join(',')
          }
 
          if (['select', 'link'].includes(values.type)) {
            if (values.resourceType === '1') {
              if (/\$first/.test(values.initval) && values.initval.replace(/\s/g, '') === '$first') {
                values.initval = '$first'
              }
 
              if (values.initval === '$first' && values.required !== 'true') {
                notification.warning({
                  top: 92,
                  message: '使用$first时,搜索条件应为必填!',
                  duration: 5
                })
                return
              }
            }
          }
 
          // 下拉菜单或联动菜单
          if (['multiselect', 'select', 'link', 'radio'].includes(values.type)) {
            if (values.resourceType === '0') {
              values.options = values.options || []
              values.dataSource = ''
 
              if (values.options.filter(op => op.Text === '').length > 0) {
                notification.warning({
                  top: 92,
                  message: '提示文本(Text)不可为空!',
                  duration: 5
                })
                return
              } else if (values.options.filter(op => op.Value === '').length > 1) {
                notification.warning({
                  top: 92,
                  message: 'Value为空最多只可添加一行(在关联菜单中,Value为空时不区分ParentID)!',
                  duration: 5
                })
                return
              } else if (values.type === 'link') {
                let arr = values.options.map(m => m.ParentID + m.Value)
                let _arr = Array.from(new Set(arr))
                if (arr.length > _arr.length) {
                  notification.warning({
                    top: 92,
                    message: '同一ParentID中,Value值不可重复!',
                    duration: 5
                  })
                  return
                }
              } else {
                let arr = values.options.map(m => m.Value)
                let _arr = Array.from(new Set(arr))
                if (arr.length > _arr.length) {
                  notification.warning({
                    top: 92,
                    message: 'Value值不可重复!',
                    duration: 5
                  })
                  return
                }
              }
            } else {
              values.options = []
            }
          } else if (values.type === 'checkcard') {
            if (values.multiple === 'dropdown' && values.display !== 'text') {
              values.multiple = 'false'
            }
 
            if (values.resourceType === '0') {
              values.options = values.options || []
              values.options = values.options.map(m => {
                m.ParentID = m.ParentID || ''
                m.pid = m.pid || ''
                return m
              })
 
              let type = values.type
              if (values.linkField) {
                type = 'link'
              }
 
              if (type === 'link') {
                let arr = values.options.map(m => m.ParentID + m.$value)
                let _arr = Array.from(new Set(arr))
                if (arr.length > _arr.length) {
                  notification.warning({
                    top: 92,
                    message: '同一ParentID中,Value值不可重复!',
                    duration: 5
                  })
                  return
                }
              } else {
                let arr = values.options.map(m => m.$value)
                let _arr = Array.from(new Set(arr))
                if (arr.length > _arr.length) {
                  notification.warning({
                    top: 92,
                    message: 'Value值不可重复!',
                    duration: 5
                  })
                  return
                }
              }
            } else {
              values.options = []
            }
          }
 
          if (values.type === 'range') {
            let error = ''
            if (sessionStorage.getItem('appType') === 'mob') {
              if (values.maxValue <= values.minValue) {
                error = '最大值必须大于最小值'
              } else if (values.step <= 0) {
                error = '步长必须大于0'
              } else {
                let s = (values.maxValue - values.minValue) / values.step
                if (s !== parseInt(s)) {
                  error = '步长必须被 (max - min) 整除'
                }
              }
 
              if (!error && values.initval) {
                let vals = values.initval.split(',')
                if (vals.length !== 2) {
                  error = '初始值设置错误!'
                } else if (isNaN(parseFloat(vals[0])) || isNaN(parseFloat(vals[1]))) {
                  error = '初始值设置错误!'
                } else {
                  let start = parseFloat(vals[0])
                  let end = parseFloat(vals[1])
                  let s = (values.maxValue - start) / values.step
                  let e = (values.maxValue - end) / values.step
                  if (start > end || start < values.minValue || end > values.maxValue) {
                    error = '初始值设置错误!'
                  } else if (s !== parseInt(s) || e !== parseInt(e)) {
                    error = '初始值设置错误!'
                  }
                }
              }
            } else if (values.initval) {
              let vals = values.initval.split(',')
              if (vals.length !== 2) {
                error = '初始值设置错误!'
              } else if (isNaN(parseFloat(vals[0])) || isNaN(parseFloat(vals[1]))) {
                error = '初始值设置错误!'
              }
            }
 
            if (error) {
              notification.warning({
                top: 92,
                message: error,
                duration: 5
              })
              return
            }
          } else if (values.type === 'switch' || values.type === 'check') {
            values.initval = values.initval === values.openVal ? values.openVal : values.closeVal
          }
 
          ['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => {
            if (values[item]) {
              values[item] = values[item].replace(/\s+|\t+|\v+|\r+/ig, '')
            }
          })
 
          let pass = checkSQL(values.dataSource)
 
          if (!pass) return
 
          resolve(values)
        } else {
          reject(err)
        }
      })
    })
  }
 
  render() {
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
    return (
      <Form {...formItemLayout} className="model-search-edit-form" id="commontable-search-form-box">
        <Row gutter={24}>{this.getFields()}</Row>
      </Form>
    )
  }
}
 
export default Form.create()(MainSearch)