4
hao
2025-04-16 c5fb1fbcbb2bf4d511773d348f9ef625855c61fc
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
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
/**
 
 @Name:tablePlug 表格拓展插件
 @Author:岁月小偷
 @License:MIT
 @version 2.5.5
 
 */
layui.define(['table'], function (exports) {
  "use strict";
 
  var version = '2.5.5-preview01';
  var modelName = 'tablePlug'; // 插件名称,支持自己定义,但是不建议
  var pathTemp = layui.cache.modules[modelName] || ''; // 正常情况下不会出现未定义的情况
  var filePath = pathTemp.substr(0, pathTemp.lastIndexOf('/'));
  // 引入tablePlug.css
  layui.link(filePath + '/tablePlug.css?v' + version);
  // 引入图标文件
  layui.link(filePath + '/icon/iconfont.css?v' + version);
 
  var $ = layui.$
    , laytpl = layui.laytpl
    , laypage = layui.laypage
    , layer = layui.layer
    , form = layui.form
    , util = layui.util
    , table = layui.table
    , hint = layui.hint()
    , device = layui.device();
 
  if (!form.render.plugFlag) {
    // 只要未改造过的才需要改造一下
    // 保留一下原始的form.render
    var formRender = form.render;
    form.render = function (type, filter, jqObj) {
      var that = this;
      var retObj;
      if (jqObj) {
        layui.each(jqObj, function (index, elem) {
          elem = $(elem);
          var elemP = elem.parent();
          var formFlag = elemP.hasClass('layui-form');
          var filterTemp = elemP.attr('lay-filter');
          // mark一下当前的
          formFlag ? '' : elemP.addClass('layui-form');
          filterTemp ? '' : elemP.attr('lay-filter', 'tablePlug_form_filter_temp_' + new Date().getTime() + '_' + Math.floor(Math.random() * 100000));
          // 将焦点集中到要渲染的这个的容器上
          retObj = formRender.call(that, type, elemP.attr('lay-filter'));
          // 恢复现场
          formFlag ? '' : elemP.removeClass('layui-form');
          filterTemp ? '' : elemP.attr('lay-filter', null);
        });
      } else {
        retObj = formRender.call(that, type, filter);
      }
      return retObj;
    };
    form.render.plugFlag = true;
  }
 
  // 异步地将独立功能《优化layui的select的选项设置》引入
  layui.extend({optimizeSelectOption: '{/}' + filePath + '/optimizeSelectOption/optimizeSelectOption'}).use('optimizeSelectOption');
 
  var layuiVersion = '2.5.5' // 基于2.5.5开发的
    // 检测是否满足智能重载的条件 检测是否修改了源码将构造出还有thisTable透漏出来
    , checkSmartReloadCodition = (function () {
      if (layui.device().ie && parseInt(layui.device().ie) < 9) {
        console.warn('tablePlug插件暂时不支持ie9以下的ie浏览器,如果需要支持可自行调试,一般就是一些数组的方法ie8没有还有一个重要的就是window.parent这些支持不好,在getPosition的时候会死循环,如果有这方面相关的经验有处理方法请分享给俺,谢谢。')
      }
      if (table.thisTable && table.Class) {
        // console.info('欢迎使用tablePlug插件,使用过程中有任何问题或者有什么建议都可以到码云上新建issues', 'https://gitee.com/sun_zoro/layuiTablePlug');
        return true;
      } else {
        console.error(table.thisTable+"--------"+table.Class);
        console.error('如果要使用该插件(tablePlug),参照readme.md的说明修改layui的table模块的代码,目前该组件是基于layui-V' + layuiVersion, 'https://gitee.com/sun_zoro/layuiTablePlug');
        return false;
      }
    })()
    , tablePlug = {
      version: version // tablePlug的版本后面提交的时候会更新也好知道使用的是不是同一个版本
    }
    , tableIns = {}
    , CHECK_TYPE_ADDITIONAL = 'additional'  // 新增的
    , CHECK_TYPE_REMOVED = 'removed'  // 删除的
    , CHECK_TYPE_ORIGINAL = 'original' // 原有的
    , CHECK_TYPE_DISABLED = 'disabled' // 不可选的
    , FIXED_SCROLL = 'layui-table-fixed-scroll'
 
    //解析自定义模板数据
    ,parseTempData = function(item3, content, tplData, text){
      var str = item3.templet ? function(){
        return typeof item3.templet === 'function'
          ? item3.templet(tplData)
          : laytpl($(item3.templet).html() || String(content)).render(tplData)
      }() : content;
      return text ? $('<div>'+ str +'</div>').text() : str;
    }
 
    , ELEM_VIEW = 'layui-table-view', ELEM_TOOL = '.layui-table-tool', ELEM_BOX = '.layui-table-box',
    ELEM_INIT = '.layui-table-init', ELEM_HEADER = '.layui-table-header', ELEM_BODY = '.layui-table-body',
    ELEM_MAIN = '.layui-table-main', ELEM_FIXED = '.layui-table-fixed', ELEM_FIXL = '.layui-table-fixed-l',
    ELEM_FIXR = '.layui-table-fixed-r', ELEM_TOTAL = '.layui-table-total', ELEM_PAGE = '.layui-table-page',
    ELEM_SORT = '.layui-table-sort', ELEM_EDIT = 'layui-table-edit', ELEM_HOVER = 'layui-table-hover'
    , NONE = 'layui-none'
    , HIDE = 'layui-hide'
    // , LOADING = 'layui-tablePlug-loading-p'
    , ELEM_CLICK = 'layui-table-click'
    , COLGROUP = 'colGroup' // 定义一个变量,方便后面如果table内部有变化可以对应的修改一下即可
    , tableSpecialColType = ['numbers', 'checkbox', 'radio'] // 表格的特殊类型字段
    , LayuiTableColFilter = [
      '<span class="layui-table-filter layui-inline">',
      '<span class="layui-tablePlug-icon layui-tablePlug-icon-filter"></span>',
      '</span>'
    ]
    , filterLayerIndex // 保存打开字段过滤的layer的index
    , getIns = function (id) {
      return table.thisTable.that[id];
    }
 
    , tableCheck = function () {
      var checked = {};
      return {
        // 检验是否可用,是否初始化过
        check: function (tableId) {
          return !!checked[tableId];
        },
        reset: function (tableId) {
          if (!checked[tableId]) {
            checked[tableId] = {};
            checked[tableId][CHECK_TYPE_ORIGINAL] = [];
            checked[tableId][CHECK_TYPE_ADDITIONAL] = [];
            checked[tableId][CHECK_TYPE_REMOVED] = [];
            checked[tableId][CHECK_TYPE_DISABLED] = [];
          } else {
            this.set(tableId, CHECK_TYPE_ADDITIONAL, []);    // 新增的
            this.set(tableId, CHECK_TYPE_REMOVED, []);       // 删除的
          }
        },
        init: function (tableId, data, primaryKey) {
          this.reset(tableId);
          var ids = [];
          if (data && data.length && typeof data[0] === 'object') {
            // 如果data是对象数组
            ids = addCacheData(tableId, data, primaryKey);
          } else {
            ids = data;
          }
          this.set(tableId, CHECK_TYPE_ORIGINAL, ids);
        },
        // 设置部分记录不可选
        disabled: function (tableId, data) {
          if (!checked[tableId]) {
            this.reset(tableId);
          }
          this.set(tableId, CHECK_TYPE_DISABLED, data);
        },
        checkDisabled: function (tableId, value) {
          return this.get(tableId, CHECK_TYPE_DISABLED).indexOf(value) !== -1;
        },
        // 获得当前选中的,不区分状态
        getChecked: function (tableId) {
          var delArr = this.get(tableId, CHECK_TYPE_REMOVED);
 
          var retTemp = this.get(tableId, CHECK_TYPE_ORIGINAL).concat(this.get(tableId, CHECK_TYPE_ADDITIONAL));
          var ret = [];
          layui.each(retTemp, function (index, data) {
            if (delArr.indexOf(data) === -1 && ret.indexOf(data) === -1) {
              ret.push(data);
            }
          });
          return ret;
        },
        get: function (tableId, type) {
          if (type === CHECK_TYPE_ADDITIONAL
            || type === CHECK_TYPE_REMOVED
            || type === CHECK_TYPE_ORIGINAL
            || type === CHECK_TYPE_DISABLED) {
            return checked[tableId] ? (checked[tableId][type] || []) : [];
          } else {
            return checked[tableId];
          }
        },
        set: function (tableId, type, data) {
          if (type !== CHECK_TYPE_ORIGINAL
            && type !== CHECK_TYPE_ADDITIONAL
            && type !== CHECK_TYPE_REMOVED
            && type !== CHECK_TYPE_DISABLED) {
            return;
          }
          checked[tableId][type] = (!data || !isArray(data)) ? [] : data;
        },
        update: function (tableId, id, checkedStatus, isRadio) {
          var _original = checked[tableId][CHECK_TYPE_ORIGINAL];
          var _additional = checked[tableId][CHECK_TYPE_ADDITIONAL];
          var _removed = checked[tableId][CHECK_TYPE_REMOVED];
          if (checkedStatus) {
            // 单选的时候不管什么时候都将新增的记录给去掉
            isRadio && _additional.splice(0, 1);
            // 勾选
            if (_original.indexOf(id) === -1) {
              // 不在原来的集合中
              if (_additional.indexOf(id) === -1) {
                _additional.push(id);
              }
            } else {
              // 在原来的集合中,意味着之前有去掉勾选的操作
              if (!isRadio && _removed.indexOf(id) !== -1) {
                _removed.splice(_removed.indexOf(id), 1);
              }
            }
          } else {
            // 取消勾选
            if (_original.indexOf(id) === -1) {
              // 不在原来的集合中,意味着以前曾经添加过
              if (_additional.indexOf(id) !== -1) {
                _additional.splice(_additional.indexOf(id), 1);
              }
            } else {
              // 在原来的集合中
              if (_removed.indexOf(id) === -1) {
                _removed.push(id);
              }
            }
          }
        }
      }
    }()
 
    , isArray = function (obj) {
      // 判断一个变量是不是数组
      return Object.prototype.toString.call(obj) === '[object Array]';
    }
 
    // 针对表格中是否选中的数据处理
    , dataRenderChecked = function (data, tableId, config) {
      if (!data || !tableId) {
        return;
      }
      config = config || getConfig(tableId);
      if (!config || !config.checkStatus) {
        return;
      }
      var nodeSelected = tableCheck.getChecked(tableId);
      for (var i = 0; i < data.length; i++) {
        data[i][table.config.checkName] = nodeSelected.indexOf(data[i][getPrimaryKey(config)]) !== -1;
      }
    }
 
    // 同步表格不可点击的checkbox
    , disabledCheck = function (tableId, syncConfig) {
      // tableId 这个参数有可能传入table的id也可以直接传入table的实例
      // syncConfig是否需要同步config
      // var config = getConfig(tableId);
      var config;
      if (typeof tableId === 'string') {
        config = getConfig(tableId);
      } else {
        config = tableId.config;
        tableId = config ? config.id : '';
      }
 
      if (!config) {
        return;
      }
      var tableView = config.elem.next();
 
      if (syncConfig) {
        config.checkDisabled = config.checkDisabled || {};
        config.checkDisabled.enabled = config.checkDisabled.enabled || true;
        config.checkDisabled.data = tableCheck.get(tableId, CHECK_TYPE_DISABLED) || [];
      }
      if (config.checkDisabled && config.checkDisabled.enabled) {
        layui.each(table.cache[tableId], function (index, data) {
          tableView.find('.layui-table-body')
            .find('tr[data-index="' + index + '"]')
            .find('input[name="layTableCheckbox"],[lay-type="layTableRadio"]')
            .prop('disabled', tableCheck.checkDisabled(tableId, data[getPrimaryKey(config)]));
        });
      } else {
        tableCheck.set(tableId, CHECK_TYPE_DISABLED, []);
      }
 
      tableView.find('input[lay-filter="layTableAllChoose"]').prop('checked', table.checkStatus(tableId).isAll);
      form.render('checkbox', tableView.attr('lay-filter'));
      form.render('radio', tableView.attr('lay-filter'));
    };
 
  // 对table的全局config进行深拷贝
  tablePlug.set = function (config) {
    $.extend(true, table.config, config || {});
  };
 
  // 为啥要自己定义一个set去更新table.config而不用table.set?
  // 因为table.set实际是非深拷贝,然后我这里期待的是一个可以根据需要后面根据开发者需要去丰富pageLanguageText的内容的而不是set的时候需要把plug里面写的初始的也全部写上
  tablePlug.set({
    pageLanguageText: {
      // 自定义table的page组件中的多语言支持,实际这个完全可以自己定义,想要显示的文字,但是建议实用为主,真的需要再去定义
      en: {
        jumpTo: 'jump to', // 到第
        page: 'page', // 页
        go: 'go', // 确定
        total: 'total', // 共
        unit: '', // 条(单位,一般也可以不填)
        optionText: 'limit each page' // 条/页
      }
      // 定义中文简写的, (如果需要的话,建议不改,按照原来的就行)
      // 'zh-CN': {
      //
      // }
      // 比如定义中文繁体
      // 'zh-TW': {
      //
      // }
    }
  });
 
  // 获得某个节点的位置 offsetTop: 是否获得相对top window的位移
  function getPosition(elem, _window, offsetTop) {
    _window = _window || window;
    elem = elem.length ? elem.get(0) : elem;
    var offsetTemp = {};
    if (offsetTop && _window.top !== _window.self) {
      var frameElem = _window.frames.frameElement;
      offsetTemp = getPosition(frameElem, _window.parent, offsetTop);
    }
    var offset = elem.getBoundingClientRect();
 
    return {
      top: offset.top + (offsetTemp.top || 0),
      left: offset.left + (offsetTemp.left || 0)
    };
  }
 
  /* 2.5.5已经换成一个会动的加载图标了,所以这个逻辑可以去掉 目前它的位置是在body表格中间的还可以接受暂时不处理 */
  // 修改原始table的loading的逻辑
  // var loading = table.Class.prototype.loading;
  // table.Class.prototype.loading = function (hide) {
  //   var that = this;
  //   loading.call(that, hide);
  //   if (!hide && that.layInit) {
  //     that.layInit.remove();
  //     // 添加一个动画
  //     that.layInit.addClass('layui-anim layui-anim-rotate layui-anim-loop');
  //     if (!that.layMain.height()) {
  //       // 如果当前没有内容,添加一个空的div让它有显示的地方
  //       that.layBox.append($('<div class="' + LOADING + '" style="height: 56px;"></div>'));
  //     }
  //     var offsetHeight = 0;
  //     if (that.layMain.height() - that.layMain.prop('clientHeight') > 0) {
  //       // 如果出现滚动条,要减去滚动条的宽度
  //       offsetHeight = that.getScrollWidth();
  //     }
  //     var thHeightTemp = that.elem.hasClass('vertical') ? 0 : that.layHeader.height();
  //     that.layInit.height(that.layBox.height() - thHeightTemp - offsetHeight).css('marginTop', thHeightTemp + 'px');
  //     that.layBox.append(that.layInit);
  //   }
  // };
 
  // 目前新增了一个errorView处理异常或者没有数据的时候的显示问题,对应的initTable中的一些逻辑是否还有必要待定 todo
  // 初始化表格的内容
  table.Class.prototype.initTable = function () {
    var that = this;
    var options = that.config;
 
    that.layFixed.find('tbody').html('');
    that.layFixed.addClass(HIDE);
    that.layTotal.addClass(HIDE);
    that.layPage.addClass(HIDE);
 
    that.layMain.find('tbody').html('');
    that.layMain.find('.' + NONE).remove();
 
    that.layHeader.find('input[name="layTableCheckbox"]').prop('checked', false);
    that.renderForm('checkbox');
  };
 
  // 内部使用,如果没有传reversal, 默认就是按照当前的状态取反更新一下,如果有传入,则以传入的为准
  var reverseTable = function (tableId, reversal) {
    if (!tableId) {
      layui.each(table.thisTable.that, function (key, obj) {
        reverseTable(key, reversal);
      });
    } else {
      var insTemp = getIns(tableId);
      var config = insTemp.config;
 
      if (typeof reversal !== 'boolean') {
        // 如果不是true/false; 默认就是将当前的状态给重新渲染一下
        reversal = !config.reversal;
      }
 
      // 设置状态
      config.reversal = reversal;
      // 调用反转方法
      insTemp.reverse();
      // 处理360急速模式下出现的异常问题(临时处理方式)
      insTemp.resize();
    }
  };
 
  var cacheData = {};
  var addCacheData = function (tableId, data, primaryKey) {
    var options = typeof tableId === 'string' ? getConfig(tableId) : tableId;
    // 如果是url模式并且设置了复选框跨页状态存储就把当前的data给缓存起来
    primaryKey = primaryKey || getPrimaryKey(options);
    if (options.checkStatus && primaryKey) {
      cacheData[options.id] = cacheData[options.id] || {};
      layui.each(data || table.cache[options.id] || [], function (index, data) {
        cacheData[options.id][data[primaryKey]] = data;
      });
    }
    return (data || table.cache[options.id] || []).map(function (value) {
      return value[primaryKey]
    });
  };
 
  // 渲染完成之后的回调
  var renderDone = function (scroll) {
    var that = this;
    var options = that.config;
    scroll && (that.layBody.scrollTop(0), that.layBody.scrollLeft(0));
    // 同步不可选的状态
    disabledCheck(that);
    // 添加筛选的功能
    addFieldFilter.call(that);
 
    // if (!that.layMain.find('.' + NONE).length) {
    //   that.layTotal.removeClass(HIDE);
    //   that.layFixLeft.removeClass(HIDE);
    // }
 
    // 初始化临时数据区
    layui.each(that.tempData, function (index, data) {
      that.addTemp(index + 1, data, null, true);
    });
 
    // 同步反转状态
    // reverseTable(that.key, !!that.config.reversal);
    options.reversal === true && that.reverse();
 
    // 动态给checkbox添加lay-filter方便加form的监听处理
    that.layBody.find('input[type="checkbox"][name="layTableCheckbox"]').attr('lay-filter', 'layTableCheckbox');
    // 更新统计行的数据
    // renderTotal(that.config.id);
    renderTotal(that);
 
    // 如果是url模式并且设置了复选框跨页状态存储就把当前的data给缓存起来
    addCacheData(options);
  };
 
  //异常提示
  table.Class.prototype.errorView = function(html){
    var that = this
      ,elemNone = that.layMain.find('.'+ NONE)
      ,layNone = $('<div class="'+ NONE +'">'+ (html || 'Error') +'</div>');
 
    if(elemNone[0]){
      that.layNone.remove();
      elemNone.remove();
    }
 
    that.layFixed.addClass(HIDE).find('tbody').html('');
    that.layMain.find('tbody').html('');
 
    that.layMain.append(that.layNone = layNone);
    // 补充异常情况下对page和total的内容处理
    that.layPage && that.layPage.addClass(HIDE).find('>div').html('');
    that.layTotal && that.layTotal.addClass(HIDE).find('tbody').html('');
 
    table.cache[that.key] = []; //格式化缓存数据
  };
 
  //获得数据
  table.Class.prototype.pullData = function(curr, refresh){
    var that = this
      ,options = that.config
      ,request = options.request
      ,response = options.response
      ,sort = function(){
      if(typeof options.initSort === 'object'){
        that.sort(options.initSort.field, options.initSort.type);
      }
    };
 
    that.startTime = new Date().getTime(); //渲染开始时间
 
    if(options.url){ //Ajax请求
      var params = {};
      params[request.pageName] = curr;
      params[request.limitName] = options.limit;
 
      //参数
      var data = $.extend(params, options.where);
      // 请求前对ajax的data进行修改的回调
      if (typeof options.renderRequest === 'function') {
        data = options.renderRequest(data);
      }
      if(options.contentType && options.contentType.indexOf("application/json") == 0){ //提交 json 格式
        data = JSON.stringify(data);
      }
 
      that.loading();
 
      $.ajax({
        type: options.method || 'get'
        ,url: options.url
        ,contentType: options.contentType
        ,data: data
        ,dataType: 'json'
        ,headers: options.headers || {}
        ,success: function(res){
          //如果有数据解析的回调,则获得其返回的数据
          if(typeof options.parseData === 'function'){
            res = options.parseData(res) || res;
          }
          //检查数据格式是否符合规范
          if(res[response.statusName] != response.statusCode){
            that.renderForm();
            that.errorView(
              res[response.msgName] ||
              ('返回的数据不符合规范,正确的成功状态码应为:"'+ response.statusName +'": '+ response.statusCode)
            );
          } else {
            that.renderData(res, curr, res[response.countName], false, refresh && (options.page ? options.page.count === res[response.countName] : true)), sort();
            options.time = (new Date().getTime() - that.startTime) + ' ms'; //耗时(接口请求+视图渲染)
          }
          refresh ? that.loading(true) : that.setColsWidth();
          typeof options.done === 'function' && options.done(res, curr, res[response.countName]);
        }
        ,error: function(e, m){
          that.errorView('数据接口请求异常:'+ m);
 
          that.renderForm();
          refresh ? that.loading(true) : that.setColsWidth();
        }
      });
 
    } else if(options.data && options.data.constructor === Array){ //已知数据
      var res = {}
        ,startLimit = curr*options.limit - options.limit
 
      res[response.dataName] = options.data.concat().splice(startLimit, options.limit);
      res[response.countName] = options.data.length;
 
      that.renderData(res, curr, res[response.countName], false, refresh && (options.page ? options.page.count === options.data.length : true)), sort();
      refresh ? that.loading(true) : that.setColsWidth();
      typeof options.done === 'function' && options.done(res, curr, res[response.countName]);
    }
  };
 
  //数据渲染
  table.Class.prototype.renderData = function(res, curr, count, sort, refresh){
    var that = this
      ,options = that.config
      ,data = res[options.response.dataName] || []
      ,trs = []
      ,trs_fixed = []
      ,trs_fixed_r = []
 
      //渲染视图
      ,render = function(){ //后续性能提升的重点
        var thisCheckedRowIndex;
        if(!sort && that.sortKey){
          return that.sort(that.sortKey.field, that.sortKey.sort, true);
        }
        layui.each(data, function(i1, item1){
          var tds = [], tds_fixed = [], tds_fixed_r = []
            ,numbers = i1 + options.limit*(curr - 1) + 1; //序号
 
          if(item1.length === 0) return;
          if(!sort){
            item1[table.config.indexName] = i1;
          }
 
          that.eachCols(function(i3, item3){
            var field = item3.field || i3
              ,key = options.index + '-' + item3.key
              ,content = item1[field];
 
            if(content === undefined || content === null) content = '';
            if(item3.colGroup) return;
 
            //td内容
            var td = ['<td data-field="'+ field +'" data-key="'+ key +'" '+ function(){ //追加各种属性
              var attr = [];
              if(item3.edit) attr.push('data-edit="'+ item3.edit +'"'); //是否允许单元格编辑
              if(item3.align) attr.push('align="'+ item3.align +'"'); //对齐方式
              if(item3.templet) attr.push('data-content="'+ content +'"'); //自定义模板
              // if(item3.toolbar) attr.push('data-off="true"'); //行工具列关闭单元格事件
              if(item3.event) attr.push('lay-event="'+ item3.event +'"'); //自定义事件
              if(item3.style) attr.push('style="'+ item3.style +'"'); //自定义样式
              if(item3.minWidth) attr.push('data-minwidth="'+ item3.minWidth +'"'); //单元格最小宽度
              return attr.join(' ');
            }() +' class="'+ function(){ //追加样式
              var classNames = [];
              if(item3.hide) classNames.push(HIDE); //插入隐藏列样式
              if(!item3.field) classNames.push('layui-table-col-special'); //插入特殊列样式
              return classNames.join(' ');
            }() +'">'
              ,'<div class="layui-table-cell laytable-cell-'+ function(){ //返回对应的CSS类标识
                return item3.type === 'normal' ? key
                  : (key + ' laytable-cell-' + item3.type);
              }() +'">' + function(){
                var tplData = $.extend(true, {
                  LAY_INDEX: numbers
                }, item1)
                  ,checkName = table.config.checkName;
 
                //渲染不同风格的列
                switch(item3.type){
                  case 'checkbox':
                    return '<input type="checkbox" name="layTableCheckbox" lay-skin="primary" '+ function(){
                      //如果是全选
                      if(item3[checkName]){
                        item1[checkName] = item3[checkName];
                        return item3[checkName] ? 'checked' : '';
                      }
                      return tplData[checkName] ? 'checked' : '';
                    }() +'>';
                    break;
                  case 'radio':
                    if(tplData[checkName]){
                      thisCheckedRowIndex = i1;
                    }
                    return '<input type="radio" name="layTableRadio_'+ options.index +'" '
                      + (tplData[checkName] ? 'checked' : '') +' lay-type="layTableRadio">';
                    break;
                  case 'numbers':
                    return numbers;
                    break;
                };
 
                //解析工具列模板
                if(item3.toolbar){
                  return laytpl($(item3.toolbar).html()||'').render(tplData);
                }
                return parseTempData(item3, content, tplData);
              }()
              ,'</div></td>'].join('');
 
            tds.push(td);
            if(item3.fixed && item3.fixed !== 'right') tds_fixed.push(td);
            if(item3.fixed === 'right') tds_fixed_r.push(td);
          });
 
          trs.push('<tr data-index="'+ i1 +'">'+ tds.join('') + '</tr>');
          trs_fixed.push('<tr data-index="'+ i1 +'">'+ tds_fixed.join('') + '</tr>');
          trs_fixed_r.push('<tr data-index="'+ i1 +'">'+ tds_fixed_r.join('') + '</tr>');
        });
 
        refresh || that.layBody.scrollTop(0);
        that.layMain.find('.'+ NONE).remove();
        that.layMain.find('tbody').html(trs.join(''));
        that.layFixLeft.find('tbody').html(trs_fixed.join(''));
        that.layFixRight.find('tbody').html(trs_fixed_r.join(''));
 
        that.renderForm();
        typeof thisCheckedRowIndex === 'number' && that.setThisRowChecked(thisCheckedRowIndex);
        that.syncCheckAll();
 
        //滚动条补丁
        that.haveInit ? that.scrollPatch() : setTimeout(function(){
          that.scrollPatch();
        }, 50);
        that.haveInit = true;
 
        layer.close(that.tipsIndex);
 
        //同步表头父列的相关值
        options.HAS_SET_COLS_PATCH || that.setColsPatch();
        options.HAS_SET_COLS_PATCH = true;
      };
 
    // 初始化选中的数据
    dataRenderChecked(data, options.id, options);
 
    var dataTemp = table.getTemp(that.key);
    // 存储临时数据
    that.tempData = dataTemp.data;
 
    table.cache[that.key] = data; //记录数据
 
    //显示隐藏分页栏
    that.layPage[(count == 0 || (data.length === 0 && curr == 1)) ? 'addClass' : 'removeClass'](HIDE);
 
    if(data.length === 0){
      that.renderForm();
      return that.errorView(options.text.none), renderDone.call(that, true);
    } else {
      that.layFixed.removeClass(HIDE);
    }
 
    //排序
    if(sort){
      return render(), renderDone.call(that);
    }
 
    render(); //渲染数据
    if (refresh) {
      return renderDone.call(that);
    }
    that.renderTotal(data); //数据合计
    that.layTotal && that.layTotal.removeClass(HIDE);
 
    //同步分页状态
    if(options.page){
      options.page = $.extend({
        elem: 'layui-table-page' + options.index
        ,count: count
        ,limit: options.limit
        ,limits: options.limits || [10,20,30,40,50,60,70,80,90]
        ,groups: 3
        ,layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
        ,prev: '<i class="layui-icon">&#xe603;</i>'
        ,next: '<i class="layui-icon">&#xe602;</i>'
        ,jump: function(obj, first){
          if(!first){
            //分页本身并非需要做以下更新,下面参数的同步,主要是因为其它处理统一用到了它们
            //而并非用的是 options.page 中的参数(以确保分页未开启的情况仍能正常使用)
            that.page = obj.curr; //更新页码
            options.limit = obj.limit; //更新每页条数
 
            that.pullData(obj.curr);
          }
          // #### 源码修改 #### 支持多语言的page
          if (that.config.pageLanguage && !(that.config.pageLanguage === true)) {
            var pageLanguageText;
            if (typeof that.config.pageLanguage === 'string') {
              if (!table.config.pageLanguageText[that.config.pageLanguage]) {
                console.log('找不到' + that.config.pageLanguage + '对应的语言文本定义');
                return;
              }
              pageLanguageText = table.config.pageLanguageText[that.config.pageLanguage];
            } else if (typeof that.config.pageLanguage === 'object') {
              var lanTemp = that.config.pageLanguage.lan;
              if (!lanTemp) {
                return;
              }
              pageLanguageText = $.extend({}, table.config.pageLanguageText[lanTemp], that.config.pageLanguage.text || {});
            } else {
              return;
            }
 
            if (!pageLanguageText) {
              return;
            }
 
            // 处理page支持en
            var pageElem = that.layPage.find('>div');
            pageElem.addClass(HIDE);
            var skipElem = pageElem.find('.layui-laypage-skip');
            var skipInput = skipElem.find('input');
            var skipBtn = skipElem.find('button');
            skipElem.html(pageLanguageText['jumpTo'] || 'jump to');
            skipInput.appendTo(skipElem);
            skipElem.append(pageLanguageText['page'] || 'page');
            skipBtn.html(pageLanguageText['go'] || 'go').appendTo(skipElem);
 
            var countElem = pageElem.find('.layui-laypage-count');
            var countText = countElem.text();
            countElem.html((pageLanguageText['total'] || 'total') + ' ' + countText.split(' ')[1] + (pageLanguageText['unit'] ? ' ' + pageLanguageText['unit'] : ''));
 
            var limitsElem = pageElem.find('.layui-laypage-limits');
            layui.each(limitsElem.find('option'), function (index, optionElem) {
              optionElem = $(optionElem);
              var textTemp = optionElem.text();
              optionElem.html(textTemp.split(' ')[0] + ' ' + (pageLanguageText['optionText'] || 'limit each page'));
            });
            pageElem.removeClass(HIDE);
          }
        }
      }, options.page);
      options.page.count = count; //更新总条数
      laypage.render(options.page);
    }
    // 渲染完毕做一些处理
    renderDone.call(that, true);
  };
 
  /* 固定列高度还有bug */
  var setColsWidth = table.Class.prototype.setColsWidth;
  table.Class.prototype.setColsWidth = function () {
    var that = this;
    // that.layBox.find('.' + LOADING).remove();
    setColsWidth.call(that);
 
    var options = that.config;
    var tableId = options.id;
    var tableView = that.elem;
 
    var noneElem = tableView.find('.' + NONE);
 
    // 如果没有数据的时候表头内容的宽度超过容器的宽度
    that.elem[noneElem.length && (that.layHeader.first().find('.layui-table').width() - 1) > that.layHeader.first().width() ? 'addClass' : 'removeClass']('layui-table-none-overflow');
 
    //如果多级表头,重新填补填补表头高度
    if (options.cols.length > 1) {
      //补全高度
      // var th = that.layFixed.find(ELEM_HEADER).find('th');
      // 只有有头部的高度的时候计算才有意义
      // var heightTemp = that.layHeader.height();
      // heightTemp = heightTemp / options.cols.length; // 每一个原子tr的高度
      var colsNum = options.cols.length;
      var thBox = that.layBox.find(ELEM_HEADER);
      var thElem = that.layFixed.find(ELEM_HEADER + ' th');
      var matchFlag = false;
      thElem.each(function (index, thCurr) {
        thCurr = $(thCurr);
        var rowspan = parseInt(thCurr.attr('rowspan') || '1');
        // var _thH = heightTemp * (parseInt(thCurr.attr('rowspan') || 1))
        //   - 1 - parseFloat(thCurr.css('padding-top')) - parseFloat(thCurr.css('padding-bottom'));
        // 找到原始的box里面的th的高度,只有行合并小于最大合并数的才需要设置高度
        if (rowspan < colsNum) {
          thCurr.height(thBox.find('th[data-key="' + thCurr.attr('data-key') + '"]').height());
          matchFlag = true;
        }
        // thCurr.height(_thH);
      });
      if (matchFlag) {
        // 修复ie浏览器下因为全行合并的高度导致后面的一些高度异常的问题
        that.layFixed.find('>' + ELEM_HEADER + ' th[rowspan="' + colsNum + '"]').height('auto');
      }
    }
 
    // that.layBody.scrollTop(0);
    // that.layBody.scrollLeft(0);
    // that.layHeader.scrollLeft(0);
  };
 
  $(window).resize(function () {
    layer.close(filterLayerIndex);
  });
 
  //初始化一些参数
  table.Class.prototype.setInit = function (type) {
    var that = this
      , options = that.config;
    var tableId = options.id;
 
    options.clientWidth = options.width || function () { //获取容器宽度
      //如果父元素宽度为0(一般为隐藏元素),则继续查找上层元素,直到找到真实宽度为止
      var getWidth = function (parent) {
        var width, isNone;
        parent = parent || options.elem.parent();
        width = parent.width();
        try {
          isNone = parent.css('display') === 'none';
        } catch (e) {
        }
        if (parent[0] && (!width || isNone)) return getWidth(parent.parent());
        return width;
      };
      return getWidth();
    }();
 
    if (type === 'width') return options.clientWidth;
 
    // 去掉之前的记录
    delete table.thisTable.arrs[tableId];
 
    if (!tableCheck.check(tableId)) {
      // 如果render的时候设置了checkStatus或者全局设置了默认跨页保存那么重置选中状态
      tableCheck.init(tableId, options.checkStatus ? (options.checkStatus['default'] || []) : []);
    } else {
      if (options.checkStatus && options.checkStatus['default']) {
        // 如果在option里面设置了默认选中的数据
        tableCheck.set(tableId, CHECK_TYPE_ORIGINAL, options.checkStatus['default']);
      }
    }
 
    if (options.checkDisabled && isArray(options.checkDisabled.data) && options.checkDisabled.data.length) {
      tableCheck.disabled(tableId, isArray(options.checkDisabled.data) ? options.checkDisabled.data : []);
    }
 
    var record;
    // 如果配置了字段筛选的记忆需要更新字段的hide设置
    if (options.colFilterRecord) {
      record = colFilterRecord.get(tableId, options.colFilterRecord);
      // 把修改hide的逻辑挪到下面做减少遍历
      // var record = colFilterRecord.get(tableId, options.colFilterRecord);
      // $.each(options.cols, function (i, item1) {
      //   $.each(item1, function (j, item2) {
      //
      //     item2.hide = !!record[item2.field];
      //   });
      // });
    } else {
      colFilterRecord.clear(tableId);
    }
 
    // 封装对col的配置处理
    var initCols = function (i1, item1, i2, item2) {
      //如果列参数为空,则移除
      if (!item2) {
        item1.splice(i2, 1);
        return;
      }
 
      item2.key = i1 + '-' + i2;
      item2.hide = item2.hide || false;
      item2.colspan = item2.colspan || 1;
      item2.rowspan = item2.rowspan || 1;
 
      //根据列类型,定制化参数
      that.initOpts(item2);
 
      // 如果配置了字段筛选的记忆需要更新字段的hide设置
      item2.hide = (record && item2.type === "normal" && item2.field && typeof record[item2.field] === 'boolean') ? record[item2.field] : item2.hide;
 
 
      // plug修改,根据配置信息确定是否合并列
      if (item2.colspan > 1) {
        // 合并列不应该出现filed
        delete item2.field;
      }
      if (!item2.field && !item2.toolbar && (!item2.colspan || item2.colspan === 1) && (tableSpecialColType.indexOf(item2.type) === -1)) {
        item2[COLGROUP] = true;
      } else if (item2[COLGROUP] && !(item2.colspan > 1)) {
        // 如果有乱用colGroup的,明明是一个字段列还给它添加上这个属性的会在这里KO掉,
        item2[COLGROUP] = false;
      }
 
      //设置列的父列索引
      //如果是组合列,则捕获对应的子列,
      var indexChild = i1 + (parseInt(item2.rowspan) || 1);
      // if (item2.colGroup || item2.colspan > 1 || (indexChild < options.cols.length)) { // 只要不是最后一层都会有子列
      if (item2.colGroup || indexChild < options.cols.length) { // 只要不是最后一层都会有子列
        var childIndex = 0;
        // #### 源码修改 #### 修复复杂表头数据与表头错开的bug
        layui.each(options.cols[indexChild], function (i22, item22) {
          //如果子列已经被标注为{HAS_PARENT},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
          if (item22.HAS_PARENT || (childIndex >= 1 && childIndex == (item2.colspan || 1))) return;
 
          item22.HAS_PARENT = true;
          item22.parentKey = i1 + '-' + i2;
          childIndex = childIndex + parseInt(item22.colspan > 1 ? item22.colspan : 1);
          initCols(indexChild, options.cols[indexChild], i22, item22);
        });
        item2.colGroup = typeof item2.colGroup === 'boolean' ? item2.colGroup : !(item2.field || item2.toolbar || (tableSpecialColType.indexOf(item2.type) !== -1));
        item2.isGroup = true; //标注是组合列
      }
 
      // //根据列类型,定制化参数
      // that.initOpts(item2);
    };
 
 
    //初始化列参数
    layui.each(options.cols, function (i1, item1) {
      if (i1 > 0) {
        return true
      }
      layui.each(item1, function (i2, item2) {
        // 调用解析cols
        initCols(i1, item1, i2, item2);
      });
    });
  };
 
  var tableInsReload = table.Class.prototype.reload;
  //表格完整重载
  table.Class.prototype.reload = function (options) {
    var that = this;
    table.reload(that.config.id, options, true);
  };
 
  // 添加一条临时数据
  table.Class.prototype.addTemp = function (numbers, data, callback, notScroll) {
    var that = this;
    var tds_fixed = [], tds_fixed_r = [], tds = [];
    var options = that.config, item1 = data || {};
    numbers = -numbers;
    if (that.layBody.find('tr[data-index="' + numbers + '"]').length) {
      // 已经存在
      return;
    }
    table.cache[that.key][numbers] = item1;
    that.eachCols(function (i3, item3) {
      var field = item3.field || i3
        , key = options.index + '-' + item3.key
        , content = item1[field];
 
      if (content === undefined || content === null) content = '';
      if (item3.colGroup) return;
 
      //td内容
      var td = ['<td data-field="' + field + '" data-key="' + key + '" ' + function () { //追加各种属性
        var attr = [];
        if (item3.type === 'normal' && item3.edit !== false) attr.push('data-edit="text"'); //是否允许单元格编辑
        if (item3.align) attr.push('align="' + item3.align + '"'); //对齐方式
        if (item3.templet) attr.push('data-content="' + content + '"'); //自定义模板
        // if (item3.toolbar) attr.push('data-off="true"'); //行工具列关闭单元格事件
        if (item3.event) attr.push('lay-event="' + item3.event + '"'); //自定义事件
        if (item3.style) attr.push('style="' + item3.style + '"'); //自定义样式
        if (item3.minWidth) attr.push('data-minwidth="' + item3.minWidth + '"'); //单元格最小宽度
        return attr.join(' ');
      }() + ' class="' + function () { //追加样式
        var classNames = [];
        if (item3.hide) classNames.push(HIDE); //插入隐藏列样式
        if (!item3.field) classNames.push('layui-table-col-special'); //插入特殊列样式
        return classNames.join(' ');
      }() + '">'
        , '<div class="layui-table-cell laytable-cell-' + function () { //返回对应的CSS类标识
          return item3.type === 'normal' ? key
            : (key + ' laytable-cell-' + item3.type);
        }() + '">' + function () {
          var tplData = $.extend(true, {
            LAY_INDEX: numbers
          }, item1);
 
          //渲染不同风格的列
          switch (item3.type) {
            case 'checkbox':
            case 'radio':
            case 'numbers':
              return '';
              break;
          }
 
          //解析工具列模板
          if (item3.toolbar) {
            return '';
          }
          // return item3.templet ? function () {
          //   return typeof item3.templet === 'function'
          //     ? item3.templet(tplData)
          //     : laytpl($(item3.templet).html() || String(content)).render(tplData)
          // }() : content;
          return parseTempData(item3, content, tplData);
        }()
        , '</div></td>'].join('');
 
      tds.push(td);
      if (item3.fixed && item3.fixed !== 'right') tds_fixed.push(td);
      if (item3.fixed === 'right') tds_fixed_r.push(td);
    });
 
    that.layMain.find('.' + NONE).remove();
    that.elem.removeClass('layui-table-none-overflow');
    // 追加到最后
    that.layMain.find('tbody').append('<tr class="layui-tablePlug-data-temp" data-index="' + numbers + '">' + tds.join('') + '</tr>');
    that.layFixLeft.removeClass(HIDE).find('tbody').append('<tr class="layui-tablePlug-data-temp" data-index="' + numbers + '">' + tds_fixed.join('') + '</tr>');
    that.layFixRight.find('tbody').append('<tr class="layui-tablePlug-data-temp" data-index="' + numbers + '">' + tds_fixed_r.join('') + '</tr>');
    that.renderForm();
    that.resize();
    // 滚动到底部
    notScroll || that.layBody.scrollTop(that.layBody[0].scrollHeight);
 
    that.layBody.find('tr.layui-tablePlug-data-temp[data-index="' + numbers + '"]')
      .find('td:first-child')
      .append('<div class="close_temp"></div>');
 
    that.layFixRight.find('.close_temp').remove();
 
    // 执行回调,传过去两个参数,第一个是当前的table的config,第二个是新增的这个临时的tr的jquery对象
    typeof callback === 'function' && callback.call(that.config, that.layBody.find('tr[data-index="' + numbers + '"]'));
  };
 
  // 对外提供添加临时数据的接口
  table.addTemp = function (id, data, callback) {
    var ins = getIns(id);
    if (typeof data === 'function') {
      callback = data;
      data = {};
    }
    ins && ins.addTemp(table.getTemp(id).numbers, (data && typeof data === 'object') ? data : {}, callback);
  };
 
  // 获得临时数据
  table.getTemp = function (id) {
    var data = table.cache[id] || [];
    var dataTemp = [], i = 1;
    for (; ; i++) {
      if (data[-i]) {
        if (isArray(data[-i])) {
          // 无效的数据
        } else {
          dataTemp.push(data[-i]);
        }
      } else {
        break;
      }
    }
    return {
      data: dataTemp,
      numbers: i
    }
  };
 
  // 清空临时数据
  table.cleanTemp = function (id, index) {
    var ins = getIns(id);
    var dataTemp = table.getTemp(id);
    var data = table.cache[id] || [];
    if (dataTemp.data.length) {
      var numbers = dataTemp.numbers;
      for (var i = 1; i < numbers; i++) {
        if (data[-i] && (index ? -i === index : true)) {
          data[-i] = [];
          if (index) {
            break;
          }
        }
      }
    }
    // 删除节点
    $('div.layui-table-view[lay-id="' + id + '"]').removeClass('has-data-temp-warn')
      .find('tr.layui-tablePlug-data-temp[data-index' + (index ? '="' + index + '"' : '') + ']').remove();
    table.resize(id);
    ins.layBody.scrollTop(ins.layBody[0].scrollHeight);
  };
 
  $(document).on('click', '.layui-table-view tr.layui-table-hover.layui-tablePlug-data-temp div.close_temp', function (event) {
    layui.stope(event);
    var btnElem = $(this);
    var trElem = btnElem.closest('tr');
    var tableId = trElem.closest('.layui-table-view').attr('lay-id');
    table.cleanTemp(tableId, trElem.data('index'));
  });
 
  var asyncChild = function (index, cols, i1, item2) {
    //如果是合并列,则捕获对应的子列
    // if (!item2.CHILD_COLS && item2.colGroup) {
    // if (item2.colGroup) {
    if (item2.isGroup) {
      var childIndex = 0;
      index++
      item2.CHILD_COLS = [];
      // #### 源码修改 #### 修复复杂表头数据与表头错开的bug
      // 找到它的子列所在cols的下标
      var i2 = i1 + (parseInt(item2.rowspan) || 1);
      layui.each(cols[i2], function (i22, item22) {
        //如果子列已经被标注为{PARENT_COL_INDEX},或者子列累计 colspan 数等于父列定义的 colspan,则跳出当前子列循环
        if (item22.PARENT_COL_INDEX || (childIndex >= 1 && childIndex == (item2.colspan || 1))) return;
        item22.PARENT_COL_INDEX = index;
 
        item2.CHILD_COLS.push(item22);
        childIndex = childIndex + parseInt(item22.colspan > 1 ? item22.colspan : 1);
        asyncChild(index, cols, i2, item22);
      });
    }
  };
 
  //遍历表头
  table.eachCols = function (id, callback, cols) {
    var that = this;
    var config = that.thisTable.config[id] || {}
      // , arrs = [], index = 0;
      , arrs = config.cols ? (that.thisTable.arrs[id] || []) : [], index = 0;
    cols = $.extend(true, [], cols || config.cols);
    // arrs = ;
    var cacheFlag;
 
    if (!arrs.length) {
      //重新整理表头结构
      layui.each(cols, function (i1, item1) {
        if (i1 > 0) {
          return true;
        }
        layui.each(item1, function (i2, item2) {
          asyncChild(index, cols, i1, item2);
 
          if (item2.PARENT_COL_INDEX) return; //如果是子列,则不进行追加,因为已经存储在父列中
          arrs.push(item2);
        });
      });
      that.thisTable.arrs[id] = arrs;
    } else {
      // console.log('命中缓存!!');
      cacheFlag = true;
    }
 
    //重新遍历列,如果有子列,则进入递归
    var eachArrs = function (obj) {
      layui.each(obj || arrs, function (i, item) {
        var key = item.key.split('-');
 
        // 因为加了缓存需要同步他的hide信息
        if (cacheFlag) {
          // 将缓存中的hide跟cols的hide同步
          item.hide = cols[key[0]][key[1]].hide;
          // 将之前设置的选中状态去掉
          item[table.config.checkName] = false;
          // 如果没有设置width默认成自动分配宽度列
          item.width = item.width || 0;
        }
        if (!item[COLGROUP]) {
          typeof callback === 'function' && callback(i, item);
        }
        if (item.CHILD_COLS) return eachArrs(item.CHILD_COLS);
        // typeof callback === 'function' && callback(i, item);
      });
    };
 
    eachArrs();
  };
 
  // 字段过滤的相关功能
  var addFieldFilter = function () {
    var that = this;
    var tableId = that.key;
    var tableView = that.elem;
 
    table.eachCols(tableId, function (index, item) {
      if (item.type === 'normal') {
        var field = item.field;
        if (!field) {
          return;
        }
        var thElem = tableView.find('th[data-field="' + field + '"]');
        if (!item.filter) {
          thElem.find('.layui-table-filter').remove();
        } else {
          if (!thElem.find('.layui-table-filter').length) {
            $(LayuiTableColFilter.join('')).insertAfter(thElem.find('.layui-table-cell>span:not(.layui-inline)')).click(function (event) {
              layui.stope(event);
              var filterActive = tableView.find('.layui-table-filter.layui-active');
              if (filterActive.length && filterActive[0] !== this) {
                // 目前只支持单列过滤,多列过滤会存在一些难题,不好统一,干脆只支持单列过滤
                filterActive.removeClass('layui-active');
                that.layBody.find('tr.' + HIDE).removeClass(HIDE);
              }
              var mainElem = tableView.find('.layui-table-main');
              var nodes = [];
              layui.each(mainElem.find('td[data-field="' + field + '"]'), function (index, elem) {
                elem = $(elem);
                var textTemp = elem.text();
                if (nodes.indexOf(textTemp) === -1) {
                  nodes.push(textTemp);
                }
              });
              var layerWidth = 200;
              var layerHeight = 300;
              var btnElem = $(this);
              var btnPosition = getPosition(btnElem.find('.layui-tablePlug-icon-filter'));
              var topTemp = btnPosition.top;
              var leftTemp = btnPosition.left + btnElem.width();
              if (leftTemp + layerWidth > $(document).width()) {
                leftTemp -= (layerWidth + btnElem.width());
              }
              filterLayerIndex = layer.open({
                content: '',
                title: null,
                type: 1,
                // area: [layerWidth + 'px', layerHeight + 'px'],
                area: layerWidth + 'px',
                shade: 0.1,
                closeBtn: 0,
                fixed: false,
                resize: false,
                shadeClose: true,
                offset: [topTemp + 'px', leftTemp + 'px'],
                isOutAnim: false,
                maxmin: false,
                success: function (layero, index) {
                  layero.find('.layui-layer-content').html('<table id="layui-tablePlug-col-filter" lay-filter="layui-tablePlug-col-filter"></table>');
                  table.render({
                    elem: '#layui-tablePlug-col-filter',
                    data: nodes.map(function (value, index1, array) {
                      var nodeTemp = {
                        name: value
                      };
                      nodeTemp[table.config.checkName] = !that.layBody.find('tr.' + HIDE).filter(function (index, item) {
                        return $(item).find('td[data-field="' + field + '"]').text() === value;
                      }).length;
                      return nodeTemp;
                    }),
                    page: false,
                    skin: 'nob',
                    // id: 'layui-tablePlug-col-filter-layer',
                    even: false,
                    height: nodes.length > 8 ? layerHeight : null,
                    size: 'sm',
                    style: 'margin: 0;',
 
                    cols: [[
                      {type: 'checkbox', width: 40},
                      {
                        field: 'name',
                        title: '全选<span class="table-filter-opt-invert" onclick="layui.tablePlug && layui.tablePlug.tableFilterInvert(this);">反选</span>'
                      }
                    ]]
                  })
                },
                end: function () {
                  btnElem[that.layBody.find('tr.' + HIDE).length ? 'addClass' : 'removeClass']('layui-active');
                }
              });
 
              // 监听字段过滤的列选择的
              table.on('checkbox(layui-tablePlug-col-filter)', function (obj) {
                if (obj.type === 'all') {
                  that.layBody.find('tr')[obj.checked ? 'removeClass' : 'addClass'](HIDE);
                } else {
                  layui.each(that.layBody.first().find('tr td[data-field="' + field + '"]'), function (index, elem) {
                    elem = $(elem);
                    if (elem.text() === obj.data.name) {
                      var trElem = elem.parent();
                      that.layBody.find('tr[data-index="' + trElem.data('index') + '"]')[obj.checked ? 'removeClass' : 'addClass'](HIDE);
                    }
                  });
                }
                // that.resize();
              });
 
            });
          } else {
            // thElem.find('.layui-table-filter')[that.layBody.find('tr.' + HIDE).length ? 'addClass' : 'removeClass']('layui-active');
            thElem.find('.layui-table-filter').removeClass('layui-active');
          }
        }
      }
    }, that.config.cols);
  };
 
  // 表格反转
  table.Class.prototype.reverse = function () {
    var that = this;
    var config = that.config;
    var isVertical = config.reversal;
 
    that.elem[isVertical ? 'addClass' : 'removeClass']('vertical');
    setTimeout(function () {
      that.layTotal.css({top: isVertical ? that.layTool.outerHeight() - 1 + 'px' : 0});
      console.log('isVertical:'+isVertical);
      console.log(that.layHeader.width());
      that.layMain.css({
        marginLeft: isVertical ? that.layHeader.width() + 'px' : 0,
        marginRight: (isVertical && config.totalRow) ? that.layTotal.width() + 'px' : 0
      });
      isVertical || that.layHeader.scrollLeft(that.layMain.scrollLeft());
    }, 0);
    return that;
  };
 
  // 调整表格实例resize的逻辑如果表格是反转了需要重新更新一下反转的效果
  // var tableResize = table.Class.prototype.resize;
  // if (!tableResize.modifiedByTablePlug) {
  //   table.Class.prototype.resize = function () {
  //     var that = this;
  //     var ret = tableResize.call(that);
  //     that.config.reversal === true && that.reverse();
  //     return ret;
  //   };
  //   table.Class.prototype.resize.modifiedByTablePlug = true;
  // }
 
  //遍历表头
  table.Class.prototype.eachCols = function (callback) {
    var that = this;
    // table.eachCols(null, callback, that.config.cols);
    table.eachCols(that.config.id, callback, that.config.cols);
    return that;
  };
 
  // 记录解析之后的cols arr
  table.thisTable.arrs = {};
  // 改造table.render和reload记录返回的对象
  var tableRender = table.render;
  table.render = function (config) {
    var that = this;
    var insTemp = tableRender.call(that, config);
    var insObj = getIns(insTemp.config.id); // 获得当前的table的实例,对实例内部的方法进行改造
    if (!insObj || !insObj.layMain) {
      // console.log('出现render过后还没有找到需要的对象或者节点的情况');
    }
    // 同步滚动条 如果render的节点不存在,就不处理事件
    insObj.layMain && insObj.layMain.off('scroll') // 去掉layMain原始的事件
      .on('scroll', function () {
 
        var othis = $(this)
          , scrollLeft = othis.scrollLeft()
          , scrollTop = othis.scrollTop();
 
        insObj.layHeader.scrollLeft(scrollLeft);
        insObj.layTotal.scrollLeft(scrollLeft);
        // 过滤掉鼠标滚动fixed区域而联动滚动main的情况
        // insObj.layFixed.find(ELEM_BODY + ':not(.' + FIXED_SCROLL + ')').scrollTop(scrollTop);
        insObj.layFixed.find(ELEM_BODY + ':not(:hover)').scrollTop(scrollTop);
 
        layer.close(insObj.tipsIndex);
      });
 
    // 监听ELEM_BODY的滚动
    insObj.layFixed && insObj.layFixed.find(ELEM_BODY).on('scroll', function () {
      var elemBody = $(this);
      if (elemBody.is(':hover')) {  // 只有当前鼠标的fixed区域才需要处理
        // 同步两个fixed的滚动
        insObj.layFixed.find(ELEM_BODY + ':not(:hover)').scrollTop(elemBody.scrollTop());
        // 联动main的滚动
        insObj.layMain.scrollTop(elemBody.scrollTop());
      }
    });
 
    if (refresh.timer[insTemp.config.id]) {
      // 存在定时刷新
      refresh.reset(insTemp.config.id);
    }
    return tableIns[insTemp.config.id] = insTemp;
  };
 
  // 改造table reload
  var tableReload = table.reload;
  var queryParams = (function () {
    // 查询模式的白名单
    var params = ['url', 'method', 'where', 'contentType', 'headers', 'parseData', 'request', 'response', 'data', 'page', 'initSort', 'autoSort', 'reversal'];
    // 查询模式的黑名单
    var params_blacklist = ['id', 'elem', 'cols', 'width', 'height'];
    return {
      // 获得查询的属性
      getParams: function () {
        return $.extend(true, [], params);
      },
      getParamsBlacklist: function () {
        return $.extend(true, [], params_blacklist);
      },
      // 注册查询的属性,方便后面自己有扩展新的功能的时候,有一些配置可以注册成不重载的属性
      registParams: function () {
        // 过渡期处理
        // 智能重载
        console.warn('智能重载相关的部分已经从查询模式白名单模式修改为查询模式参数的黑名单模式,所以该方法基本是启用状态,' +
          '自定义的参数如果不是会修改整个table的框子的可以不用像之前一样要注册一下加入白名单了,使用起来会更加方便一些');
        // var that = this;
        // layui.each(arguments, function (i, value) {
        //   if (isArray(value)) {
        //     that.registParams.apply(that, value);
        //   } else {
        //     if (typeof value === 'string' && params.indexOf(value) === -1) {
        //       params.push(value);
        //     }
        //   }
        // });
      },
      registerBlacklist: function () {
        // 将一些属性加入黑名单
        console.warn('不建议自己调用改方法将参数加入查询参数的黑名单,除非是在非常了解该功能的前提下');
        var that = this;
        layui.each(arguments, function (i, value) {
          if (isArray(value)) {
            that.registerBlacklist.apply(that, value);
          } else {
            if (typeof value === 'string' && params_blacklist.indexOf(value) === -1) {
              params_blacklist.push(value);
            }
          }
        });
      }
      // check: function () {
      //
      // }
    }
  })();
 
  // 是否启用智能重载模式
  var smartReload = (function () {
    var enable = true; // v0.2.0之后默认开启智能重载
    return {
      enable: function () {
        if (arguments.length) {
          var isEnable = arguments[0];
          if (typeof isEnable !== "boolean") {
            hint.error('如果要开启或者关闭全局的表格智能重载模式,请传入一个true/false为参数');
          } else {
            enable = isEnable;
          }
        } else {
          return enable;
        }
      }
    }
  })();
 
  // 添加两个目前tablePlug扩展的属性到查询模式白名单中
  // queryParams.registParams('colFilterRecord', 'checkStatus', 'smartReloadModel', 'checkDisabled');
 
  table.reload = function (tableId, config, shallowCopy) {
    var that = this;
    config = config || {};
 
    var configOld = getConfig(tableId);
    var configTemp = $.extend(true, {}, getConfig(tableId), config);
    // 如果不记录状态的话就重置目前的选中记录
    if (!configTemp.checkStatus) {
      tableCheck.reset(tableId);
    }
    if (smartReload.enable() && configTemp.smartReloadModel) {
 
      // 如果开启了智能重载模式
      // 是否为重载模式
      var reloadModel = false;
      if (!!configTemp.page !== !!configOld.page) {
        // 如果是否分页发生了改变
        reloadModel = true;
      }
      // if (!reloadModel) {
      //   // 白名单的校验
      //   var dataParamsTemp = $.extend(true, [], queryParams.getParams());
      //
      //   layui.each(config, function (_key, _value) {
      //     var indexTemp = dataParamsTemp.indexOf(_key);
      //     if (indexTemp === -1) {
      //       return reloadModel = true;
      //     } else {
      //       // 如果匹配到去掉这个临时的属性,下次查找的时候减少一个属性
      //       dataParamsTemp.splice(indexTemp, 1);
      //     }
      //   });
      // }
      if (!reloadModel) {
        // 黑名单的校验
        var dataParamsTemp = queryParams.getParamsBlacklist();
 
        layui.each(config, function (_key, _value) {
          var indexTemp = dataParamsTemp.indexOf(_key);
          if (indexTemp !== -1) {
            return reloadModel = true;
          }
        });
      }
 
      if (!reloadModel) {
        var insTemp = getIns(tableId);
 
        if (typeof config.page === 'object') {
          config.page.curr && (insTemp.page = config.page.curr);
          delete config.elem;
          delete config.jump;
        }
        if(config.data && config.data.constructor === Array) delete insTemp.config.data;
        shallowCopy ? $.extend(insTemp.config, config) : $.extend(true, insTemp.config, config);
        if (!insTemp.config.page) {
          insTemp.page = 1;
        }
        insTemp.loading();
        insTemp.pullData(insTemp.page);
        return table.thisTable.call(insTemp);
      }
    }
 
    // 如果是重载
    if (shallowCopy) {
      tableInsReload.call(getIns(tableId), config);
      tableIns[tableId].config = getIns(tableId).config;
    } else {
      var insTemp = tableReload.call(that, tableId, config);
      return tableIns[tableId] = insTemp;
    }
  };
 
  // 获得table的config
  var getConfig = function (tableId) {
    return table.thisTable.config[tableId] || (tableIns[tableId] && tableIns[tableId].config) || {};
  };
 
  // 原始的
  var checkStatus = table.checkStatus;
  // 重写table的checkStatus方法
  table.checkStatus = function (tableId, getCacheData) {
    var that = this;
    var statusTemp = checkStatus.call(that, tableId);
    var config = getConfig(tableId);
    if (config && config.checkStatus) {
      // 状态记忆
      statusTemp.status = tableCheck.get(tableId);
      if (getCacheData) {
        statusTemp.dataCache = [];
        var cacheDataTemp = cacheData[config.id];
        layui.each($.extend(true, [], tableCheck.getChecked(tableId)), function (index, id) {
          cacheDataTemp[id] && statusTemp.dataCache.push(table.clearCacheKey(cacheDataTemp[id]));
        });
      }
    }
    if (config && config.checkDisabled) {
      var checkDisabledTemp = config.checkDisabled;
      if (typeof checkDisabledTemp === 'object' && checkDisabledTemp.enabled !== false) {
        var num1 = 0; //可选的数量
        var num2 = 0; //最终选中的数量
        var primaryKey = getPrimaryKey(config);
        var disabledTemp = tableCheck.get(tableId, CHECK_TYPE_DISABLED);
        layui.each(table.cache[tableId], function (index, data) {
          var primaryValue = data[primaryKey];
          if (disabledTemp.indexOf(primaryValue) === -1) {
            num1++;
            if (data[table.config.checkName]) {
              num2++;
            }
          }
        });
        statusTemp.isAll = (num2 > 0 && num1 === num2);
      }
    }
    return statusTemp;
  };
 
  // 更新复选框的状态
  var updateCheckStatus = function (tableId, value, checked, isRadio) {
    if (!tableCheck.checkDisabled(tableId, value)) {
      tableCheck.update(tableId, value, checked, isRadio);
    } else {
      // 操作了不可选的
      return false;
    }
  };
 
  var getPrimaryKey = function (config) {
    if (config.primaryKey) {
      return config.primaryKey;
    }
    var keyStatus = config.checkStatus && config.checkStatus.primaryKey,
      keyDisabled = config.checkDisabled && config.checkDisabled.primaryKey;
    if (keyStatus && keyDisabled && keyStatus !== keyDisabled) {
      layui.hint().error('注意:当前表格(' + config.id + ')中checkStatus和checkDisabled都配置了primaryKey,但是他们不是同一个字段,必须保持表格配置中主键是唯一的,建议直接设置在顶层配置中就可以了!')
    }
    return keyDisabled || keyStatus || 'id';
  };
 
  // 监听所有的表格中的type:'checkbox'注意不要在自己的代码里面也写这个同名的监听,不然会被覆盖,
  table.on('checkbox', function (obj) {
    var tableView = $(this).closest('.layui-table-view');
    var tableId = tableView.attr('lay-id');
    var config = getConfig(tableId);
    if (tableCheck.check(tableId)) {
      var _checked = obj.checked;
      var _data = obj.data;
      var _type = obj.type;
      var primaryKey = getPrimaryKey(config);
 
      if (_type === 'one') {
        updateCheckStatus(tableId, _data[primaryKey], _checked);
      } else if (_type === 'all') {
        // 全选或者取消全不选
        var renderFlag = false;
        layui.each(layui.table.cache[tableId], function (index, data) {
          var disableFlag = updateCheckStatus(tableId, data[primaryKey], _checked);
          if (disableFlag === false) {
            renderFlag = true;
            // 因为原始的table操作了不可选的复选框需要纠正一下状态
            var checkedTemp = tableCheck.getChecked(tableId).indexOf(data[primaryKey]) !== -1;
            tableView.find('.layui-table-body')
              .find('tr[data-index="' + index + '"]')
              .find('input[name="layTableCheckbox"]').prop('checked', checkedTemp);
            data[table.config.checkName] = checkedTemp;
          }
        });
        // renderFlag && getIns(tableId).renderForm('checkbox');
        renderFlag && form.render('checkbox', tableView.attr('lay-filter'));
      }
    }
  });
 
  // 单选状态记忆
  table.on('radio()', function (obj) {
    var tableView = obj.tr.closest('.layui-table-view');
    var tableId = tableView.attr('lay-id');
    var config = getConfig(tableId);
    if (tableCheck.check(tableId)) {
      var _checked = obj.checked;
      var _data = obj.data;
      var primaryKey = getPrimaryKey(config);
      updateCheckStatus(tableId, _data[primaryKey], _checked, true);
    }
  });
 
  // 让被美化的复选框支持原始节点的change事件
  form.on('checkbox', function (data) {
    $(data.elem).change();
  });
 
  // 表格筛选列的状态记录的封装
  var colFilterRecord = (function () {
    var recodeStoreName = 'tablePlug_col_filter_record';
    var getStoreType = function (recordType) {
      return recordType === 'local' ? 'data' : 'sessionData';
    };
    return {
      // 记录
      set: function (tableId, key, checked, recordType) {
        if (!tableId || !key) {
          return;
        }
        // 默认用sessionStore
        var storeType = getStoreType(recordType);
        var dataTemp = this.get(tableId, recordType);
        dataTemp[key] = !checked;
        layui[storeType](recodeStoreName, {
          key: tableId,
          value: dataTemp
        })
      },
      get: function (tableId, recordType) {
        return layui[getStoreType(recordType)](recodeStoreName)[tableId] || {};
      },
      clear: function (tableId) {
        $.each(['data', 'sessionData'], function (index, type) {
          layui[type](recodeStoreName, {
            key: tableId,
            remove: true
          });
        });
      }
    };
  })();
 
  // 监听表格筛选的点
  $(document).on('change', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]', function (event) {
    var elem = $(this);
    // var key = elem.data('key');
    var key = elem.attr('name');
    var tableView = elem.closest('.layui-table-view');
    var tableId = tableView.attr('lay-id');
    var config = getConfig(tableId);
    var filterRecord = config.colFilterRecord;
    if (filterRecord) {
      colFilterRecord.set(tableId, key, this.checked, filterRecord);
    } else {
      colFilterRecord.clear(tableId)
    }
  });
 
  // 缓存当前操作的是哪个表格的哪个tr的哪个td
  $(document).off('mousedown', '.layui-table-grid-down')
    .on('mousedown', '.layui-table-grid-down', function (event) {
      // 记录操作的td的jquery对象
      table._tableTdCurr = $(this).closest('td');
    });
 
  // 给弹出的详情里面的按钮添加监听级联的触发原始table的按钮的点击事件
  $(document).off('click', '.layui-table-tips-main [lay-event]')
    .on('click', '.layui-table-tips-main [lay-event]', function (event) {
      var elem = $(this);
      var tableTrCurr = table._tableTdCurr;
      if (!tableTrCurr) {
        return;
      }
      var layerIndex = elem.closest('.layui-table-tips').attr('times');
      // 关闭当前的这个显示更多的tip
      layer.close(layerIndex);
      // 找到记录的当前操作的那个按钮
      table._tableTdCurr.find('[lay-event="' + elem.attr('lay-event') + '"]').first().click();
    });
 
  // 监听统一的toolbar一般用来处理通用的
  table.on('toolbar()', function (obj) {
    var config = obj.config;
    var btnElem = $(this);
    var tableId = config.id;
    var tableView = config.elem.next();
    switch (obj.event) {
      case 'LAYTABLE_COLS':
        // 给筛选列添加全选还有反选的功能
        var panelElem = btnElem.find('.layui-table-tool-panel');
        var checkboxElem = panelElem.find('[lay-filter="LAY_TABLE_TOOL_COLS"]');
        var checkboxCheckedElem = panelElem.find('[lay-filter="LAY_TABLE_TOOL_COLS"]:checked');
        $('<li class="layui-form" lay-filter="LAY_TABLE_TOOL_COLS_FORM">' +
          '<input type="checkbox" lay-skin="primary" lay-filter="LAY_TABLE_TOOL_COLS_ALL" '
          + ((checkboxElem.length === checkboxCheckedElem.length) ? 'checked' : '') + ' title="全选">' +
          '<span class="LAY_TABLE_TOOL_COLS_Invert_Selection">反选</span></li>')
          .insertBefore(panelElem.find('li').first())
          .on('click', '.LAY_TABLE_TOOL_COLS_Invert_Selection', function (event) {
            layui.stope(event);
            // 反选逻辑
            panelElem.find('[lay-filter="LAY_TABLE_TOOL_COLS"]+').click();
          });
        form.render('checkbox', 'LAY_TABLE_TOOL_COLS_FORM');
        break;
    }
  });
 
  // 监听筛选列panel中的全选
  form.on('checkbox(LAY_TABLE_TOOL_COLS_ALL)', function (obj) {
    $(obj.elem).closest('ul')
      .find('[lay-filter="LAY_TABLE_TOOL_COLS"]' + (obj.elem.checked ? ':not(:checked)' : ':checked') + '+').click();
  });
 
  // 监听筛选列panel中的单个记录的change
  $(document).on('change', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]', function (event) {
    var elemCurr = $(this);
    // 筛选列单个点击的时候同步全选的状态
    $('input[lay-filter="LAY_TABLE_TOOL_COLS_ALL"]')
      .prop('checked',
        elemCurr.prop('checked') ? (!$('input[lay-filter="LAY_TABLE_TOOL_COLS"]').not(':checked').length) : false);
    form.render('checkbox', 'LAY_TABLE_TOOL_COLS_FORM');
  });
 
  // 逻辑移到另外的js里面去了
 
  // 阻止表格中lay-event的事件冒泡
  $(document).on('click', '.layui-table-view tbody [lay-event],.layui-table-view tbody tr [name="layTableCheckbox"]+', function (event) {
    layui.stope(event);
  });
 
  // 是否让固定列支持鼠标滚动
  var enableTableFixedScroll = function (enabled) {
    enabled = !!enabled;
 
    $(document).off('mouseenter', '.' + ELEM_VIEW + ' ' + ELEM_FIXR + ' ' + ELEM_BODY)
      .off('mouseleave', '.' + ELEM_VIEW + ' ' + ELEM_FIXR + ' ' + ELEM_BODY)
      .off('mouseenter', '.' + ELEM_VIEW + ' ' + ELEM_FIXL + ' ' + ELEM_BODY)
      .off('mouseleave', '.' + ELEM_VIEW + ' ' + ELEM_FIXL + ' ' + ELEM_BODY)
      .off('mouseenter', '.' + ELEM_VIEW + ' ' + ELEM_FIXED + ' ' + ELEM_HEADER);
 
    if (enabled) {
      // 给固定列添加一些鼠标的事件监听,用于支持固定列滚动
      $(document).on('mouseenter', '.' + ELEM_VIEW + ' ' + ELEM_FIXR + ' ' + ELEM_BODY, function (event) {
        // 处理鼠标移入右侧
        var elem = $(this);
        var elemFixedR = elem.closest(ELEM_FIXR);
        if (elemFixedR.css('right') !== '-1px') {
          // 如果有滚动条的话
          elemFixedR.addClass(FIXED_SCROLL);
        } else {
          setTimeout(function () {
            if (elemFixedR.css('right') !== '-1px') {
              // console.log('出现了一开始还没有打滚动条补丁的时候就触发的情况');
              elemFixedR.addClass(FIXED_SCROLL);
            }
          }, 50);
        }
      }).on('mouseleave', '.' + ELEM_VIEW + ' ' + ELEM_FIXR + ' ' + ELEM_BODY, function (event) {
        // 处理鼠标移出右侧
        $(this).closest(ELEM_FIXR).removeClass(FIXED_SCROLL);
      }).on('mouseenter', '.' + ELEM_VIEW + ' ' + ELEM_FIXL + ' ' + ELEM_BODY, function (event) {
        // 处理鼠标移入左侧
        var elem = $(this);
        var elemFixedL = elem.closest(ELEM_FIXL);
        elemFixedL.addClass(FIXED_SCROLL);
        var widthOut = elemFixedL.find(ELEM_HEADER).find('table').width();
        var widthIn = elemFixedL.find(ELEM_HEADER).width() + 1;
        elemFixedL.css({width: widthOut + 'px'}).find(ELEM_BODY).css({width: widthIn + 'px'});
      }).on('mouseleave', '.' + ELEM_VIEW + ' ' + ELEM_FIXL + ' ' + ELEM_BODY, function (event) {
        // 处理鼠标移出左侧
        $(this).css({width: 'auto'}).closest(ELEM_FIXL).css({width: 'auto'}).removeClass(FIXED_SCROLL);
      }).on('mouseenter', '.' + ELEM_VIEW + ' ' + ELEM_FIXED + ' ' + ELEM_HEADER, function (event) {
        var elem = $(this);
        elem.closest(ELEM_FIXED).removeClass(FIXED_SCROLL);
      });
    }
  };
 
  // 默认开启固定列滚动监听的支持
  enableTableFixedScroll(true);
 
 
  // 同步表格中是否固定列上的的全选状态,
  form.on('checkbox(layTableAllChoose)', function (obj) {
    var elem = $(obj.elem);
    var tableView = elem.closest('.' + ELEM_VIEW);
    form.render('checkbox',
      tableView.attr('lay-filter'),
      tableView.find('[lay-filter="layTableAllChoose"]' + (obj.elem.checked ? ':not(:checked)' : ':checked')).prop('checked', obj.elem.checked)
    );
  });
 
  // 同步表格中是否固定列上的的复选框状态,
  form.on('checkbox(layTableCheckbox)', function (obj) {
    var elem = $(obj.elem);
    var tableView = elem.closest('.' + ELEM_VIEW);
    var trElem = tableView.find('tr[data-index="' + elem.closest('tr').data('index') + '"]');
    form.render('checkbox',
      tableView.attr('lay-filter'),
      trElem.find('[lay-filter="layTableCheckbox"]' + (obj.elem.checked ? ':not(:checked)' : ':checked')).prop('checked', obj.elem.checked)
    );
  });
 
  // 将cache的数据重新渲染一下
  var renderData = function (activeIndex, sort) {
    var that = this;
    var resTemp = {};
    var options = that.config;
    var scrollTop = that.layMain.scrollTop();
    var scrollLeft = that.layMain.scrollLeft();
 
    activeIndex = activeIndex >= 0 ? activeIndex : that.layBody.find('tr.' + ELEM_CLICK).data('index');
    resTemp[options.response.statusName] = options.response.statusCode;
    resTemp[options.response.msgName] = '数据更新';
    resTemp[options.response.dataName] = table.cache[options.id];
    // resTemp[options.response.countName] = that.count || (options.page ? options.page.count : options.data.length);
    resTemp[options.response.countName] = that.count || (options.page ? options.page.count : table.cache[options.id].length);
    if (sort) {
      // 如果是移动了数据,会取消当前的排序规则,以当前的顺序为准进行调整,如果还需要排序
      // delete that.sortKey;
      that.layHeader.find('.layui-table-sort[lay-sort]').attr('lay-sort', '');
    }
    that.renderData(resTemp, that.page, resTemp[options.response.countName], sort);
 
    // 滚动到之前的位置
    that.layBody.scrollTop(scrollTop);
    that.layMain.scrollLeft(scrollLeft);
 
    // 执行done回调保证跟初始化一样
    typeof options.done === 'function' && options.done(resTemp, that.page, resTemp[options.response.countName]);
 
    activeIndex >= 0 && setTimeout(function () {
      that.setThisRowChecked(activeIndex);
    }, 0);
 
    return that;
  };
 
  // 表格记录顺序调整
  var move = function (tableId, from, to) {
    var that = this;
    if ((!from && from !== 0) || (!to && to !== 0) || from < 0 || to < 0 || from === to) {
      return that;
    }
    var tableObj = getIns(tableId);
    if (tableObj) {
      var options = tableObj.config;
      var dataTemp = table.cache[tableId];
      if (!dataTemp || !dataTemp[from] || !dataTemp[to]) {
        // 没有找到对应的数据
        return that;
      }
      dataTemp.splice(to, 0, dataTemp.splice(from, 1)[0]);
 
      renderData.call(tableObj, to, true);
    }
    return that;
  };
 
  // 更新表格的数据
  var update = function (tableId, dataIndex, data) {
    var that = this;
 
    if (!tableId) {
      console.warn('tableId不能为空');
      return that;
    }
 
    if (dataIndex && (typeof dataIndex === 'object' || isArray(dataIndex))) {
      // 第二个参数如果是要修改的数据的话
      data = dataIndex;
      dataIndex = '';
    }
    if (dataIndex === null || isNaN(dataIndex)) {
      // 如果dataIndex不是数值就作废
      dataIndex = '';
    }
 
    if (data && (typeof data !== 'object' && !isArray(data))) {
      // 存在data,但是格式不对
      console.warn('data格式必须是对象或者数组');
      return that;
    }
 
    var tableObj = getIns(tableId);
    if (tableObj) {
      var dataTemp = table.cache[tableId];
      var options = tableObj.config;
      if (!data) {
        // 没有传data默认为重新渲染一下cache里面的数据
        renderData.call(tableObj);
        return that;
      }
 
      if (isArray(data)) {
        // 如果是一次性更新多条记录
        dataIndex = '';
      }
      if (dataIndex !== '') {
        // 更新指定的某一条记录
        $.extend(true, dataTemp[dataIndex], data);
      } else {
        if (!isArray(data)) {
          data = [data];
        }
        if (!options.primaryKey) {
          // 没有设置主键的表格按照顺序update进去
          $.extend(true, dataTemp, data);
        } else {
          // 如果设置了主键按照主键一致更新进去
          // 遍历更新的数据
          layui.each(data, function (index, obj) {
            if (!obj[options.primaryKey]) {
              // 等价 continue
              return;
            }
            // 遍历缓存数据找到匹配的
            layui.each(dataTemp, function (indexTemp, objTemp) {
              if (objTemp[options.primaryKey] === obj[options.primaryKey]) {
                $.extend(true, dataTemp[indexTemp], obj);
                // 等价 break;
                return true;
              }
            });
          });
        }
      }
      renderData.call(tableObj);
    }
    return that;
  };
 
  // 新增记录
  var add = function (tableId, data) {
    var that = this;
 
    if (!tableId) {
      console.warn('tableId不能为空');
      return that;
    }
 
    if (!data) {
      console.warn('data不能为空');
      return that;
    }
 
    var tableObj = getIns(tableId);
    if (tableObj) {
      var options = tableObj.config;
      if (options.url) {
        // 如果是url模式的话直接reload会更加合理
        table.reload(tableId);
        return that;
      } else {
        if (isArray(options.data)) {
          if (typeof data !== 'object' && !isArray(data)) {
            console.warn('data必须是对象或者数组');
            return that;
          }
          // data 模式
          if (!isArray(data)) {
            data = [data];
          }
          var primaryKey = getPrimaryKey(options);
          layui.each(data, function (index, _data) {
            if (primaryKey) {
              // 如果有设置主键
              if (!_data[primaryKey]) {
                // 缺少主键的记录,临时生成一个,一般来说不建议缺少主键的值,这个add的功能常用在请求接口之后返回新增的数据了希望添加到data中
                // 如果新增走的不是先请求接口的建议还是用addTemp添加临时数据的形式
                _data[primaryKey] = 'idTemp_' + new Date().getTime() + '_' + Math.round(Math.random() * 1000000)
              }
            }
            options.data.push(_data)
          });
          table.reload(tableId);
        }
        return that;
      }
    }
  };
 
  // 删除记录
  var del = function (tableId, data) {
    var that = this;
    if (!tableId) {
      console.warn('tableId不能为空');
      return that;
    }
    if (!data && data !== 0) {
      console.warn('data不能为空');
      return that;
    }
 
    var tableObj = getIns(tableId);
    if (tableObj) {
      var options = tableObj.config;
      var optionsTemp = {};
      var countTemp = tableObj.count || (options.page ? options.page.count : options.data.length);
      var primaryKey = getPrimaryKey(options);
      if (options.url) {
        if (options.page) {
          if (isArray(data)) {
            countTemp -= data.length;
          } else {
            countTemp -= 1;
          }
          optionsTemp.page = {};
          var pagesTemp = Math.ceil(countTemp / options.page.limit);
          optionsTemp.page.curr = countTemp === 0 ? 1 : (tableObj.page > pagesTemp ? (pagesTemp || 1) : tableObj.page);
        }
        layui.each(data, function (index, item) {
          var idTemp = typeof item === 'object' ? item[primaryKey] : item;
          // 将选中的记录给去掉如果有的话
          tableCheck.update(tableId, idTemp, false);
        });
        // 如果是url模式的话直接reload会更加合理
        table.reload(tableId, optionsTemp);
        return that;
      } else {
        if (isArray(options.data)) {
          // data 模式
          if (typeof data !== 'object' && !isArray(data)) {
            if (isNaN(data)) {
              return that;
            }
            var nodeDel;
            // 删除某个下标
            if (options.page) {
              // 分页的
              if (data < options.page.limit) {
                nodeDel = options.data.splice((tableObj.page - 1) * options.page.limit + data, 1);
              }
            } else {
              nodeDel = options.data.splice(data, 1);
            }
            if (!nodeDel.length) {
              // 传过来的下标有问题,没有删除到数据
              return that;
            }
            countTemp -= 1;
            tableCheck.update(tableId, nodeDel[0][primaryKey], false);
          } else {
            if (!isArray(data)) {
              data = [data];
            }
            layui.each(data, function (index, _data) {
              if (primaryKey) {
                // 如果有设置主键
                if (_data && typeof _data === 'object' && !_data[primaryKey]) {
                  // 缺少主键的记录
                  return;
                }
              }
              layui.each(options.data, function (index, value) {
                // 传过来的data支持id集合和数据对象集合
                if (_data === value[primaryKey] || _data[primaryKey] === value[primaryKey]) {
                  options.data.splice(index, 1);
                  tableCheck.update(tableId, value[primaryKey], false);
                  countTemp -= 1;
                  return true;
                }
              });
            });
          }
          if (options.page) {
            optionsTemp.page = {};
            var pagesTemp = Math.ceil(countTemp / options.page.limit);
            optionsTemp.page.curr = countTemp === 0 ? 1 : (tableObj.page > pagesTemp ? (pagesTemp || 1) : tableObj.page);
          }
          table.reload(tableId, optionsTemp);
        }
        return that;
      }
    }
  };
 
  // 定时刷新某个表格
  var refresh = function (tableId, time) {
    var that = this;
    var timer = refresh.timer;
    if (tableId === false) {
      // 取消所有的定时刷新
      layui.each(timer, function (_id, _timer) {
        // clearInterval(_timer);
        refresh.clear(_id);
      });
      // refresh.timer = {};
      return that;
    }
    if (!tableId) {
      console.warn('tableId不能为空');
      return that;
    }
    var tableObj = getIns(tableId);
    if (!tableObj) {
      console.warn('找不到id为', tableId, '的实例');
      return that;
    }
    var options = tableObj.config;
 
    if (time === false) {
      // 清除当前表格的定时刷新
      // clearInterval(timer[tableId]);
      // delete timer[tableId];
      refresh.clear(tableId);
      return that;
    }
 
    if (!time && time !== 0) {
      // 单次刷新
      tableObj.pullData(tableObj.page, true);
      return that;
    }
 
    if (time === true || time < 50) {
      time = 50; // 默认最高频率为50毫秒一次
    }
 
    // clearInterval(timer[tableId]);
    refresh.clear(tableId);
    timer[tableId] = {
      time: time,
      index: setInterval(function () {
        if (!$(document).find(options.elem).length) {
          // 如果当前表格已经不存在
          refresh.call(that, tableId, false);
        } else {
          // tableObj.pullData(tableObj.page, true)
          refresh(tableId);
        }
      }, time)
    };
 
  };
  refresh.timer = {};
  refresh.clear = function (tableId) {
    if (refresh.timer[tableId]) {
      clearInterval(refresh.timer[tableId].index);
      var time = refresh.timer[tableId].time;
      delete refresh.timer[tableId];
      return time;
    }
  };
  refresh.reset = function (tableId) {
    refresh(tableId, refresh.clear(tableId));
  };
 
 
  // 渲染统计行
  var renderTotal = function (tableId, field, value) {
    var that = this;
    if (!tableId) {
      console.warn('tableId不能为空');
      return that;
    }
    var tableObj;
    if (typeof tableId === 'string') {
      tableObj = getIns(tableId);
    } else {
      tableObj = tableId;
      tableId = tableObj.key || (tableObj.config ? tableObj.config.id : '');
    }
 
    if (!tableObj || !tableId) {
      console.warn('找不到id为', tableId, '的实例');
      return that;
    }
    var options = tableObj.config;
    if (!options.totalRow) {
      return that;
    }
 
    var totalElem = tableObj.layTotal;
    if (field) {
      totalElem.find('td[data-field="' + field + '"] div.layui-table-cell').html(value || '');
      return that;
    }
    table.eachCols(tableId, function (index, item) {
      if (item.totalRow && !item.totalRowText && item.field) {
        var fieldTemp = item.field;
        var totalFormat = item.totalFormat || 'sum';
        var dataTemp = $.extend([], table.cache[tableId]);
        var res;
        if (typeof totalFormat === 'function') {
          res = totalFormat.call(options, tableId, dataTemp, fieldTemp);
        } else {
          res = 0;
          switch (totalFormat) {
            case 'sum':
              layui.each(dataTemp, function (index, data) {
                res += parseFloat(data[fieldTemp]) || 0;
              });
              break;
          }
        }
        res && totalElem.find('td[data-field="' + fieldTemp + '"] div.layui-table-cell').html(res || '');
      }
    });
 
  };
 
 
  $.extend(tablePlug, {
    CHECK_TYPE_ADDITIONAL: CHECK_TYPE_ADDITIONAL
    , CHECK_TYPE_REMOVED: CHECK_TYPE_REMOVED
    , CHECK_TYPE_ORIGINAL: CHECK_TYPE_ORIGINAL
    , tableCheck: tableCheck
    , colFilterRecord: colFilterRecord  // 表格字段筛选记忆功能的封装
    , getConfig: getConfig  // 表格复选列的方法封装
    , getIns: function (tableId) { // 获得某个表格render返回的实例的封装
      return tableIns[tableId];
    }
    , disabledCheck: function (tableId, data) {  // 同步表格中的某些不可点击的节点
      var that = this;
      tableCheck.disabled(tableId, data || []);
      disabledCheck.call(that, tableId, true);
    }
    , dataRenderChecked: dataRenderChecked
    // , getObj: getIns  // 得到当前table的实际的实例
    , queryParams: queryParams // 表格查询模式的配置封装
    , smartReload: smartReload // 全局设置一个是否开启智能重载模式
    // 反选
    , tableFilterInvert: function (elem) {
      elem = $(elem);
      var tableView = elem.closest('.layui-table-view'),
        tableId = tableView.attr('lay-id');
      if (!tableId) {
        return;
      }
      var checkStatus = table.checkStatus(tableId);
      if (checkStatus.isAll) {
        // 以前全选了反选既为全不选,直接点击一下全选这个复选框就可以了
        tableView.find('[lay-filter="layTableAllChoose"]+').click();
      } else {
        if (!tableView.find('tbody [name="layTableCheckbox"]:checked').length) {
          // 如果一个都没有选中也是直接点击全选按钮
          tableView.find('[lay-filter="layTableAllChoose"]+').click();
        } else {
          layui.each(tableView.find('tbody [name="layTableCheckbox"]'), function (index, item) {
            $(item).next().click();
          });
        }
      }
    }
    , getPosition: getPosition
    , reverseTable: reverseTable
    , move: move
    , moveUp: function (tableId, index) {
      return move.call(this, tableId, index, index - 1);
    }
    , moveDown: function (tableId, index) {
      return move.call(this, tableId, index, index + 1);
    }
    , update: update
    , addData: add
    , del: del
    , refresh: refresh
    , renderTotal: renderTotal
    , enableTableFixedScroll: enableTableFixedScroll
  });
 
  //外部接口
  exports(modelName, tablePlug);
});