Universal.js
45.4 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
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
var SelectorSource = {};
layui.define(function (exports) {
var obj = {
mmain: function (AreaName, TableName, table, layer, element, laydate, $, vm, vmq, EditInfo, selfbtn, mainList, form) {
//监听行单击事件(双击事件为:rowDouble)
table.on('row(mainList)', function (obj) {
table.on('checkbox(mainList)', function (obj) {
if (obj.checked == true) {
obj.tr.addClass('layui-table-click');
} else {
obj.tr.removeClass('layui-table-click');
}
});
});
//监听表格排序
table.on('sort(mainList)', function (obj) {
table.reload('mainList', {
url: "/" + AreaName + "/" + TableName + '/Load',
initSort: obj //记录初始排序,如果不设的话,将无法标记表头的排序状态。 layui 2.1.1 新增参数
, method: "POST"
, where:
{
field: obj.field //排序字段
, order: obj.type//排序方式
}
});
});
//头工具栏事件
table.on('toolbar(mainList)', function (obj) {
var checkStatus = table.checkStatus('mainList');
var count = checkStatus.data.length;//选中的行数
switch (obj.event) {
//新增数据
case 'tabAdd':
vm.$set('$data', {});
//新增前的处理方法
if (selfbtn['DomConfig'] !== undefined) {
selfbtn['DomConfig'].call(null, true);
}
layer.open({
title: '新增',
area: ["750px", "450px"],
maxmin: true,
type: 1,
content: $('#modifyForm'),
btn: ['保存', '关闭'],
yes: function (index) {
//保存前方法
if (selfbtn['SaveBefore'] !== undefined) {
var rtn = selfbtn['SaveBefore'].call(null, "Add");
if (rtn != null) {
if ($(rtn[0]).context.tagName == "SELECT") {
$($(rtn[0]).next()[0].children[0].firstChild).attr("placeholder", "此项为必填项");
}
layer.alert("必填项不能为空", { icon: 5, shadeClose: true, title: "错误信息" });
$(rtn).css("background-color", "yellow");
$(rtn).focus();
return null;
}
}
$.ajax({
url: "/" + AreaName + "/" + TableName + "/Ins",
type: "post",
data: { Table_Entity: vm.$data },
dataType: "json",
success: function (result) {
if (result.Code == 200 && result.Status) {
layer.msg('新增成功', { icon: 6, shade: 0.4, time: 1000 });
layer.close(index);
mainList.mainList();//重载TABLE
//保存成功方法
if (selfbtn['SaveSuccess'] !== undefined) {
selfbtn['SaveSuccess'].call(null, "Add");
}
}
else {
layer.alert(result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
},
btn2: function (index) {
layer.close(index);
}
, end: function (index, layero) {
ClearSelect(TableName, $, form);
}
});
break;
//编辑单笔数据
case 'btnEdit':
if (count == 1) {
EditInfo(checkStatus.data[0]);
//编辑前的处理方法
if (selfbtn['DomConfig'] !== undefined) {
selfbtn['DomConfig'].call(null, false);
}
layer.open({
title: '编辑',
area: ["750px", "450px"],
maxmin: true,
type: 1,
content: $('#modifyForm'),
btn: ['保存', '关闭'],
yes: function (index) {
//保存前方法
if (selfbtn['SaveBefore'] !== undefined) {
var rtn = selfbtn['SaveBefore'].call(null, "Edit");
if (rtn != null) {
if ($(rtn[0]).context.tagName == "SELECT") {
$($(rtn[0]).next()[0].children[0].firstChild).attr("placeholder", "此项为必填项");
}
layer.alert("必填项不能为空", { icon: 5, shadeClose: true, title: "错误信息" });
$(rtn).css("background-color", "yellow");
$(rtn).focus();
return null;
}
}
$.ajax({
url: "/" + AreaName + "/" + TableName + "/Upd",
type: "POST",
data: { Table_Entity: vm.$data },
dataType: "json",
success: function (result) {
if (result.Code == 200 && result.Status) {
layer.msg("修改成功!", { icon: 6, shade: 0.4, time: 1000 });
layer.close(index);
mainList.mainList();
//保存成功方法
if (selfbtn['SaveSuccess'] !== undefined) {
selfbtn['SaveSuccess'].call(null, "Edit");
}
} else {
layer.alert(result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
},
btn2: function (index) {
layer.close(index);
}
, end: function (index, layero) {
ClearSelect(TableName, $, form);
}
});
}
else
layer.alert("请选择一条数据", { icon: 5, shadeClose: true, title: "错误信息" });
break;
//上传数据
case 'btnUpload':
Import();
break;
//导出数据
case 'btnExport':
var index = layer.load();
$.ajax({
url: "/" + AreaName + "/" + TableName + "/Export",
type: "POST",
data: vmq.$data,
dataType: "json",
success: function (result) {
layer.close(index);
var ExportTitle = new Array();
var ExportData = result.data;
for (var i = 0; i < result.count; i++) {
var data = result.data[i];
for (var item in data) {
if (i == 0) {
ExportTitle.push(item);
}
}
}
table.exportFile(ExportTitle, ExportData, 'csv')
layer.msg("导出完成!", { icon: 6, shade: 0.4, time: 1000 });
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.close(index);
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
break;
//检索按钮,弹出检索区
case 'btnSelect':
panelSearch();
break;
//刷新数据
case 'btnRefresh':
mainList.mainList();
$('.layui-collapse').hide();
layer.closeAll();
break;
//批量删除数据
case 'btnDelete':
if (count > 0) {
//删除前方法
if (selfbtn['SaveBefore'] !== undefined) {
selfbtn['SaveBefore'].call(null, "Delete");
}
layer.confirm('确定要删除所选信息', { icon: 3 }, function (index) {
var data = checkStatus.data; //获取选中行的数据
$.ajax({
url: "/" + AreaName + "/" + TableName + "/DelByIds",
type: "post",
data: { ids: data.map(function (e) { return e.Id; }) },
dataType: "json",
success: function (result) {
if (result.Code == 200 && result.Status) {
layer.msg('删除成功', { icon: 6, shade: 0.4, time: 1000 });
layer.close(index);
mainList.mainList();//重载TABLE
//保存成功方法
if (selfbtn['SaveSuccess'] !== undefined) {
selfbtn['SaveSuccess'].call(null, "Delete");
}
$('.layui-collapse').hide();
}
else {
layer.alert(result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
});
}
else
layer.alert("请至少选择一条数据", { icon: 5, shadeClose: true, title: "错误信息" });
break;
}
//自定义按钮方法遍历
for (var key in selfbtn) {
if (obj.event == key)
selfbtn[key]();
}
});
//监听页面主按钮操作
var active = {
//检索区的查询按钮
btnQuery: function () {
var inputName = $('.layui-date').map(function () { return $(this).attr("name"); }).toArray();
var inputDate = $('.layui-date').map(function () { return $(this).val(); }).toArray();
var editTime = function (tmpTime) {
if (tmpTime.length === 4) {
return tmpTime = tmpTime + "-01-01 00:00:00.001";
}
else if (tmpTime.length === 7) {
return tmpTime = tmpTime + "-01 00:00:00.002";
}
else if (tmpTime.length === 10) {
return tmpTime = tmpTime + " 00:00:00.003";
}
else if (tmpTime.length === 13) {
return tmpTime = tmpTime + ":00:00.004";
}
else if (tmpTime.length === 16) {
return tmpTime = tmpTime + ":00.005";
}
else {
return tmpTime = tmpTime + ".000";
}
};
inputDate.forEach(function (item, len) {
if (item.length !== 0) {
var tmpTime = item.replace(" 00:00:00", "").replace(":00:00", "").replace(":00", "");
if (item !== "") {
var dateString = inputName[len].substring(1, inputName[len].length);
vmq[dateString] = editTime(tmpTime);
}
}
});
table.reload('mainList', {
page: { curr: 1 }
, url: "/" + AreaName + "/" + TableName + "/Load"
, method: "POST"
, where: vmq.$data
, text: { none: mainList.NoData() }
});
panelSearch();
},
//检索区重置按钮
btnReset: function () {
for (var item in vmq.$data) {
vmq.$data[item] = null;
$("[name='q" + item + "']").val('');
layui.form.render(); //下拉框等页面元素需要重渲染
}
},
//检索区关闭按钮
btnClose: function () {
panelSearch();
},
//下载模板
btnTemplate: function () {
var index = layer.load();
$.ajax({
url: "/" + AreaName + "/" + TableName + "/GetTemplate",
type: "POST",
dataType: "json",
success: function (result) {
layer.close(index);
var ExportTitle = new Array();
var ExportData = result.data;
for (var i = 0; i < result.count; i++) {
var data = result.data[i];
for (var item in data) {
if (i == 0) {
ExportTitle.push(item);
}
}
}
table.exportFile(ExportTitle, ExportData, 'csv')
layer.msg("导出模板完成!", { icon: 6, shade: 0.4, time: 1000 });
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.close(index);
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
}
};
$('.layui-btn').on('click', function () {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//监听页面主按钮操作 end
mainList.mainList();
function panelSearch() {
$('#panelSearch').toggle("fast");
}
function Import() {
layer.open({
type: 1,
skin: 'layui-layer-molv',
anim: 1,
id: 'LAY_layuipro', //设定一个id,防止重复弹出
btnAlign: 'c',
moveType: 1, //拖拽模式,0或者1
title: "请选择需导入的文件:", //不显示标题
area: ['400px', '300px'], //宽高
content: $('#ImportData'), //捕获的元素
scrollbar: false,
btn: ['导入', '关闭'],
yes: function () {
var index1 = layer.load();
var fileObj = document.getElementById("excelfile").files[0]; // js 获取文件对象
if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
layer.alert("请先选择需要上传的文件!", { skin: 'layui-layer-molv', anim: 1, icon: 5 });
layer.close(index1);
return;
}
var formFile = new FormData();
formFile.append("excelfile", fileObj); //加入文件对象
var data = formFile;
$.ajax({
url: "/" + AreaName + "/" + TableName + "/Import",
data: data,
type: "Post",
dataType: "json",
cache: false,//上传文件无需缓存
processData: false,//用于对data参数进行序列化处理 这里必须false
contentType: false, //必须
success: function (result) {
if (result.Code == 200) {
if (result.Status) {
layer.msg(result.Message, { icon: 6 });
}
else {
layer.alert(result.Message, { icon: 5, shade: 0.4, shadeClose: true, title: '导入失败' });
}
$('#excelfile').val("");
mainList.mainList();
}
}
});
layer.closeAll();
},
cancel: function (index) {
$("Hide").unbind();
layer.close(index);
}
});
}
//自动刷新
function AutoRefresh() {
if ($("#autoRefresh").get(0).checked) {
mainList.mainList();
}
}
if ($('#autoRefresh').length != 0) {
$(document).ready(
function () {
setInterval(AutoRefresh, 10000);
}
);
}
}
, BindSelector: function ($, form, vml, selector) {
var SelectorObject = {};
var vmList = new Array();
vmList = vml[0];
if (selector != null) {
Object.keys(selector).forEach(function (key) {
if (selector[key].Dom != null) {
var SelectObj = {
Dom: selector[key].Dom,
SelType: selector[key].SelType,
SelFrom: selector[key].SelFrom,
SelModel: selector[key].SelModel,
SelLabel: selector[key].SelLabel,
SelValue: selector[key].SelValue
};
SelectorObject[key] = new Array(SelectObj);
}
else {
var SelectObj2 = {
SelType: selector[key].SelType,
SelFrom: selector[key].SelFrom,
SelModel: selector[key].SelModel
};
SelectorObject[key] = new Array(SelectObj2);
}
});
}
//用jQuery的$.each(),自带回调函数,形成了函数作用域,替代解决JS的for循环包裹异步函数的问题
$.each(SelectorObject, function (key, value) {
var oItem = value[0];
var SelType = oItem.SelType;
var SelFrom = oItem.SelFrom;
var data, url;
if (SelType == "FromUrl") {
data = { limit: 1000 };
url = SelFrom;
}
else if (SelType == "FromDict") {
data = { DictType: SelFrom };
url = "/base/SysDictData/FindSysDictData";
}
$.ajax({
async: false,
type: "post",
data: data,
url: url,
dataType: "json",
success: function (result) {
if (result.count > 0) {
SelectorSource[oItem.SelModel] = result.data;
setTimeout(function () {
form.render('select'); //只渲染下拉框
}, 10);
form.on('select(qform)', function (data) {
vmList['vmq'].$data[$(data.elem).data("model")] = data.value;
});
form.on('select(eform)', function (data) {
if (vmList['vmDtl' + $(data.elem)[0].classList[1].split('_')[1]] == undefined) {
vmList['vm'].$data[$(data.elem).data("model")] = data.value;
} else {
vmList['vmDtl' + $(data.elem)[0].classList[1].split('_')[1]].$data[$(data.elem).data("model")] = data.value;
}
});
}
}
});
});
Object.keys(SelectorObject).forEach(function (key) {
if (SelectorObject[key][0].Dom != null) {
SelectorObject[key][0].Dom.forEach(function (value, i) {
var SelLabel = SelectorObject[key][0].SelLabel;
var SelValue = SelectorObject[key][0].SelValue;
for (var k = 0; k < value.length; k++) {
$(value[k]).empty();
$(value[k]).append("<option style='display: none'></option>");
if (SelectorSource[key] == undefined) {
console.log("数据源:[" + key + "]配置有误,请联系管理员!");
}
else {
for (var j = 0; j < SelectorSource[key].length; j++) {
$(value[k]).append("<option value = '" + SelectorSource[key][j][SelValue] + "'>" + SelectorSource[key][j][SelLabel] + "</option>");
}
}
}
});
}
});
}
, mainDtl: function (table, layer, element, $, selfbtn, All, form) {
var DtlShowbool = {};//所有折叠的当前状态
var Dtl = {};//当前点击All数据
var Value = {};//主表数据缓存数据
var Values = new Array();//主表数据缓存数据集合
//所有折叠状态初始化
for (i = 0; i < All.length; i++) {
DtlShowbool[All[i].TableNameDtl] = false;
}
//监听单元格点击
table.on('tool(mainList)', function (obj) {
var Dtlbtn = {};
var mainListDtl;
for (i = 0; i < All.length; i++) {
if (obj.event === All[i].TableNameDtl) {
Dtl = All[i];
}
}
if (Dtl != {}) {
for (i = 0; i < Object.keys(Dtl.NameDtl).length; i++) {
//主表数据赋值
Value[Object.keys(Dtl.NameDtl)[i]] = obj.data[Dtl.NameDtl[Object.keys(Dtl.NameDtl)[i]]];
Values[Dtl.TableNameDtl] = Value;
//重载赋值(防止主子表字段名不一样)
if (obj.data[Dtl.NameDtl[Object.keys(Dtl.NameDtl)[i]]] != null) {
Dtl.vmqDtl.$data[Object.keys(Dtl.NameDtl)[i]] = obj.data[Dtl.NameDtl[Object.keys(Dtl.NameDtl)[i]]];
} else {
Dtl.vmqDtl.$data[Object.keys(Dtl.NameDtl)[i]] = '###';
}
}
//重载方法
mainListDtl = {
mainListDtl: function (mainDtl) {
table.reload('mainListDtl' + mainDtl.TableNameDtl, {
url: "/" + mainDtl.AreaNameDtl + "/" + mainDtl.TableNameDtl + "/Load"
, where: mainDtl.vmqDtl.$data
, method: "post"
, page: { curr: 1 }
});
}
};
//监听折叠
element.on('collapse(DisplayDtl)', function (data) {
//记录当前折叠状态
DtlShowbool[data.title[0].id.split('_')[1]] = data.show;
//头工具栏事件
table.on('toolbar(mainListDtl' + data.title[0].id.split('_')[1] + ')', function (obj) {
for (i = 0; i < All.length; i++) {
if (obj.event.split('_')[1] === All[i].TableNameDtl) {
Dtlbtn = All[i];
}
}
if (Dtlbtn != {}) {
var checkStatus = table.checkStatus('mainListDtl' + Dtlbtn.TableNameDtl);
var count = checkStatus.data.length;//选中的行数
switch (obj.event) {
case 'tabAddDtl_' + Dtlbtn.TableNameDtl: //跳转至单据页面,新增数据
//新增前的处理方法
if (selfbtn['DomConfig_' + Dtlbtn.TableNameDtl] !== undefined) {
var rtn = selfbtn['DomConfig_' + Dtlbtn.TableNameDtl].call(null,"Add", Dtlbtn.vmqDtl._data);
if (rtn == false) { return null; }
}
layer.open({
type: 1
, area: ['600px', '500px']
, content: $('#modifyFormDtl_' + Dtlbtn.TableNameDtl)
, success: function (layero, index) {
for (i = 0; i < Object.keys(Values[Dtlbtn.TableNameDtl]).length; i++) {
Dtlbtn.vmDtl.$set(Object.keys(Values[Dtlbtn.TableNameDtl])[i], Value[Object.keys(Values[Dtlbtn.TableNameDtl])[i]])
}
}
, btn: ['保存', '取消']
, yes: function (index, layero) {
//保存前方法
if (selfbtn['SaveBefore_' + Dtlbtn.TableNameDtl] !== undefined) {
var rtn = selfbtn['SaveBefore_' + Dtlbtn.TableNameDtl].call(null, "Add");
if (rtn != null) {
if ($(rtn[0]).context.tagName == "SELECT") {
$($(rtn[0]).next()[0].children[0].firstChild).attr("placeholder", "此项为必填项");
}
layer.alert("必填项不能为空", { icon: 5, shadeClose: true, title: "错误信息" });
$(rtn).focus();
return null;
}
}
//新增
$.ajax({
url: "/" + Dtlbtn.AreaNameDtl + "/" + Dtlbtn.TableNameDtl + "/Ins",
type: "post",
data: { Table_Entity: Dtlbtn.vmDtl.$data },
dataType: "json",
success: function (result) {
if (result.Code == 200 && result.Status) {
layer.msg('新增成功', { icon: 6, shade: 0.4, time: 1000 });
mainListDtl.mainListDtl(Dtlbtn);//重载TABLE
//新增成功回调方法
if (selfbtn['SaveSuccess_' + Dtlbtn.TableNameDtl] !== undefined) {
selfbtn['SaveSuccess_' + Dtlbtn.TableNameDtl].call(null, "Add");
}
}
else {
layer.alert(result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
layer.close(index);
}
, btn2: function (index, layero) {
Dtlbtn.vmDtl.$set('$data', {});
layer.close(index);
}
, end: function (index, layero) {
ClearSelect(Dtlbtn.TableNameDtl, $, form);
Dtlbtn.vmDtl.$set('$data', {});
}
});
break;
case 'btnRefreshDtl_' + Dtlbtn.TableNameDtl: //刷新数据
mainListDtl.mainListDtl(Dtlbtn);
layer.closeAll();
break;
case 'btnEditDtl_' + Dtlbtn.TableNameDtl: //编辑单笔数据
if (count == 1) {
Dtlbtn.EditInfoDtl(checkStatus.data[0]);
//编辑前的处理方法
if (selfbtn['DomConfig_' + Dtlbtn.TableNameDtl] !== undefined) {
var rtn = selfbtn['DomConfig_' + Dtlbtn.TableNameDtl].call(null, "Edit", Dtlbtn.vmqDtl._data);
if (rtn == false) { return null; }
}
layer.open({
type: 1
, area: ['600px', '500px']
, content: $('#modifyFormDtl_' + Dtlbtn.TableNameDtl)
, success: function (layero, index) {
}
, btn: ['保存', '取消']
, yes: function (index, layero) {
//保存前方法
if (selfbtn['SaveBefore_' + Dtlbtn.TableNameDtl] !== undefined) {
var rtn = selfbtn['SaveBefore_' + Dtlbtn.TableNameDtl].call(null, "Edit");
if (rtn != null) {
if ($(rtn[0]).context.tagName == "SELECT") {
$($(rtn[0]).next()[0].children[0].firstChild).attr("placeholder", "此项为必填项");
}
layer.alert("必填项不能为空", { icon: 5, shadeClose: true, title: "错误信息" });
$(rtn).focus();
return null;
}
}
//编辑
$.ajax({
url: "/" + Dtl.AreaNameDtl + "/" + Dtlbtn.TableNameDtl + "/Upd",
type: "POST",
data: { Table_Entity: Dtlbtn.vmDtl.$data },
dataType: "json",
success: function (result) {
if (result.Code == 200 && result.Status) {
layer.msg("修改成功!", { icon: 6, shade: 0.4, time: 1000 });
mainListDtl.mainListDtl(Dtlbtn);
//保存成功方法
if (selfbtn['SaveSuccess_' + Dtlbtn.TableNameDtl] !== undefined) {
selfbtn['SaveSuccess_' + Dtlbtn.TableNameDtl].call(null, "Edit");
}
} else {
layer.alert(result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
}
}
});
layer.close(index);
}
, btn2: function (index, layero) {
Dtlbtn.vmDtl.$set('$data', {});
layer.close(index);
}
, end: function (index, layero) {
ClearSelect(Dtlbtn.TableNameDtl, $, form);
Dtlbtn.vmDtl.$set('$data', {});
}
});
}
else
layer.alert("请选择一条数据", { icon: 5, shadeClose: true, title: "错误信息" });
break;
case 'btnDeleteDtl_' + Dtlbtn.TableNameDtl: //批量删除数据
if (count > 0) {
//删除前方法
if (selfbtn['DomConfig_' + Dtlbtn.TableNameDtl] !== undefined) {
var rtn = selfbtn['DomConfig_' + Dtlbtn.TableNameDtl].call(null, "Delete", Dtlbtn.vmqDtl._data);
if (rtn == false) { return null; }
}
layer.confirm('确定要删除所选信息', { icon: 3 }, function (index) {
var data = checkStatus.data; //获取选中行的数据
$.ajax({
url: "/" + Dtlbtn.AreaNameDtl + "/" + Dtlbtn.TableNameDtl + "/DelByIds",
type: "post",
data: { ids: data.map(function (e) { return e.Id; }) },
dataType: "json",
success: function (result) {
if (result.Code == 200 && result.Status) {
layer.msg('删除成功', { icon: 6, shade: 0.4, time: 1000 });
layer.close(index);
mainListDtl.mainListDtl(Dtlbtn);//重载TABLE
//保存成功方法
if (selfbtn['SaveSuccess_' + Dtlbtn.TableNameDtl] !== undefined) {
selfbtn['SaveSuccess_' + Dtlbtn.TableNameDtl].call(null, "Delete");
}
}
else {
layer.alert(result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
}
});
});
}
else
layer.alert("请至少选择一条数据", { icon: 5, shadeClose: true, title: "错误信息" });
break;
}
for (var key in selfbtn) {
if (obj.event == key)
selfbtn[key]();
}
}
});
});
//单元格对checkbox失效
$(obj.tr[1]).click();
layer.closeAll();
//字体颜色转换
if (Dtl.TableNameDtl == 'CyclecountDetail') {
obj.tr.siblings().find('.' + Dtl.TableNameDtl + 'Class').css('color', 'white');
obj.tr.find('.' + Dtl.TableNameDtl + 'Class').css('color', 'sandybrown');
}
else {
obj.tr.siblings().find('.' + Dtl.TableNameDtl + 'Class').css('color', 'cornflowerblue');
obj.tr.find('.' + Dtl.TableNameDtl + 'Class').css('color', 'sandybrown');
}
//显示折叠
$('.layui-collapse').show();
$('#DisplayDtl' + Dtl.TableNameDtl).show();
for (i = 0; i < Object.keys(DtlShowbool).length; i++) {
if (DtlShowbool[Object.keys(DtlShowbool)[i]] == true && Object.keys(DtlShowbool)[i] != DtlShowbool[Dtl.TableNameDtl]) {
//关闭其他折叠
$('#title_' + Object.keys(DtlShowbool)[i]).click();
DtlShowbool[Object.keys(DtlShowbool)[i]] = false;
}
}
if (DtlShowbool[Dtl.TableNameDtl] == false) {
//打开当前数据对应折叠
$('#title_' + Dtl.TableNameDtl).click();
}
mainListDtl.mainListDtl(Dtl);
}
});
}
};
exports('Universal', obj);
});
function GetLabel(type, key, value, keyvalue) {
var rtn;
var DataList = SelectorSource[type];
if (DataList == undefined) {
return keyvalue;
}
for (var i = 0; i < DataList.length; i++) {
if (keyvalue == true || keyvalue == false) {
keyvalue = keyvalue + "";
}
if (DataList[i][key] == keyvalue) {
if (DataList[i].CssClass == '' || DataList[i].CssClass == 'null' || DataList[i].CssClass == null) {
rtn = '<label class="' + DataList[i].CssClass + '" style="color:black;font-size:12px;">' + DataList[i][value] + '</label>';
} else {
rtn = '<label class="' + DataList[i].CssClass + '" style="color:white;font-size:12px;">' + DataList[i][value] + '</label>';
}
break;
}
}
if (rtn == undefined) {
if (keyvalue == null) {
return '';
}
return keyvalue;
}
else {
return rtn;
}
}
//清除下拉框数据
function ClearSelect(TableName, $, form) {
$('.ClearSelector_' + TableName).each(function () {
var selDom = ($(this));
selDom.val("");
});
form.render("select");
}