GridTable_wev8.js
23.8 KB
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
define(['mUtil', "Component", "wev-loading", "fieldParseHelper", "pageExpandHelper", "mApi/popup"], function (mUtil, Component, WevLoading, fieldHelper, pageExpandHelper) {
var GridTable = function (options) {
var _gridTable = {};
Component.super(this, options);
this.type = "GridTable";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
this.keysOfSkipedVarParse = ['dataurl'];
this.dataload = true;
this.components = {
loading: new WevLoading({
delay: 300,
animation: 1
}),
moreLoading: new WevLoading({
btn: 1,
onclick: function (hideLoading) {
_gridTable.loadData(hideLoading);
}
})
};
var vm = this.viewModel = {
pageSize: 10,
showFields: [],
normalSearch: {
hide: false, //是否隐藏查询
tip: "请输入。。。",
fields: [] //指定查询列
},
advancedSearch: {},
btns: [],
options: {
width: "100%",
height: 300,
fixedColumn: 0, //锁定列数
groupsum: false, //分组合计
totalsum: false, //总计
groupsum_title: "小计", //小计
totalsum_title: "总计", //总计
unreadBadge: false
},
readonly: false //是否数据只读
};
this.beforeMount = function () {
var fieldSets = vm.showFields;
vm.headerView = {};
if (mUtil.isArray(fieldSets) && fieldSets.length) {
var normalCols = [];
fieldSets.forEach(function (item) {
normalCols.push({
text: item.text,
width: item.width
});
});
vm.headerView.normal = normalCols;
}
if (vm.headerView.normal) {
var fixedColumn = vm.options.fixedColumn || 0;
var fixedCols = [];
vm.headerView.normal.forEach(function (col, index) {
if (index < fixedColumn) {
fixedCols.push(col);
col.fixedColumn = true;
}
col.width = mUtil.toPixel(col.width, "width");
});
vm.headerView.fixed = fixedCols;
}
var gtWidth = vm.options.width;
if (gtWidth) {
vm.options.width = mUtil.toPixel(gtWidth, "width");
}
var gtHeight = vm.options.height;
if (gtHeight) {
vm.options.height = mUtil.toPixel(gtHeight, "max-height");
} else {
vm.options.autoHeight = true;
vm.options.height = "height:auto";
}
//过滤历史数据中静态页中的扩展按钮,改为动态获取
if (vm.btns) {
vm.btns = vm.btns.filter(function (ele) {
//历史数据无vm.pageExtend参数
if (ele.id.startsWith("pageexpandBtn")) vm.pageExtend = true;
return !ele.id.startsWith("pageexpandBtn");
});
}
};
var $comp;
this.mounted = function () {
var that = this;
$comp = this.$comp;
// 初始化表格数据
_gridTable.refreshList();
// 初始化搜索功能
_gridTable.initSearch();
//初始化自定义按钮,切换显示按钮
_gridTable.initBtns();
var winHeight = $(window).height();
var pageHeight = $(".page-scroller", this.$container).height();
if(winHeight - pageHeight >= -1){//page-scroller不大于窗口高度时,去除表格标题栏touchmove默认事件,避免ios中会拖动整个页面
$comp.find(".wev-gridtable-main-content-wrapper>table").on('touchmove', function(event){
event.preventDefault();
});
}
if (vm.options.readonly) return;
//绑定单条数据,左滑按钮点击事件
var $mainTb = $comp.find(".wev-gridtable-main-content-body-wrapper>table");
$mainTb.on("click", "tr:not(.wev-groupsum)", function(e){
if($(e.target).closest('.wev-file[data-docid]').length) return;
var $element = $(this);
var dataid = $element.attr("data-id");
var currItem = {}, dataurl;
//自动解析页面移除未读、反馈角标
if(vm.options.unreadBadge && $element.find('span.wev-read-status').length && vm.options.urltype == '0'){
var $list = $(".wev-gridtable-main-content-body-wrapper > table > tbody", $comp);
$list.find('tr[data-id="'+dataid+'"] span.wev-read-status').remove();
}
_gridTable.state.list.every(function (item) {
if (item.id != dataid) return true;
currItem = item;
return false;
});
if (vm.callback && mUtil.isFunction(vm.callback.click)) {
vm.callback.click.call(this, currItem);
}
if (!currItem.id) return;
if(vm.options.urltype == 0){
if (vm.layoutUrl) {
$u(vm.layoutUrl + "&billid=" + currItem.id);
} else {
Mobile_NS.getLayoutUrl(vm.relate.modeid, 1, currItem.id);
}
}else if(currItem.dataurl){
var dataurl = currItem.dataurl;
if (dataurl.indexOf("javascript") === 0) {
mUtil.eval(dataurl, that.pageid);
} else {
$u(dataurl);
}
}
});
if (vm.options.urltype !== 0) return;
// 自动解析地址 解析布局url
var url = mUtil.getActionUrl("service.FormComponent", { action: "resolveDefaultLayout" });
mUtil.getJSON(url, { modelid: vm.relate.modeid, appid: vm.relate.appid, uitype: 1 }, function (result) {
vm.layoutUrl = result.data || "";
require(["mApi/other"]);//TODO 预加载
}, function (errMsg) { });
};
this.reload = function (args, callback) {
_gridTable.state.dynamicParam = {};
if (mUtil.isObject(args)) {
$.extend(_gridTable.state.dynamicParam, args);
}
_gridTable.refreshList(callback);
};
_gridTable.state = {
timestamp: 0,
pageNo: 0,
list: [],
conditions: {},
dynamicParam: {}
};
_gridTable.initSearch = function () {
var $search = $(".wev-search", this.$comp),
$searchInput = $("input", $search);
$search.on("click.active", ".wev-placeholder", function (e) {
$search.addClass("wev-active").removeClass("wev-inactive");
$searchInput.focus();
}).on("click.clear", ".wev-clear-btn", function () {
$searchInput.val("").focus().triggerHandler("input");
_gridTable.state.conditions = {};
});
// 搜索框事件
$searchInput.on("blur", function () {
if (this.value) return;
$search.removeClass("wev-active").addClass("wev-inactive");
}).on("input", function () {
$search.toggleClass("wev-has-value", !!this.value);
}).on("keyup", function (e) {
if (e.keyCode !== 13) return;
_gridTable.state.conditions.searchKey = encodeURIComponent(this.value);
_gridTable.state.conditions.searchFields = JSON.stringify(vm.normalSearch.fields || []);
_gridTable.refreshList();
this.blur();
});
if (!vm.advancedSearch.enable) return;
require(["css!listAdvancedSearch_css"]);
// 高级搜索
var timestamp = new Date().valueOf(), pageid = this.pageid.split("_").slice(1).join("."), id = this.id;
$search.on("click.advancedSearch", ".wev-search-advanced", function () {
require(["mService"], function (mService) {
mService.show("search", {
_identity: id + "_" + timestamp,
id: id,
pageid: pageid,
searchid: vm.sourceid,
conditions: JSON.stringify(vm.advancedSearch.fields),
title: vm.advancedSearch.title
});
});
});
};
_gridTable.initBtns = function () {
var that = this,
pageid = this.pageid;
if (vm.pageExtend) {
var cfg = {
pageid: pageid,
searchid: vm.sourceid
};
pageExpandHelper.parsePageExpand($comp.find(".wev-search"), that.id, cfg);
}
if (!vm.btns.length) return;
vm.btns.forEach(function (item) {
if(item.script && !item.click){
item.click = mUtil.strToFunc(item.script);
}
});
$(".wev-list-btn-container", $comp).on("click", ".btn.wev-btn-custom", function () {
var index = $(this).index(),
btn = vm.btns[index];
mUtil.eval(btn.click, pageid);
});
};
_gridTable.refreshList = function (cb) {
var that = this,
loading = this.components.loading,
moreLoading = this.components.moreLoading,
state = _gridTable.state;
loading.setRefs(this.$comp, "wev-refreshing");
loading.show();
state.pageNo = 0;
state.list = [];
_gridTable.loadData(function (hasMore, noData) {
loading.hide();
moreLoading.hide(hasMore, noData);
cb && cb();
mUtil.trigger('dataload', that.pageid, that.id);
// 支持上拉刷新功能, 表格为自适应高度时,需要为最后一个插件,且容器为page-content
if(hasMore && (!vm.options.autoHeight || mUtil.canPullToRefresh(that.id))) {
require(['pullToRefreshHelper'], function (PullToRefresh) {
var $tableWrapper = $comp.find('.wev-gridtable-main-content-body-wrapper');
var $container = $tableWrapper;
if (vm.options.autoHeight) {
$container = $comp.closest('.page-content');
}
new PullToRefresh({
el: $tableWrapper.children('table'),
container: $container.get(0),
loadData: _gridTable.loadData,
loading: that.components.moreLoading
});
});
}
});
};
_gridTable.loadData = function (callback) {
var that = this;
var $comp = that.$el;
var timestamp = new Date().valueOf(); //时间戳
var state = _gridTable.state;
state.timestamp = timestamp;
state.pageNo++;
var pageNo = state.pageNo, groupfield = '';
if(vm.options.groupsum && vm.showFields.length){
groupfield = vm.showFields[0].fieldid;
}
var parseFields = fieldHelper.parseFieldIds(JSON.stringify(vm.showFields));
var reqparam = {action: "getDatas", searchid: vm.sourceid, pageNo: pageNo, pageSize: vm.pageSize, fieldparse: parseFields, groupfield: groupfield, unreadBadge: vm.options.unreadBadge };
//拓展请求参数
$.extend(true, reqparam, state.dynamicParam);
var actionUrl = mUtil.getActionUrl(that.type, reqparam, that.pageid);
mUtil.getJSON(actionUrl, state.conditions, function (result) {
result = result.data;
if (timestamp != state.timestamp) return;
var fieldmap = result.fieldMap, listDatas = [], normalDatas = [];
var needReplaceUrl = mUtil.containsVariables(vm.options.dataurl);
result.datas.forEach(function(data){
var dataItem = {};
var dataId = data.keyvalue;
var dataurl = "";
if(vm.options.urltype == 1 && vm.options.dataurl){
dataurl = needReplaceUrl ? fieldHelper.replaceVal(vm.options.dataurl, data.dataMap) : vm.options.dataurl;
if(dataurl.indexOf("javascript:") == -1){
if(!vm.options.isNewLayout && dataurl.indexOf("&billid=") == -1 && dataurl.indexOf("?billid=") == -1){
dataurl += (dataurl.indexOf("?") == -1 ? "?" : "&") + "billid=" + dataId;
}
}
}else{
dataurl = "javascript:void(0);";
}
dataItem.id = dataId;
dataItem.dataurl = dataurl;
dataItem.dataMap = data.dataMap;
listDatas.push(dataItem);
var normalDataItem = convertShowValue(data, fieldmap, vm.showFields);
normalDatas.push(normalDataItem);
});
mUtil.concat(state.list, listDatas);
var templateHtml = [
'{@each datas as row}',
'<tr data-id="${row.id}">',
'{@each row.cols as col,index}',
'<td {@if col.fixedColumn === true}class="wev-gridtable-fixed-col"{@/if} style="${col.columnWidth}" data-value="${col.cleanValue}" data-htmltype="${col.htmltype}" data-type="${col.type}">',
'$${col.columnValue}',
'{@if index == 0}',
'{@if col.readStatus == "1"}',
'<span class="wev-read-status wev-unread"></span>',
'{@else if col.readStatus == "2"}',
'<span class="wev-read-status wev-feedback"></span>',
'{@/if}',
'{@/if}',
'</td>',
'{@/each}',
'</tr>',
'{@/each}'
].join('');
var html = mUtil.parseTemplate(templateHtml, {datas: normalDatas}),
$list = $(".wev-gridtable-main-content-body-wrapper > table > tbody", $comp);
if (pageNo == 1) {
$list.html("");
}
var $newList = $(html);
$list.append($newList);
require(["lazyImgHelper"]);
//分组合计
_gridTable.groupSum();
if (pageNo == 1) {
//保证标题宽度和内容宽度相等
_gridTable.resetGridColumnWidth();
//初始化固定列
_gridTable.initFixedColumn();
}
_gridTable.updateFixedContentColumn();
var hasMore = pageNo < result.totalPageCount;
var noData = result.totalSize <= 0;
callback(hasMore, noData);
});
};
function convertShowValue(billdata, fieldmap, fieldset){
return {
id: billdata.keyvalue,
cols: fieldset.map(function(field, index){
var fieldid = field.fieldid, formField = fieldmap[fieldid], dataMap = billdata.dataMap, cleanValue = '';
var columnValue = fieldHelper.getFieldValue(field, billdata, fieldmap);
columnValue && (cleanValue = columnValue.replace(/<[^>]+>/g, ''));
return {
columnValue : columnValue,
columnWidth : mUtil.toPixel(field.width, "width"),
cleanValue : cleanValue,
htmltype : formField.fieldhtmltype,
type : formField.fieldtype,
fixedColumn : index < vm.options.fixedColumn,
readStatus : billdata.readStatus
}
})
};
}
_gridTable.groupSum = function () {
if (!vm.options.groupsum && !vm.options.totalsum) return;
var that = this,
groupsum = vm.options.groupsum,
totalsum = vm.options.totalsum,
fixedColumn = vm.options.fixedColumn;
var sumArr = [];
var totalSumArr = [];
$(".wev-gridtable-main-content-body-wrapper>table>tbody>tr.wev-groupsum", this.$el).remove();
$(".wev-gridtable-main-content-body-wrapper>table>tbody>tr", this.$el).each(function (i) {
var $row = $(this);
$row.children("td").each(function (j) {
var totalCalculate = 0,
isThousands = false,
$col = $(this),
htmltype = $col.attr("data-htmltype"),
type = $col.attr("data-type");
if (htmltype != "1") return;
if (type == "2" || type == "3") {
totalCalculate = 1;
} else if (type == "4" || type == "5") {
totalCalculate = 1;
isThousands = true;
}
if (totalCalculate == 0) return;
var dv = $col.attr("data-value");
dv = dv.replace(/,/g, "");
if (!isNaN(dv) && dv != "") {
var sv = sumArr[j] || "0";
sv = sv.replace(/,/g, "");
sumArr[j] = accAdd(sv, dv);
var tsv = totalSumArr[j] || "0";
tsv = tsv.replace(/,/g, "");
totalSumArr[j] = accAdd(tsv, dv);
if (isThousands) {
sumArr[j] = changeToThousands(sumArr[j]);
totalSumArr[j] = changeToThousands(totalSumArr[j]);
}
}
});
if (!groupsum) return;
var $firstCol = $row.children("td").first();
var firstColVal = $firstCol.attr("data-value");
var $nextfirstCol = $row.next().children("td").first();
var nextfirstColVal = $nextfirstCol.attr("data-value");
if (firstColVal == nextfirstColVal) return;
var $groupRow = $row.clone();
var $groupCol = $groupRow.children("td");
$groupRow[0].className = "wev-groupsum";
$groupCol.html("").first().html(vm.options.groupsum_title);
$groupCol.each(function (j) {
if (j === 0) return;
$(this).html(sumArr[j] || "");
});
$row.after($groupRow);
sumArr = [];
});
var $lastRow = $(".wev-gridtable-main-content-body-wrapper>table>tbody>tr", that.$el).last();
if (!totalsum || !$lastRow.length) return;
var $totalRow = $lastRow.clone();
var $totalCol = $totalRow.children("td");
$totalRow[0].className = "wev-groupsum";
$totalCol.html("").first().html(vm.options.totalsum_title);
$totalCol.each(function (j) {
if (j === 0) return;
$(this).html(totalSumArr[j] || "");
});
$lastRow.after($totalRow);
};
// 两个浮点数求和
function accAdd(num1, num2) {
var r1 = num1.toString().split('.')[1],
r2 = num2.toString().split(".")[1], m, sum;
r1 = r1 && r1.length || 0;
r2 = r2 && r2.length || 0;
m = Math.pow(10, Math.max(r1, r2));
sum = Math.round(num1 * m + num2 * m) / m;
sum = sum.toFixed(Math.max(r1, r2));// 恢复浮点数结果精度
return sum;
}
function changeToThousands(sv) {
sv = sv.replace(/\s+/g, "") || "";
return commafy(sv);
}
/**
* 数字格式转换成千分位
* @param{Object}num
*/
function commafy(num) {
num = num + "";
num = num.replace(/[ ]/g, ""); //去除空格
if (!num || isNaN(num)) return "";
//2.针对是否有小数点,分情况处理
var index = num.indexOf("."),
reg = /(-?\d+)(\d{3})/;
if (index == -1) {//无小数点
while (reg.test(num)) {
num = num.replace(reg, "$1,$2");
}
} else {
var intPart = num.substring(0, index);
var pointPart = num.substring(index + 1, num.length);
while (reg.test(intPart)) {
intPart = intPart.replace(reg, "$1,$2");
}
num = intPart + "." + pointPart;
}
return num;
}
_gridTable.resetGridColumnWidth = function () {
var that = this,
contentTdWidthArr = [];
//获取第一行数据的每列列宽
var $firstContentRow = $(".wev-gridtable-main-content-body-wrapper>table>tbody>tr", that.$el).first();
$firstContentRow.children("td").each(function () {
var w = $(this).width();
contentTdWidthArr.push(w);
});
var $firstTitleRow = $(".wev-gridtable-main-content-wrapper>table>thead>tr", that.$el).first();
//比较标题列宽是否等于数据列宽,如果不等于则重新计算标题列宽
$firstTitleRow.children("th").each(function (i) {
var $th = $(this);
var w = contentTdWidthArr[i];
if (w == null || typeof (w) == "undefined") {
return;
}
var w2 = $th.width();
if (w != w2) {
var p = getHorizontalPadding($th); //padding
var nw2 = w - p;
$th.css("width", nw2 + "px");
}
});
var cWidth = $(".wev-gridtable-main-content-body-wrapper>table", that.$el).width();
$(".wev-gridtable-main-content-body-wrapper", that.$el).width(cWidth);
};
function getHorizontalPadding($obj) {
var paddingLeft = $obj.css("padding-left") || "";
paddingLeft = paddingLeft.replace("px", "");
paddingLeft = parseInt(paddingLeft) || 0;
var paddingRight = $obj.css("padding-right") || "";
paddingRight = paddingRight.replace("px", "");
paddingRight = parseInt(paddingRight) || 0;
return paddingLeft + paddingRight;
}
_gridTable.fixedColumnWidth = 0;
_gridTable.initFixedColumn = function () {
var that = this,
fixedColumn = vm.options.fixedColumn;
//计算固定列容器宽度
var fixedColumnWidth = 0;
$(".wev-gridtable-main-content-wrapper>table>thead>tr", that.$el).first().children("th").each(function (i) {
if (i < fixedColumn) {
fixedColumnWidth += $(this).width() + 1;
}
});
//固定列标题宽度
$(".wev-gridtable-fixed-content-wrapper > table", that.$el).css("width", fixedColumnWidth + "px");
$(".wev-gridtable-fixed-content-wrapper", that.$el).css("width", fixedColumnWidth + "px");
$(".wev-gridtable-fixed-content-body-wrapper-mapping", that.$el).css("width", fixedColumnWidth + "px");
_gridTable.fixedColumnWidth = fixedColumnWidth;
//修复固定列标题高度和内容标题高度不等的问题
var $firstTitleRow = $(".wev-gridtable-main-content-wrapper>table>thead>tr", that.$el).first();
var $firstFixedTitleRow = $(".wev-gridtable-fixed-content-wrapper>table>thead>tr", that.$el).first();
if ($firstFixedTitleRow.length) {
var $col1 = $firstTitleRow.children("th").eq(0);
var h1 = $col1.height();
var contentH1 = $col1.css("height");
var $col2 = $firstFixedTitleRow.children("th").eq(0);
var h2 = $col2.height();
var contentH2 = $col2.css("height");
if (h1 > h2) {
$col2.css("height", contentH1);
} else if (h1 < h2) {
$col1.css("height", contentH2);
}
}
if (!vm.options.autoHeight) {
var rightScrolling = false;
var rightTimeoutId = null;
$(".wev-gridtable-main-content-body-wrapper", that.$el).on("scroll", function () {
if (leftScrolling || verticalScrolling) {
return;
}
rightScrolling = true;
if (rightTimeoutId) {
clearTimeout(rightTimeoutId);
}
$(".wev-gridtable-fixed-content-body-wrapper-mapping", that.$el).show();
$(".wev-gridtable-fixed-content-body-wrapper", that.$el).css("visibility", "hidden");
$(".wev-gridtable-fixed-content-body-wrapper", that.$el).scrollTop($(this).scrollTop());
rightTimeoutId = setTimeout(function () {
rightScrolling = false;
}, 1000);
});
var leftScrolling = false;
var leftTimeoutId = null;
$(".wev-gridtable-fixed-content-body-wrapper", that.$el).on("scroll", function () {
if (rightScrolling || verticalScrolling) {
return;
}
leftScrolling = true;
if (leftTimeoutId) {
clearTimeout(leftTimeoutId);
}
$(".wev-gridtable-fixed-content-body-wrapper-mapping", that.$el).show();
$(this).css("visibility", "hidden");
$(".wev-gridtable-main-content-body-wrapper", that.$el).scrollTop($(this).scrollTop());
leftTimeoutId = setTimeout(function () {
leftScrolling = false;
}, 1000);
});
var verticalScrolling = false;
var verticalTimeoutId = null;
$(".wev-gridtable-main-content-wrapper", that.$el).on("scroll", function () {
verticalScrolling = true;
if (verticalTimeoutId) {
clearTimeout(verticalTimeoutId);
}
$(".wev-gridtable-fixed-content-body-wrapper", that.$el).css("visibility", "visible");
$(".wev-gridtable-fixed-content-body-wrapper-mapping", that.$el).hide().css("left", $(this).scrollLeft() + "px");
verticalTimeoutId = setTimeout(function () {
verticalScrolling = false;
}, 100);
});
}
};
_gridTable.updateFixedContentColumn = function () {
var that = this,
fixedColumn = vm.options.fixedColumn;
if (!fixedColumn || fixedColumn < 1) {
return;
}
var $gtContent = $(".wev-gridtable-main-content-body-wrapper>table", that.$el);
var $cloneGtContent = $gtContent.clone();
$("tr", $cloneGtContent).each(function () {
var $row = $(this);
$row.children("td").not(".wev-gridtable-fixed-col").remove();
$row.children("td").removeClass("wev-gridtable-fixed-col");
});
$cloneGtContent.css("width", _gridTable.fixedColumnWidth + "px");
var $fixedGtContent = $(".wev-gridtable-fixed-content-body-wrapper", that.$el);
$fixedGtContent.find("*").remove();
$fixedGtContent.append($cloneGtContent);
var $cloneGtContent2 = $cloneGtContent.clone();
var $fixedGtContentMapping = $(".wev-gridtable-fixed-content-body-wrapper-mapping", that.$el);
$fixedGtContentMapping.find("*").remove();
$fixedGtContentMapping.append($cloneGtContent2);
resetFixedGridContentHeight(this.$el);
};
function resetFixedGridContentHeight($el) {
//修复固定列行高
$(".wev-gridtable-main-content-body-wrapper>table>tbody>tr", $el).each(function (i) {
var $row = $(this);
var $col = $row.children("td").eq(0);
var h = $col.height();
var contentH = $col.css("height");
var $col2 = $(".wev-gridtable-fixed-content-body-wrapper>table>tbody>tr", $el).eq(i).children("td").eq(0);
var h2 = $col2.height();
var contentH2 = $col2.css("height");
var $col3 = $(".wev-gridtable-fixed-content-body-wrapper-mapping>table>tbody>tr", $el).eq(i).children("td").eq(0);
var h3 = $col3.height();
if (h > h2) {
$col2.css("height", contentH);
$col3.css("height", contentH);
} else if (h < h2) {
$col.css("height", contentH2);
}
});
}
_gridTable.refreshList = _gridTable.refreshList.bind(this);
_gridTable.initSearch = _gridTable.initSearch.bind(this);
_gridTable.loadData = _gridTable.loadData.bind(this);
_gridTable.groupSum = _gridTable.groupSum.bind(this);
_gridTable.resetGridColumnWidth = _gridTable.resetGridColumnWidth.bind(this);
_gridTable.initFixedColumn = _gridTable.initFixedColumn.bind(this);
_gridTable.updateFixedContentColumn = _gridTable.updateFixedContentColumn.bind(this);
_gridTable.initBtns = _gridTable.initBtns.bind(this);
};
return Component.init(GridTable);
});