king
2021-10-10 8cdfdd9914d1c4f6cd59176d61869522f51f39e4
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
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Table, Typography, Icon, Switch, Modal, Input, InputNumber, Tooltip, Button, notification, message } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import asyncComponent from '@/utils/asyncComponent'
import Utils, { getEditTableSql } from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import '@/assets/css/table.scss'
import './index.scss'
 
const { Paragraph } = Typography
const { confirm } = Modal
const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
 
class BodyRow extends React.Component {
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props.data), fromJS(nextProps.data))
  }
 
  render() {
    let { lineMarks, data, ...resProps } = this.props
    let style = {}
    let className = ''
 
    lineMarks && lineMarks.some(mark => {
      let originVal = data[mark.field[0]] + ''
      let contrastVal = ''
      let result = false
 
      if (mark.field[1] === 'static') {
        contrastVal = mark.contrastValue + ''
      } else {
        contrastVal = data[mark.field[2]] + ''
      }
 
      if (mark.match === '=') {
        result = originVal === contrastVal
      } else if (mark.match === '!=') {
        result = originVal !== contrastVal
      } else if (mark.match === 'like') {
        result = originVal.indexOf(contrastVal) > -1
      } else if (mark.match === '>') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch (e) {
          originVal = NaN
        }
 
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
          result = true
        }
      } else if (mark.match === '<') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch (e) {
          originVal = NaN
        }
 
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
          result = true
        }
      }
 
      if (result) {
        if (mark.signType[0] === 'font') {
          style.color = mark.color
        } else if (mark.signType[0] === 'background') {
          style.background = mark.color
          if (mark.fontColor) {
            style.color = mark.fontColor
          }
          className = 'background'
        } else if (mark.signType[0] === 'underline') {
          style.textDecoration = 'underline'
          style.color = mark.color
        } else if (mark.signType[0] === 'line-through') {
          style.textDecoration = 'line-through'
          style.color = mark.color
        }
      }
 
      return result
    })
 
    return <tr {...resProps} className={className} style={style}/>
  }
}
 
class BodyCell extends React.Component {
  state = {
    editing: false,
    err: null
  }
 
  getMark = (record, marks, style, content) => {
    marks.some(mark => {
      let originVal = record[mark.field[0]] + ''
      let contrastVal = ''
      let result = false
 
      if (mark.field[1] === 'static') {
        contrastVal = mark.contrastValue + ''
      } else {
        contrastVal = record[mark.field[2]] + ''
      }
 
      if (mark.match === '=') {
        result = originVal === contrastVal
      } else if (mark.match === '!=') {
        result = originVal !== contrastVal
      } else if (mark.match === 'like') {
        result = originVal.indexOf(contrastVal) > -1
      } else if (mark.match === '>') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch (e) {
          originVal = NaN
        }
 
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
          result = true
        }
      } else if (mark.match === '<') {
        try {
          originVal = parseFloat(originVal)
          contrastVal = parseFloat(contrastVal)
        } catch (e) {
          originVal = NaN
        }
 
        if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
          result = true
        }
      }
 
      if (result) {
        if (mark.signType[0] === 'font') {
          style.color = mark.color
        } else if (mark.signType[0] === 'background') {
          style.background = mark.color
          if (mark.fontColor) {
            style.color = mark.fontColor
          }
        } else if (mark.signType[0] === 'underline') {
          style.textDecoration = 'underline'
          style.color = mark.color
        } else if (mark.signType[0] === 'line-through') {
          style.textDecoration = 'line-through'
          style.color = mark.color
        } else if (mark.signType[0] === 'icon') {
          let icon = (<Icon style={{color: mark.color}} type={mark.signType[3]} />)
          if (mark.signType[1] === 'front') {
            content = <span>{icon} {content}</span>
          } else {
            content = <span>{content} {icon}</span>
          }
        }
      }
      return result
    })
 
    return content
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props.record), fromJS(nextProps.record)) ||
      nextState.editing !== this.state.editing ||
      nextState.err !== this.state.err
  }
 
  componentDidMount () {
    MKEmitter.addListener('tdFocus', this.tdFocus)
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('tdFocus', this.tdFocus)
  }
 
  tdFocus = (id) => {
    const { col, record } = this.props
    if (id !== col.uuid + record.$Index) return
    this.focus()
  }
 
  enterPress = () => {
    const { col, record } = this.props
    const { value } = this.state
 
    this.setState({editing: false})
    if (col.enter === '$next') {
      MKEmitter.emit('nextLine', col, record.$Index)
    } else {
      MKEmitter.emit('tdFocus', col.enter + record.$Index)
    }
 
    if (value !== record[col.field]) {
      MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value})
    }
  }
 
  focus = () => {
    const { col, record } = this.props
 
    let err = null
    let val = record[col.field] !== undefined ? record[col.field] : ''
 
    if (col.type === 'number') {
      val = +val
      if (isNaN(val)) {
        val = 0
      }
      if (typeof(col.max) === 'number' && val > col.max) {
        err = col.label + '最大为' + col.max
      } else if (typeof(col.min) === 'number' && val < col.min) {
        err = col.label + '最小为' + col.min
      }
    } else if (col.required === 'true' && !val) {
      err = '请填写' + col.label
    }
 
    this.setState({editing: true, value: val, err}, () => {
      let node = document.getElementById(col.uuid + record.$Index)
      node && node.select()
    })
  }
 
  onBlur = () => {
    const { col, record } = this.props
    const { value } = this.state
 
    this.setState({editing: false})
 
    if (value !== record[col.field]) {
      MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value})
    }
  }
  
  onChange = (val) => {
    const { col } = this.props
    
    let err = null
 
    if (col.type === 'number') {
      val = +val
      if (isNaN(val)) {
        val = 0
      }
      if (typeof(col.max) === 'number' && val > col.max) {
        err = col.label + '最大为' + col.max
      } else if (typeof(col.min) === 'number' && val < col.min) {
        err = col.label + '最小为' + col.min
      }
    } else if (col.required === 'true' && !val) {
      err = '请填写' + col.label
    }
    this.setState({value: val, err})
  }
 
  render() {
    let { col, config, record, style, className } = this.props
    const { editing, value, err } = this.state
 
    let children = null
    if (col.type === 'text') {
      let content = ''
      if (record[col.field] !== undefined) {
        content = `${record[col.field]}`
      }
 
      if (content !== '') {
        if (col.textFormat === 'YYYY-MM-DD' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])/.test(content)) {
          content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
        } else if (col.textFormat === 'YYYY-MM-DD HH:mm:ss' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1]).([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/.test(content)) {
          content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)} ${content.substr(11, 2)}:${content.substr(14, 2)}:${content.substr(17, 2)}`
        }
 
        content = (col.prefix || '') + content + (col.postfix || '')
      }
 
      if (col.marks) {
        style = style || {}
        content = this.getMark(record, col.marks, style, content)
      }
 
      if (col.editable === 'true') {
        if (editing) {
          return (<td className="editing_table_cell">
            <Input id={col.uuid + record.$Index} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
            {err ? <Tooltip title={err}><Icon type="exclamation-circle" /></Tooltip> : null}
          </td>)
        } else {
          return (<td className={className + ' pointer'} style={style}><div className="mk-mask" onClick={this.focus}></div>{content}</td>)
        }
      } else {
        children = content
      }
    } else if (col.type === 'number') {
      let content = ''
      try {
        content = parseFloat(record[col.field])
        if (isNaN(content)) {
          content = ''
        }
      } catch (e) {
        content = ''
      }
 
      if (content !== '') {
        let decimal = col.decimal || 0
        if (col.format === 'percent') {
          content = content * 100
          decimal = decimal > 2 ? decimal - 2 : 0
        }
  
        content = content.toFixed(decimal)
  
        if (col.format === 'thdSeparator') {
          content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
        }
  
        content = col.prefix + content + col.postfix
      }
 
      if (col.marks) {
        style = style || {}
        content = this.getMark(record, col.marks, style, content)
      }
 
      if (col.editable === 'true') {
        if (editing) {
          return (<td className="editing_table_cell">
            <InputNumber id={col.uuid + record.$Index} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
            {err ? <Tooltip title={err}><Icon type="exclamation-circle" /></Tooltip> : null}
          </td>)
        } else {
          return (<td className={className + ' pointer'} style={style}><div className="mk-mask" onClick={this.focus}></div>{content}</td>)
        }
      } else {
        children = content
      }
    } else if (col.type === 'textarea') {
      let content = ''
      if (record[col.field] !== undefined) {
        content = `${record[col.field]}`
      }
 
      if (content) {
        content = col.prefix + content + col.postfix
      }
 
      children = (
        <div>
          {content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null }
        </div>
      )
    } else if (col.type === 'custom') {
      style.padding = '0px'
      if (col.style) {
        style = {...style, ...col.style}
      }
 
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
    } else if (col.type === 'action') {
      style.padding = '0px 5px'
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
    } else if (col.type === 'operation') {
      style.padding = '0px 5px'
      children = (
        <Button type="link" style={{color: 'rgb(255, 77, 79)', backgroundColor: 'transparent'}} onClick={() => MKEmitter.emit('delRecord', col.tableId, {...record})}>删除</Button>
      )
    }
 
    return (<td className={className} style={style}>{children}</td>)
  }
}
 
class NormalTable extends Component {
  static propTpyes = {
    statFValue: PropTypes.any,       // 合计字段数据
    MenuID: PropTypes.string,        // 菜单Id
    setting: PropTypes.object,       // 表格全局设置:tableType(表格是否可选、单选、多选)、columnfixed(列固定)、actionfixed(按钮固定)
    columns: PropTypes.array,        // 表格列
    lineMarks: PropTypes.any,        // 行标记
    fields: PropTypes.array,         // 组件字段集
    BID: PropTypes.any,              // 主表ID
    data: PropTypes.any,             // 表格数据
    total: PropTypes.any,            // 总数
    loading: PropTypes.bool,         // 表格加载中
    refreshdata: PropTypes.func,     // 表格中排序列、页码的变化时刷新
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    data: [],
    edData: [],
    edColumns: [],
    tableId: '',          // 表格ID
    pageIndex: 1,         // 初始页面索引
    pageSize: 10,         // 每页数据条数
    columns: null,        // 显示列
    fields: [],
    pickup: false,        // 收起未选择项
    orderfields: {},      // 排序id与field转换
    loading: false
  }
 
  UNSAFE_componentWillMount () {
    const { setting, fields, columns, data } = this.props
    let orderfields = {}
    let initEditLine = null
    let edColumns = []
    let tableId = (() => {
      let uuid = []
      let _options = 'abcdefghigklmnopqrstuv'
      for (let i = 0; i < 19; i++) {
        uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
      }
      return uuid.join('')
    }) ()
 
    let _columns = []
    columns.forEach(item => {
      if (item.Hide === 'true') return
      if (item.type === 'index') {
        item.field = '$Index'
        item.type = 'text'
      }
 
      item.tableId = tableId
 
      if (!initEditLine && item.editable === 'true') {
        initEditLine = item
      }
 
      if (item.marks && item.marks.length === 0) {
        item.marks = ''
      }
 
      if (item.field) {
        orderfields[item.uuid] = item.field
      }
 
      let _item = {
        align: item.Align,
        dataIndex: item.uuid,
        title: item.label,
        sorter: item.field && item.IsSort === 'true',
        width: item.Width || 120,
        onCell: record => ({
          record,
          col: item,
          config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
        })
      }
 
      if (item.type !== 'action') {
        let _copy = fromJS(_item).toJS()
        _copy.sorter = false
        edColumns.push(_copy)
      }
      _columns.push(_item)
    })
 
    edColumns.push({
      align: 'center',
      dataIndex: 'mkoperation',
      title: '操作',
      sorter: false,
      width: 100,
      onCell: record => ({
        record,
        col: {type: 'operation', tableId: tableId},
      })
    })
 
    if (setting.borderColor) { // 边框颜色
      let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}`
      let ele = document.createElement('style')
      ele.innerHTML = style
      document.getElementsByTagName('head')[0].appendChild(ele)
    }
 
    this.setState({
      data,
      columns: _columns,
      edColumns,
      tableId,
      orderfields,
      initEditLine
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentDidMount () {
    const { fields, columns } = this.props
 
    let _fields = []
 
    let fieldType = {}
    fields.forEach(item => {
      fieldType[item.field] = item.datatype
    })
 
    columns.forEach(col => {
      if (!col.field || col.type === 'index') return
 
      _fields.push({...col, datatype: fieldType[col.field] || 'Nvarchar(50)'})
    })
 
    this.setState({
      fields: _fields,
    })
 
    MKEmitter.addListener('nextLine', this.nextLine)
    MKEmitter.addListener('delRecord', this.delRecord)
    MKEmitter.addListener('resetTable', this.resetTable)
    MKEmitter.addListener('changeRecord', this.changeRecord)
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('nextLine', this.nextLine)
    MKEmitter.removeListener('delRecord', this.delRecord)
    MKEmitter.removeListener('resetTable', this.resetTable)
    MKEmitter.removeListener('changeRecord', this.changeRecord)
  }
 
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (!is(fromJS(this.props.data), fromJS(nextProps.data))) {
      this.setState({data: nextProps.data || []})
    }
  }
  
  nextLine = (col, index) => {
    const { setting } = this.props
    const { edData, initEditLine, tableId } = this.state
 
    if (col.tableId !== tableId) return
 
    index = +index
 
    if (index < edData.length && initEditLine) {
      MKEmitter.emit('tdFocus', initEditLine.uuid + (index + 1))
    } else if (col.footEnter === 'add' && setting.addable === 'true') {
      setTimeout(() => {
        this.plusLine(initEditLine)
      }, 10)
    } else if (col.footEnter === 'sub') {
      setTimeout(() => {
        this.checkData()
      }, 10)
    }
  }
 
  plusLine = (initEditLine) => {
    const { edData, fields } = this.state
 
    let item = {...edData[edData.length - 1]}
 
    item.key = item.key + 1
    item.$$uuid = '$new'
    item.$Index = item.key + 1 + ''
 
    fields.forEach(col => {
      item[col.field] = item[col.field] !== undefined ? item[col.field] : ''
 
      if (col.initval !== '$copy') {
        item[col.field] = col.initval
      }
      if (col.type === 'number') {
        item[col.field] = +item[col.field]
        if (isNaN(item[col.field])) {
          item[col.field] = 0
        }
      }
    })
 
    this.setState({edData: [...edData, item]}, () => {
      MKEmitter.emit('tdFocus', initEditLine.uuid + item.$Index)
    })
  }
 
  delRecord = (id, record) => {
    const { tableId, edData } = this.state
 
    if (id !== tableId) return
 
    let _data = []
 
    if (record.$$uuid === '$new') {
      _data = edData.filter(item => item.$Index !== record.$Index)
      _data = _data.map((item, index) => {
        item.key = index
        item.$Index = 1 + index + ''
        return item
      })
    } else {
      _data = edData.map(item => {
        if (item.$Index === record.$Index) {
          record.$deleted = true
          return record
        } else {
          return item
        }
      })
    }
 
    this.setState({edData: _data})
  }
 
  changeRecord = (id, record) => {
    const { tableId } = this.state
 
    if (id !== tableId) return
 
    let _data = this.state.edData.map(item => {
      if (item.$Index === record.$Index) {
        return record
      } else {
        return item
      }
    })
 
    this.setState({edData: _data})
  }
 
  addLine = () => {
    const { BID } = this.props
    const { edData, fields } = this.state
 
    let item = {}
    if (edData.length > 0) {
      item = {...edData[edData.length - 1]}
      item.key = item.key + 1
      item.$$uuid = '$new'
      item.$Index = item.key + 1 + ''
    } else {
      item.key = 0
      item.$$uuid = '$new'
      item.$Index = item.key + 1 + ''
      item.$$BID = BID || ''
    }
 
    fields.forEach(col => {
      item[col.field] = item[col.field] !== undefined ? item[col.field] : ''
 
      if (col.initval !== '$copy') {
        item[col.field] = col.initval
      }
      if (col.type === 'number') {
        item[col.field] = +item[col.field]
        if (isNaN(item[col.field])) {
          item[col.field] = 0
        }
      }
    })
 
    this.setState({edData: [...edData, item]})
  }
 
  checkData = () => {
    const { edData, fields } = this.state
 
    if (edData.length === 0) {
      notification.warning({
        top: 92,
        message: '提交数据不可为空!',
        duration: 5
      })
      return
    }
    let err = ''
    let data = fromJS(edData).toJS().map(item => {
      let line = []
      fields.forEach(col => {
        if (col.editable !== 'true' || item.$deleted) {
          if (col.type === 'number') {
            item[col.field] = +item[col.field]
            if (isNaN(item[col.field])) {
              item[col.field] = 0
            }
          } else {
            item[col.field] = item[col.field] !== undefined ? (item[col.field] + '') : ''
          }
          return
        }
        if (col.type === 'text') {
          let val = item[col.field] !== undefined ? (item[col.field] + '') : ''
          if (col.required === 'true' && !val) {
            line.push(`${col.label}不可为空`)
          }
          item[col.field] = val
        } else if (col.type === 'number') {
          let val = item[col.field]
          if (!val && val !== 0) {
            line.push(`${col.label}不可为空`)
            return
          }
          val = +val
          if (isNaN(val)) {
            line.push(`${col.label}数据格式错误`)
            return
          }
 
          val = +val.toFixed(col.decimal || 0)
          
          if (typeof(col.max) === 'number' && val > col.max) {
            line.push(`${col.label}不可大于${col.max}`)
          } else if (typeof(col.min) === 'number' && val < col.min) {
            line.push(`${col.label}不可小于${col.min}`)
          }
 
          item[col.field] = val
        }
      })
 
      if (line.length > 0) {
        err += `第${item.$Index}行:` + line.join(',') + ';'
      }
 
      return item
    })
 
    if (err) {
      notification.warning({
        top: 92,
        message: err,
        duration: 5
      })
    } else {
      this.submit(data)
    }
  }
 
  submit = (data) => {
    const { submit, BID } = this.props
    const { fields } = this.state
 
    let result = getEditTableSql(submit, data, fields)
 
    let param = {
      excel_in: result.lines,
      BID: BID || ''
    }
 
    this.setState({
      loading: true
    })
 
    if (submit.intertype === 'system') { // 系统存储过程
      param.func = 'sPC_TableData_InUpDe'
      
      if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
        result.sql = result.sql.replace(/\$@/ig, '/*')
        result.sql = result.sql.replace(/@\$/ig, '*/')
        result.bottom = result.bottom.replace(/\$@/ig, '/*')
        result.bottom = result.bottom.replace(/@\$/ig, '*/')
      } else {
        result.sql = result.sql.replace(/@\$|\$@/ig, '')
        result.bottom = result.bottom.replace(/@\$|\$@/ig, '')
      }
      
      param.excel_in_type = 'true'
      param.LText1 = Utils.formatOptions(result.insert)
      param.LText2 = Utils.formatOptions(result.bottom)
      param.LText = Utils.formatOptions(result.sql)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
      param.menuname = submit.logLabel
 
      if (window.GLOB.probation) {
        param.s_debug_type = 'Y'
      }
 
      Api.genericInterface(param).then((res) => {
        if (res.status) {
          this.execSuccess(res)
        } else {
          this.execError(res)
        }
      }, () => {
        this.execError({})
      })
    } else if (submit.intertype === 'inner' && submit.innerFunc) { // 自定义存储过程
      param.func = submit.innerFunc
 
      Api.genericInterface(param).then((res) => {
        if (res.status) {
          this.execSuccess(res)
        } else {
          this.execError(res)
        }
      }, () => {
        this.execError({})
      })
    }
  }
 
  execSuccess = (res) => {
    const { submit } = this.props
 
    if (res && res.ErrCode === 'S') { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
        duration: submit.stime ? submit.stime : 2
      })
    } else if (res && res.ErrCode === 'Y') { // 执行成功
      Modal.success({
        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
      })
    } else if (res && res.ErrCode === '-1') { // 完成后不提示
 
    }
 
    this.setState({
      loading: false
    })
 
    if (submit.execSuccess !== 'never') {
      this.repick()
      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
    }
  }
 
  execError = (res) => {
    const { submit } = this.props
 
    if (res.ErrCode === 'E') {
      Modal.error({
        title: res.message || res.ErrMesg,
      })
    } else if (res.ErrCode === 'N') {
      notification.error({
        top: 92,
        message: res.message || res.ErrMesg,
        duration: submit.ntime ? submit.ntime : 10
      })
    } else if (res.ErrCode === 'F') {
      notification.error({
        className: 'notification-custom-error',
        top: 92,
        message: res.message || res.ErrMesg,
        duration: submit.ftime ? submit.ftime : 10
      })
    } else if (res.ErrCode === 'NM') {
      message.error(res.message || res.ErrMesg)
    }
    
    this.setState({
      loading: false
    })
 
    if (submit.execError !== 'never') {
      this.repick()
      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit)
    }
  }
 
  repick = () => {
    const { data } = this.state
 
    this.setState({
      data: [],
      edData: [],
      pickup: false,
    }, () => {
      this.setState({
        data: data,
      })
    })
  }
 
  changeTable = (pagination, filters, sorter) => {
    const { orderfields } = this.state
 
    this.setState({
      pageIndex: pagination.current,
      pageSize: pagination.pageSize
    })
 
    sorter.field = orderfields[sorter.field] || ''
 
    this.props.refreshdata(pagination, filters, sorter)
  }
 
  resetTable = (id, repage) => {
    const { MenuID } = this.props
 
    if (id !== MenuID) return
 
    if (repage !== 'false') {
      this.setState({
        pageIndex: 1
      })
    }
  }
 
  pickupChange = () => {
    const { data } = this.state
 
    let pickup = !this.state.pickup
 
    if (!pickup && !is(fromJS(data), fromJS(this.state.edData))) {
      const _this = this
      confirm({
        title: '数据已修改,确定放弃保存吗?',
        onOk() {
          _this.setState({
            data: [],
            edData: [],
            pickup
          }, () => {
            _this.setState({
              data: data,
              edData: pickup ? fromJS(data).toJS() : []
            })
          })
        },
        onCancel() {}
      })
    } else {
      this.setState({
        data: [],
        edData: [],
        pickup,
        loading: false
      }, () => {
        this.setState({
          data: data,
          edData: pickup ? fromJS(data).toJS() : []
        })
      })
    }
  }
 
  render() {
    const { setting, statFValue, lineMarks } = this.props
    const { pickup, tableId, data, edData, columns, edColumns, loading } = this.state
 
    const components = {
      body: {
        row: BodyRow,
        cell: BodyCell
      }
    }
 
    // 数据收起时,过滤已选数据
    let _data = data
    let _columns = columns
 
    if (pickup) {
      _data = edData
      _data = _data.filter(item => !item.$deleted)
      _columns = edColumns
    }
 
    let _pagination = false
    if (!pickup && setting.laypage !== 'false' && setting.laypage !== false) {
      _pagination = {
        current: this.state.pageIndex,
        pageSize: this.state.pageSize,
        pageSizeOptions: ['10', '25', '50', '100', '500', '1000'],
        showSizeChanger: true,
        total: this.props.total || 0,
        showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}`
      }
    }
 
    let _footer = ''
 
    if (!pickup && statFValue && statFValue.length > 0) {
      _footer = statFValue.map(f => `${f.label}(合计):${f.value}`).join(';')
    }
 
    let height = setting.height || false
 
    return (
      <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}>
        <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} />
        {pickup ? <Button onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null}
        <Table
          components={components}
          style={setting.style}
          size={setting.size || 'middle'}
          bordered={setting.bordered !== 'false'}
          columns={_columns}
          dataSource={_data}
          loading={this.props.loading}
          scroll={{ x: '100%', y: height }}
          onRow={(record, index) => {
            return {
              lineMarks,
              data: record
            }
          }}
          onChange={this.changeTable}
          pagination={_pagination}
        />
        {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
        {pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281'}} icon="plus" type="link"></Button> : null}
      </div>
    )
  }
}
 
export default NormalTable