king
2023-09-08 783ab4e467c95e26f7f031151507bd7ad8333a63
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
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { notification, Spin, Tabs, Switch, Row, Col, Modal } from 'antd'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import { updateCommonTable } from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import MkIcon from '@/components/mk-icon'
import MKEmitter from '@/utils/events.js'
import NotFount from '@/components/404'
import './index.scss'
 
// 通用组件
const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
const MainAction = asyncSpinComponent(() => import('@/tabviews/zshare/actionList'))
const MainTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable'))
const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
const SubTable = asyncSpinComponent(() => import('@/tabviews/subtable'))
const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent'))
const DebugTable = asyncComponent(() => import('@/tabviews/debugtable'))
 
const { TabPane } = Tabs
 
class NormalTable extends Component {
  static propTpyes = {
    param: PropTypes.any,        // 其他页面传递的搜索条件等参数
    MenuID: PropTypes.string,    // 菜单Id
    MenuNo: PropTypes.string,    // 菜单参数
    MenuName: PropTypes.string,  // 菜单名称
    changeTemp: PropTypes.func
  }
 
  state = {
    ContainerId: Utils.getuuid(), // 菜单外层html Id
    BID: null,            // 页面跳转时携带ID
    loadingview: true,    // 页面加载中
    viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
    lostmsg: '',          // 页面丢失时的提示信息
    config: {},           // 页面配置信息,包括按钮、搜索、显示列、标签等
    shortcuts: null,      // 快捷键
    actions: null,        // 按钮集
    columns: null,        // 显示列
    setting: null,        // 页面全局设置:数据源、按钮及显示列固定、主键等
    data: [],             // 列表数据集
    selectedData: [],     // 已选表格数据
    total: 0,             // 总数
    loading: false,       // 列表数据加载中
    pageIndex: 1,         // 页码
    pageSize: 10,         // 每页数据条数
    orderBy: '',          // 排序
    search: '',           // 搜索条件数组,使用时需分场景处理
    BIDs: {},             // 上级表id
    pickup: false,        // 主表数据隐藏显示切换
    chartId: '',          // 展开图表ID
    statFields: [],       // 合计字段
    statFValue: [],       // 合计值
    absFields: [],        // 绝对值字段
    autoMatic: null,
    visible: false
  }
 
  /**
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { param, MenuName, MenuID } = this.props
 
    let _param = {
      func: 'sPC_Get_LongParam',
      MenuID: MenuID
    }
    let result = await Api.getCacheConfig(_param)
 
    if (result.status) {
      let config = ''
      let shortcuts = []
 
      try { // 配置信息解析
        config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
      } catch (e) {
        console.warn('Parse Failure')
        config = ''
      }
 
      // 页面配置解析错误时提示
      if (!config) {
        this.setState({
          loadingview: false,
          viewlost: true
        })
        return
      }
 
      // 页面未启用时,显示未启用页面
      if (!config.enabled) {
        this.setState({
          loadingview: false,
          viewlost: true,
          lostmsg: '抱歉,您访问的页面未启用,请联系管理员。'
        })
        return
      }
 
      // 模板错误
      if (config.Template === 'BaseTable' || config.Template === 'CustomPage') {
        this.props.changeTemp(MenuID, config.Template)
        return
      }
      
      // HS不使用自定义设置
      if (result.LongParamUser) {
        try { // 配置信息解析
          let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
          if (userConfig && !userConfig.version) {
            Object.keys(userConfig).forEach(key => {
              let component = userConfig[key]
 
              if (!component.action) return
 
              Object.keys(component.action).forEach(uuid => {
                let item = {uuid: uuid, parentId: key, shortcut: component.action[uuid].shortcut}
                let printer = component.action[uuid].printer
 
                if (item.shortcut) {
                  item.$shortcut = item.shortcut.join('+')
                  shortcuts.push(item)
                }
                if (printer) {
                  item.printer = printer.defaultPrinter || ''
                  item.printerList = printer.printerList || ''
                  window.GLOB.UserCacheMap.set(key + uuid, item)
                }
              })
            })
          } else if (userConfig) {
            shortcuts = userConfig.action
            userConfig.printers.forEach(item => {
              window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item)
            })
          }
        } catch (e) {
          console.warn('Parse Failure')
        }
      }
 
      // 信息初始化赋值
      config.MenuID = MenuID
      config.MenuName = MenuName
      config.setting.MenuName = MenuName
      config.setting.$name = MenuName
 
      // 版本兼容
      config = updateCommonTable(config)
 
      // 权限过滤
      if (!window.GLOB.mkHS) {
        config.action = config.action.filter(item => item.hidden !== 'true' && window.GLOB.mkActions[item.uuid])
        config.tabgroups.forEach(group => {
          group.sublist = group.sublist.filter(tab => {
            if (tab.supMenu === 'mainTable') {
              tab.supMenu = MenuID
            }
            tab.ContainerId = this.state.ContainerId
 
            // return window.GLOB.mkActions[tab.linkTab]
            return tab
          })
        })
      } else {
        config.action = config.action.filter(item => item.hidden !== 'true')
        config.tabgroups.forEach(group => {
          group.sublist = group.sublist.map(tab => {
            if (tab.supMenu === 'mainTable') {
              tab.supMenu = MenuID
            }
            tab.ContainerId = this.state.ContainerId
 
            return tab
          })
        })
      }
      // 去除空行标签
      config.tabgroups = config.tabgroups.filter(group => group.sublist.length > 0)
 
      let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
 
      let chartId = ''
 
      if (config.charts) {
        // 视图权限
        config.charts = config.charts.filter(item => {
          if (item.Hide === 'true') return false
          if (!item.blacklist || item.blacklist.length === 0) return true
          return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0
        })
  
        if (config.charts.length <= 1) {
          config.expand = true
        }
        chartId = config.charts[0] ? config.charts[0].uuid : ''
      }
 
      Utils.initSearchVal(config)
 
      // 字段透视及必填标志
      config.search = config.search.map(item => {
        if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) {
          item.initval = param.$searchval
        }
        return item
      })
 
      config.columns = config.columns.map(col => {
        if (!col.field || !col.blacklist || col.blacklist.length === 0) return col
        if (col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
          col.Hide = 'true'
        }
 
        return col
      })
 
      // 标记主页面,用于按钮固定及表单挂载设置
      config.setting.tabType = 'main'
      config.setting.ContainerId = this.state.ContainerId
 
      // 数据源信息预处理
      config.setting.laypage = config.setting.laypage !== 'false'     // 是否分页,转为boolean 统一格式
      config.setting.execute = config.setting.default !== 'false'     // 默认sql是否执行,转为boolean 统一格式
      config.setting.customScript = ''                                // 自定义脚本
      config.setting.dataresource = config.setting.dataresource || ''
 
      if (config.setting.interType === 'system') {
        if (config.setting.scripts && config.setting.scripts.length > 0) {
          let _customScript = ''
          config.setting.scripts.forEach(item => {
            if (item.status === 'false') return
            _customScript += `
              ${item.sql}
            `
          })
          config.setting.customScript = _customScript
        }
  
        if (!config.setting.execute) { // 默认sql 不执行时 置空
          config.setting.dataresource = ''
        } else if (/\s/.test(config.setting.dataresource)) {
          config.setting.dataresource = '(' + config.setting.dataresource + ') tb'
        }
  
        if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
          config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/')
          config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/')
        } else {
          config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '')
          config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '')
        }
 
        let userName = sessionStorage.getItem('User_Name') || ''
        let fullName = sessionStorage.getItem('Full_Name') || ''
 
        let regs = [
          { reg: /@userName@/ig, value: `'${userName}'` },
          { reg: /@fullName@/ig, value: `'${fullName}'` }
        ]
 
        regs.forEach(cell => {
          config.setting.dataresource = config.setting.dataresource.replace(cell.reg, cell.value)
          config.setting.customScript = config.setting.customScript.replace(cell.reg, cell.value)
        })
 
        if (config.urlFields) {
          let _param = param || {}
          config.urlFields.forEach(field => {
            let reg = new RegExp('@' + field + '@', 'ig')
            let val = `'${_param[field] || ''}'`
            config.setting.dataresource = config.setting.dataresource.replace(reg, val)
            config.setting.customScript = config.setting.customScript.replace(reg, val)
          })
        }
      }
 
      let _arrField = []     // 字段集
      let _columns = []      // 显示列
      let _hideCol = []      // 隐藏及合并列中字段的uuid集
      let colMap = new Map() // 用于字段过滤
      let statFields = []    // 合计字段信息
      let absFields = []     // 绝对值字段
 
      let _actions = []      // 工具栏按钮
      let _operations = []   // 操作列按钮(存在时)
 
      config.action.forEach(item => {
        item.logLabel = MenuName + '-' + item.label // 用于sPC_TableData_InUpDe记录操作按钮
        item.$menuId = this.props.MenuID
        item.$old = true
        item.ContainerId = this.state.ContainerId
 
        if (item.OpenType === 'excelOut') { // 导出
          item.$menuName = MenuName
    
          if (!item.verify || !item.verify.columns || item.verify.columns.length === 0) {
            item.errorType = 'error1'
          } else if (item.intertype === 'system' && item.verify.dataType !== 'custom' && config.setting.interType !== 'system') {
            item.errorType = 'error2'
          }
        }
 
        if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify) { // 打印机设置
          let _item = window.GLOB.UserCacheMap.get(this.props.MenuID + item.uuid)
 
          if (_item) {
            item.printer = _item.printer || ''
            item.verify.defaultPrinter = _item.printer || ''
            if (item.verify.printerTypeList && _item.printerList) {
              item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
                cell.printer = _item.printerList[cell.Value] || ''
  
                return cell
              })
            }
          }
        }
 
        if (item.controlField) {
          if (/,/ig.test(item.controlVal)) {
            item.controlVals = item.controlVal.split(',')
          } else {
            item.controlVals = [(item.controlVal || '')]
          }
        }
        
        if (item.position === 'toolbar') {
          item.$toolbtn = true
          _actions.push(item)
        } else if (item.position === 'grid') {
          _operations.push(item)
        }
      })
 
      // 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
      config.columns.forEach(col => {
        if (col.field) {
          _arrField.push(col.field)
 
          if (col.linkmenu && col.linkmenu.length > 0) {
            let menu_id = col.linkmenu.slice(-1)[0]
            col.linkThdMenu = window.GLOB.mkThdMenus.get(menu_id) || ''
          } else {
            col.linkThdMenu = ''
          }
 
          if (col.type === 'number') {
            col.decimal = col.decimal || 0
            col.round = Math.pow(10, col.decimal)
 
            if (col.format === 'percent') {
              col.decimal = col.decimal > 2 ? col.decimal - 2 : 0
            }
          }
 
          col.nameField && _arrField.push(col.nameField) // 链接名字段
          if (col.Hide !== 'true' && col.type === 'number' && col.sum === 'true') {
            statFields.push(col)
          }
          if (col.format === 'abs') {
            absFields.push(col.field)
          }
        }
        if (col.type === 'colspan' && col.sublist) { // 筛选隐藏列
          _hideCol = _hideCol.concat(col.sublist)
        }
        colMap.set(col.uuid, col)
      })
 
      // 生成显示列,处理合并列中的字段
      config.columns.forEach((col, index) => {
        if (_hideCol.includes(col.uuid)) return
 
        col.sort = index
 
        if (col.type === 'colspan') {
          if (col.unfold !== 'true') { // 不展开为旧版合并列
            col.type = 'old_colspan'
          }
 
          let _col = fromJS(col).toJS()
          let subcols = []
          _col.sublist && _col.sublist.forEach(sub => {
            if (colMap.has(sub)) {
              subcols.push(colMap.get(sub))
            }
          })
          if (subcols.length > 0) {
            _col.subcols = subcols
            _columns.push(_col)
          }
        } else {
          _columns.push(col)
        }
      })
      
      if (config.gridBtn && config.gridBtn.display && _operations.length > 0) {
        config.gridBtn.operations = _operations
        _columns.push(config.gridBtn)
      }
 
      if (config.setting.selected !== 'init' && config.setting.selected !== 'always') {
        config.setting.selected = 'false'
      } else if (config.setting.selected === 'init' && config.setting.onload === 'false') {
        config.setting.selected = 'false'
      } else {
        config.setting.orisel = true
      }
 
      let autoMatic = null
      if (config.autoMatic && config.autoMatic.enable === 'true') {
        _actions.forEach(item => {
          if (item.uuid === config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))) {
            autoMatic = config.autoMatic
            autoMatic.OpenType = item.execMode || item.OpenType
            config.setting.selected = 'false'
            item.autoMatic = true
          }
        })
      }
 
      if (config.setting.controlField) {
        if (config.setting.controlVal) {
          config.setting.controlVal = config.setting.controlVal.split(',')
        } else {
          config.setting.controlVal = ['']
        }
      }
 
      config.type = 'table'
      config.wrap = {
        show: config.setting.show || '',
        float: config.setting.float || '',
        advanceType: config.setting.advanceType || '',
        advanceWidth: config.setting.advanceWidth || '',
        drawerPlacement: config.setting.drawerPlacement || '',
        searchRatio: config.setting.searchRatio || '',
        searchLwidth: config.setting.searchLwidth,
        borderRadius: config.setting.borderRadius,
        resetContrl: config.setting.resetContrl,
      }
 
      config.setting.arr_field = _arrField.join(',')
 
      this.setState({
        pageSize: config.setting.pageSize || 10,
        loadingview: false,
        absFields,
        autoMatic,
        chartId,
        config,
        statFields,
        shortcuts: shortcuts.length > 0 ? shortcuts : null,
        setting: config.setting,
        actions: _actions,
        columns: _columns,
        BID: param && param.$BID ? param.$BID : '',
        search: Utils.initMainSearch(config.search)
      }, () => {
        if (config.setting.onload !== 'false') { // 初始化可加载
          this.loadData()
        }
        this.setShortcut()
      })
    } else {
      this.setState({
        loadingview: false,
        viewlost: true
      })
      notification.warning({
        top: 92,
        message: result.message,
        duration: 5
      })
    }
  }
 
  setShortcut = () => {
    const { shortcuts } = this.state
 
    document.onkeydown = (event) => {
      let e = event || window.event
      let keyCode = e.keyCode || e.which || e.charCode
      let preKey = ''
 
      if (e.ctrlKey) {
        preKey = 'ctrl'
      } else if (e.shiftKey) {
        preKey = 'shift'
      } else if (e.altKey) {
        preKey = 'alt'
      }
 
      if (!preKey || !keyCode) return
 
      let _shortcut = `${preKey}+${keyCode}`
 
      if (window.GLOB.breakpoint && _shortcut === 'ctrl+67') {
        window.GLOB.breakpoint = false
        sessionStorage.removeItem('breakpoint')
        
        MKEmitter.emit('debugChange')
      }
 
      if (!shortcuts) return
 
      shortcuts.some(item => {
        if (item.$shortcut === _shortcut) {
          MKEmitter.emit('triggerBtnId', item.uuid)
 
          let element = item.parentId && item.parentId !== this.props.MenuID ? document.getElementById(item.parentId) : '' // 标签切换
          if (element && element.click) {
            element.click()
          }
 
          return true
        }
        return false
      })
    }
  }
 
  loadData = (id) => {
    const { MenuID } = this.props
    const { setting, search, config, ContainerId } = this.state
 
    this.setState({
      selectedData: []
    })
    MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '')
 
    if (config.$s_req) {
      let requireFields = search.filter(item => item.required && item.value === '')
 
      if (requireFields.length > 0) {
        this.setState({
          loading: false
        })
        return
      }
    }
 
    if (setting.interType === 'custom') {
      notification.warning({
        top: 92,
        message: '系统不在支持自定义接口!',
        duration: 3
      })
      return
    }
 
    this.loadmaindata(id)
  }
 
  /**
   * @description 主表数据加载
   */ 
  async loadmaindata (id) {
    const { setting, search, orderBy, BID, pageIndex, pageSize, absFields, autoMatic } = this.state
 
    this.setState({
      loading: true
    })
 
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, search, _orderBy, pageIndex, pageSize, BID)
 
    let result = await Api.genericInterface(param)
 
    this.getStatFieldsValue()
 
    if (result.status) {
      let start = 1
      if (setting.laypage) {
        start = pageSize * (pageIndex - 1) + 1
      }
 
      if (setting.selected !== 'false' || (setting.orisel && id)) {
        setTimeout(() => {
          MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID, id)
        }, 200)
        if (setting.selected === 'init') {
          this.setState({setting: {...setting, selected: 'false'}})
        }
      }
 
      this.setState({
        data: result.data.map((item, index) => {
          if (absFields.length) {
            absFields.forEach(field => {
              if (!item[field]) return
              if (isNaN(Math.abs(item[field]))) return
 
              item[field] = Math.abs(item[field])
            })
          }
 
          item.key = index
          item.$$uuid = item[setting.primaryKey] || ''
          item.$$key = '' + item.key + item.$$uuid
          item.$$BID = BID || ''
          item.$Index = start + index + ''
 
          if (setting.controlField) {
            if (setting.controlVal.includes(item[setting.controlField] + '')) {
              item.$disabled = true
            }
          }
 
          return item
        }),
        total: result.total,
        loading: false,
        pickup: false
      })
 
      if (autoMatic) {
        if (result.data && result.data.length > 0) {
          MKEmitter.emit('autoGetData', this.props.MenuID)
        } else {
          MKEmitter.emit('autoMaticOver', this.props.MenuID)
        }
      }
    } else {
      this.setState({
        loading: false
      })
      if (autoMatic) {
        MKEmitter.emit('autoMaticError', this.props.MenuID)
      }
 
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
      }
    }
  }
 
  /**
   * @description 获取单行数据
   */ 
  async loadmainLinedata (id) {
    const { setting, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state
 
    this.setState({
      loading: true
    })
 
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, search, _orderBy, pageIndex, pageSize, BID, id)
 
    let result = await Api.genericInterface(param)
    if (result.status) {
      let data = fromJS(this.state.data).toJS()
      let selectedData = fromJS(this.state.selectedData).toJS()
      if (result.data && result.data[0]) {
        let _data = result.data[0] || {}
 
        if (absFields.length) {
          absFields.forEach(field => {
            if (!_data[field]) return
            if (isNaN(Math.abs(_data[field]))) return
            
            _data[field] = Math.abs(_data[field])
          })
        }
        _data.$$uuid = _data[setting.primaryKey] || ''
        _data.$$BID = BID || ''
 
        try {
          data = data.map(item => {
            if (item.$$uuid === _data.$$uuid) {
              _data.key = item.key
              _data.$$key = '' + item.key + item.$$uuid
              _data.$Index = item.$Index
              return _data
            } else {
              return item
            }
          })
          selectedData = selectedData.map(item => {
            if (_data.$$uuid === item.$$uuid) {
              return _data
            }
            return item
          })
        } catch (e) {
          console.warn('数据查询错误')
        }
      }
 
      this.setState({
        data,
        selectedData,
        loading: false
      })
    } else {
      this.setState({
        loading: false
      })
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
    }
  }
 
  /**
   * @description 获取合计字段值
   */
  getStatFieldsValue = () => {
    const { setting, search, BID, orderBy, statFields } = this.state
 
    if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return
 
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID)
 
    Api.genericInterface(param).then(res => {
      if (res.status) {
        let _data = res.data[0]
        let values = []
 
        if (_data) {
          statFields.forEach(item => {
            if (_data[item.field] || _data[item.field] === 0) {
              let val = +_data[item.field]
              if (isNaN(val)) {
                val = 0
              }
              val = val.toFixed(item.decimal)
              values.push({label: item.label, value: val})
            }
          })
        }
        this.setState({
          statFValue: values
        })
      } else {
        this.setState({
          statFValue: []
        })
        notification.error({
          top: 92,
          message: res.message,
          duration: 10
        })
      }
    })
  }
 
  /**
   * @description 搜索条件改变时,重置表格数据
   * 含有初始不加载的页面,修改设置
   */
  refreshbysearch = (searches) => {
    const { setting } = this.state
 
    if (setting.onload === 'false') {
      this.setState({
        pageIndex: 1,
        search: searches,
        setting: {...setting, onload: 'true'}
      }, () => {
        this.loadData()
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置
      this.setState({
        pageIndex: 1,
        search: searches
      }, () => {
        this.loadData()
      })
    }
  }
 
  /**
   * @description 表格条件改变时重置数据(分页或排序)
   */
  refreshbytable = (pagination, filters, sorter) => {
    if (!sorter) {
      this.setState({
        pageIndex: pagination.pageIndex
      }, () => {
        this.loadData()
      })
      return
    }
 
    if (sorter.order) {
      let _chg = {
        ascend: 'asc',
        descend: 'desc'
      }
      sorter.order = _chg[sorter.order]
    }
 
    this.setState({
      pageIndex: pagination.current,
      pageSize: pagination.pageSize,
      orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
    }, () => {
      this.loadData()
    })
  }
 
  /**
   * @description 表格刷新
   */
  reloadtable = (btn, id = '') => {
    if (!btn || btn.resetPageIndex !== 'false') {
      MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置
      this.setState({
        pageIndex: 1
      }, () => {
        this.loadData(id)
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID, 'false') // 列表重置
      this.loadData(id)
    }
  }
 
  /**
   * @description 页面刷新,重新获取配置
   */
  reloadview = () => {
    this.setState({ loadingview: true, viewlost: false, config: {}, setting: null,
      data: null, total: 0, loading: false, pageIndex: 1, shortcuts: null,
      pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false
    }, () => {
      this.loadconfig()
    })
  }
 
  /**
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  queryModuleParam = (menuId, callback) => {
    const { MenuID } = this.props
    const { orderBy, search, setting } = this.state
 
    if (MenuID !== menuId) return
 
    callback({
      orderBy: orderBy || setting.order,
      search: search
    })
  }
 
  /**
   * @description 表格选择项切换
   */
  changeSelectedData = (selectedData) => {
    this.setState({selectedData})
  }
  
  /**
   * @description 数据展开合并切换
   */
  pickupChange = () => {
    const { pickup } = this.state
    this.setState({
      pickup: !pickup
    })
  }
 
  /**
   * @description 图表视图切换
   */
  changeChart = (uuid) => {
    this.setState({chartId: uuid})
  }
 
  reloadData = (menuId, id, btn) => {
    const { MenuID } = this.props
 
    if (MenuID !== menuId) return
 
    if (id === 'formtab') { // 表单标签页刷新
      this.reloadtable(btn)
      return
    }
    
    if (!id) {
      this.reloadtable()
    } else {
      this.loadmainLinedata(id)
    }
  }
 
  reloadMenuView = (menuId, position) => {
    const { MenuID } = this.props
 
    if (MenuID !== menuId) return
 
    if (position === 'table') {
      this.reloadtable()
    } else {
      this.reloadview()
    }
  }
 
  resetActiveMenu = (menuId) => {
    const { MenuID } = this.props
 
    if (MenuID !== menuId) return
 
    this.setShortcut()
  }
 
  changeTableLine = (ContainerId, tableId, id, data) => {
    if (this.state.ContainerId !== ContainerId) return
 
    this.setState({
      BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data}
    })
  }
 
  /**
   * @description 按钮执行完成后页面刷新
   * @param {*} menuId     // 菜单Id
   * @param {*} position   // 刷新位置
   * @param {*} btn        // 执行的按钮
   */
  refreshByButtonResult = (menuId, position, btn, id, lines) => {
    const { MenuID } = this.props
 
    if (MenuID !== menuId) return
 
    if (position === 'line' && lines && lines.length === 1) {
      this.loadmainLinedata(lines[0].$$uuid)
    } else {
      this.reloadtable(btn, id)
    }
  }
 
  debugChange = () => {
    this.setState({visible: !this.state.visible})
  }
 
  UNSAFE_componentWillMount () {
    // 组件加载时,获取菜单数据
    this.loadconfig()
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('debugChange', this.debugChange)
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('changeTableLine', this.changeTableLine)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    document.onkeydown = () => {}
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('debugChange', this.debugChange)
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
  }
 
  render() {
    const { MenuID } = this.props
    const { BID, setting, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts } = this.state
 
    return (
      <div className="commontable" id={this.state.ContainerId}>
        {loadingview ? <Spin size="large" /> : null}
        {config && config.search && config.search.length ?
          <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
        }
        {setting && config.charts ? <Row className="chart-view" gutter={16}>
          {/* 视图组 */}
          {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
            {config.charts.map(item => (
              <TabPane tab={<MkIcon type={item.icon} />} key={item.uuid}></TabPane>
            ))}
          </Tabs> : null}
          {config.charts.map(item => {
            if (!config.expand && chartId !== item.uuid) return null
 
            if (item.chartType === 'table') {
              return (
                <Col span={item.width || 24} key={item.uuid}>
                  {config.charts.length > 1 && item.title ? <p className="chart-table chart-title">{item.title}</p> : null}
                  <div className="commontable-main-action">
                    <MainAction
                      BID={BID}
                      setting={setting}
                      actions={actions}
                      columns={columns}
                      MenuID={MenuID}
                      selectedData={selectedData}
                    />
                  </div>
                  <div className="main-table-box">
                    {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
                      <Switch title="收起" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> : null
                    }
                    <MainTable
                      MenuID={MenuID}
                      tableId={MenuID}
                      pickup={pickup}
                      setting={setting}
                      columns={columns}
                      pageSize={pageSize}
                      data={this.state.data}
                      total={this.state.total}
                      loading={this.state.loading}
                      statFValue={this.state.statFValue}
                      refreshdata={this.refreshbytable}
                      chgSelectData={this.changeSelectedData}
                    />
                  </div>
                </Col>
              )
            } else if (item.chartType === 'card') {
              return (
                <Col className="card-view" span={item.width} key={item.uuid}>
                  <CardComponent
                    BID={BID}
                    plot={item}
                    MenuID={MenuID}
                    config={config}
                    tableId={MenuID}
                    columns={columns}
                    data={this.state.data}
                    loading={this.state.loading}
                  />
                </Col>
              )
            } else {
              return (
                <Col span={item.width} key={item.uuid}>
                  <ChartComponent
                    BID={BID}
                    plot={item}
                    config={config}
                    data={this.state.data}
                    loading={this.state.loading}
                  />
                </Col>
              )
            }
          })}
        </Row> : null }
        {setting && !config.charts ? <div className="chart-view">
          <div className="commontable-main-action">
            <MainAction
              BID={BID}
              setting={setting}
              actions={actions}
              columns={columns}
              MenuID={MenuID}
              selectedData={selectedData}
            />
          </div>
          <div className="main-table-box">
            {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
              <Switch title="收起" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> : null
            }
            <MainTable
              MenuID={MenuID}
              tableId={MenuID}
              pickup={pickup}
              setting={setting}
              columns={columns}
              pageSize={pageSize}
              data={this.state.data}
              total={this.state.total}
              loading={this.state.loading}
              statFValue={this.state.statFValue}
              refreshdata={this.refreshbytable}
              chgSelectData={this.changeSelectedData}
            />
          </div>
        </div> : null }
        {setting && config.tabgroups.map(group => (
          <Tabs key={group.uuid}>
            {group.sublist.map(_tab => {
              return (
                <TabPane tab={
                  <span id={_tab.uuid}>
                    {_tab.icon ? <MkIcon type={_tab.icon} /> : null}
                    {_tab.label}
                  </span>
                } key={_tab.uuid}>
                  <SubTable
                    Tab={_tab}
                    SupMenuID={MenuID}
                    MenuID={_tab.linkTab}
                    mainSearch={_tab.searchPass === 'true' ? search : null}
                    BID={this.state.BIDs[_tab.supMenu] || ''}
                    BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
                  />
                </TabPane>
              )
            })}
          </Tabs>))
        }
        {setting && window.GLOB.breakpoint ? <DebugTable /> : null}
        {setting ? <SettingComponent config={config} shortcuts={shortcuts || []}/> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )
  }
}
 
export default NormalTable