Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
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
/**
 * 功能模块菜单
 * @author weidy@2018-06-04
 * @constructor
 */
layui.define(['layer','element','form','table','tree'],function(exports){
    var Class = function(){
        this.MODELNAME = "platform/securityManage/SmFunction";
        this.moduleKey = "SmFunction";
        this.id='SmFunction';
        this.sourceData={};
        this.backPath = configData.compatibility?path:configData.frameworkPath;
        this.buttonIconMap = {};
        this.url={
            tree:'smFunctionController/treeAllMenu',
            getObject: 'smFunctionController/getObjectByOid',
            add:'smFunctionController/addSave',
            edit:'smFunctionController/editSave',
            deleteUrl:'smFunctionController/delete',
            referTree:'smFunctionController/refTreeMenu',
            listButton:'smFunctionController/listButton',
            referButton:'smFunctionController/referButton',
            addButton:'smFunctionController/addButton',
            editButton:'smFunctionController/editButton',
            deleteButton:'smFunctionController/deleteButton',
            batchAddButton:'smFunctionController/batchAddButton'
        };
        this.columns = [];
        this.getContent=function(){//返回这个组件的基础html
            var that = this;
            var html = "";
            html = [
                    that.getToolbarHtml(),
                    '<div class="layui-layout" style="display:block;overflow-y: hidden">',
                        '<div class="layui-vci-tree" style="width:250px;float: left;background-color:#ffffff;overflow-y: auto;">',
                            '<label class="layui-icon layui-icon-tree" style="line-height: 20px;color:red;font-size:20px;">功能模块菜单</label>',
                            '<ul layui-filter="tree_',that.id,'"><ul>',
                        '</div>',
                        '<div class="layui-layout-border" style="display:block;margin-top:0px;margin-left:255px;">',
                            '<div class="layui-center" style="overflow-y:auto;">',
                                '<form class="layui-form" lay-filter="form_',that.id,'"></form>',
                            '</div>',
                            '<div class="layui-south" >',
                                '<div layui-filter="toolbar_button_',that.id,'" class="layui-btn-container">',
                                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_button_',that.id,'_selectButton"><i class="layui-icon layui-icon-add-1"></i>从按钮库中选择后添加</button>',
                                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_button_',that.id,'_addButton"><i class="layui-icon layui-icon-add-1"></i>添加按钮</button>',
                                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_button_',that.id,'_editButton"><i class="layui-icon layui-icon-edit"></i>修改按钮</button>',
                                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_button_',that.id,'_deleteButton"><i class="layui-icon layui-icon-delete"></i>移除按钮</button>',
                                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_button_',that.id,'_upButton"><i class="layui-icon layui-icon-up"></i>上移</button>',
                                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_button_',that.id,'_downButton"><i class="layui-icon layui-icon-down"></i>下移</button>',
                                '</div>',
                                '<table id="table_',that.id ,'" lay-filter="', that.id ,'"></table>',
                            '</div>',
                        '</div>',
                    '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml = function(){
            var that =this;
            return ['<div layui-filter="toolbar_',that.id, '" class="layui-btn-container">',//主列表的按钮
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_add"><i class="layui-icon layui-icon-add-1"></i>增加</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_edit"><i class="layui-icon layui-icon-edit"></i>修改</button>',
                 '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_del"><i class="layui-icon layui-icon-delete"></i>删除</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_copy"><i class="layui-icon layui-icon-cart"></i>克隆</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_export"><i class="layui-icon layui-icon-share"></i>导出成json</button>',
                '</div>'].join("");
        };
        this.init=function(){
            //基础的html被添加后,再执行初始化
            var that = this;
            $webUtil.copyConfig(that,that.moduleKey);
            $webUtil.bindDefultButtonLisenter(that, that.id);
            if(that.sourceData && 'true' == that.sourceData['admin']){
                that.admin = true;
                $("div[layui-filter='toolbar_button_" + that.id + "']").parent().hide();
                that.backPath = configData.compatibility?path:configData.adminServicePath;
            }else{
                that.admin = false;
            }
            var tree = layui.tree;
            var scrollHeight =  window.innerHeight;
            var treeUL = $('[layui-filter="tree_' + that.id + '"]');
            var treeHeight = scrollHeight - 200;
            treeUL.parent().height(treeHeight);
            tree.init("tree_" + that.id, treeUL, {
                url: that.url.tree,
                backPath: that.backPath,
                extraParams: {
                    isMuti: false,
                    isQueryAllColumn: true
                },
                showSearch:true,
                click: function (item, elem, options) {
                    that.setFormValues(item.attributes);
                },
                done: function (thisFilter) {
                    that.initForm();
                }
            });
        };
        this.initForm = function(){
            var that = this;
            var form = layui.form;
            form.addItems("form_" + that.id, that.getFormItems(true), function () {
                if(!that.admin) {
                    that.initButtonTable();
                }
            }, {}, {
                defaultColumnOneRow: 2
            });
        };
        this.initButtonTable = function(){
            var that = this;
            var table = layui.table;
            that.checkColumns();//主列表中列。
            table.render({
                elem: '#table_' + that.id,
                id: 'table_' + that.id,
                url: that.backPath + that.url.listButton,
                page: {
                    limit: 20,
                    page: 1
                },
                where:{
                    functionOid:'11'
                },
                selectMode:table.selectMode.muti,
                cols: [that.columns],
                done:function(res, cur, count){
                    that.buttonTotal = count;
                }
            });
            $webUtil.bindDefultButtonLisenter(that, "button_" + that.id);
        };
        this.checkColumns = function(){
            var that = this;
            var table = layui.table;
            if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
                that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
                    field:'id',
                    title:'按钮标识',
                    width:150
                },{
                    field:'name',
                    title:'按钮名称',
                    width:200
                },{
                    field:'iconCss',
                    title:'显示图标',
                    width:150
                },{
                    field:'displayFlag',
                    title:'是否显示',
                    width:80,
                    templet:function(r){
                        return $webUtil.formateBoolean(r.displayFlag);
                    }
                },{
                    field:'controlRightFlag',
                    title:'是否控制权限',
                    width:120,
                    templet:function(r){
                        return $webUtil.formateBoolean(r.displayFlag);
                    }
                },{
                    field:'uiFlag',
                    title:'显示界面标识',
                    width:150
                },{
                    field:'usedBySpecifyRole',
                    title:'指定访问角色',
                    width:150
                }];
            }
        };
        this.add=function(){
            var that = this;
            that.doAdd(false);
        };
        this.copy=function () {
            var that = this;
            that.doAdd(true);
        };
        this.doAdd = function(isCopy){
            var that = this;
            var filter ="addForm_" + that.id;
            var form = layui.form;
            var addSaveIndex = layer.open({
                type:1,
                title:'添加功能模块菜单',
                btn:['保存','取消','保存新增'],
                skin:'layui-layer-lan',
                content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                area:['800px','510px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:true,
                resizing:function(layero){
                    form.doResize(filter);
                },
                success:function(layero){
                    form.addItems(filter,that.getFormItems(), function(){
                        if(isCopy && that.selectTreeAttribute){
                            var copyAttribute = {};
                            for(var key in that.selectTreeAttribute){
                                if(key.toLocaleLowerCase() != 'oid'){
                                    copyAttribute[key] = that.selectTreeAttribute[key];
                                }
                            }
                            form.setValues(copyAttribute, filter);
                        }else {
                            if (that.selectTreeAttribute) {
                                form.setValues({
                                    id: that.selectTreeAttribute['id'],
                                    parentFunctionId: that.selectTreeAttribute['oid'],
                                    parentFunctionIdName: that.selectTreeAttribute['name'],
                                    displayFlag: that.selectTreeAttribute['displayFlag'],
                                    controlRightFlag: that.selectTreeAttribute['controlRightFlag']
                                }, filter);
                            } else {
                                form.setValues({
                                    displayFlag: true,
                                    controlRightFlag: true
                                }, filter);
                            }
                        }
                    },{},{defaultColumnOneRow:2,inDialog:true});
                },
                yes:function(layero){
                    if(form.validata(filter)){
                        var values = form.getValues(filter);
                        $webUtil.post(that.url.add,values,function(result){
                            if(result.success){
                                $webUtil.showMsg("添加菜单成功");
                                layer.close(addSaveIndex);
                                that.refresh();
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("添加菜单的时候出现了错误");
                        },that.backPath);
                    }
                },
                btn3:function(layero){
                    if(form.validata(filter)){
                        var values = form.getValues(filter);
                        $webUtil.post(that.url.add,values,function(result){
                            if(result.success){
                                $webUtil.showMsgFromResult(result,"添加菜单成功");
                                layer.close(addSaveIndex);
                                that.refresh();
                                that.add();
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("添加菜单的时候出现了错误");
                        },that.backPath);
                    }
                },
                btn2:function(layero){
                    layer.close(addSaveIndex);
                    that.refresh();
                }
            });
        };
        this.edit = function(){
            var that = this;
            if($webUtil.isNotNull(that.selectTreeOid )){
                var filter ="editForm_" + that.id;
                var form = layui.form;
                var addSaveIndex = layer.open({
                    type:1,
                    title:'修改功能模块菜单',
                    btn:['保存','取消'],
                    skin:'layui-layer-lan',
                    content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                    area:['800px','510px'],
                    closeBtn:2,
                    shade:true,
                    shadeClose:true,
                    resize:true,
                    resizing:function(layero){
                        form.doResize(filter);
                    },
                    success:function(layero){
                        form.addItems(filter,that.getFormItems(), function(){
                            form.setValues( that.selectTreeAttribute,filter);
                        },{},{defaultColumnOneRow:2,inDialog:true});
                    },
                    yes:function(layero){
                        if(form.validata(filter)){
                            var values = form.getValues(filter);
                            var submitValues = {};
                            for(var key in that.selectTreeAttribute){
                                submitValues[key] = that.selectTreeAttribute[key];
                            }
                            for(var key in values){
                                submitValues[key] = values[key];
                            }
                            if(!( "displayFlag" in values)){
                                submitValues['displayFlag'] = false;
                            }
                            if(!( "controlRightFlag" in values)){
                                submitValues['controlRightFlag'] = false;
                            }
                            $webUtil.put(that.url.edit,submitValues,function(result){
                                if(result.success){
                                    $webUtil.showMsg("修改功能模块菜单成功");
                                    layer.close(addSaveIndex);
                                    that.refresh();
                                }else{
                                    $webUtil.showErrorMsg(result.msg);
                                }
                            },function (xhr,error) {
                                $webUtil.showErrorMsg("修改菜单的时候出现了错误");
                            },that.backPath);
                        }
                    },
                    btn2:function(layero){
                        layer.close(addSaveIndex);
                        that.refresh();
                    }
                });
            }else{
                $webUtil.showErrorMsg("没有选择菜单");
            }
        };
        this.del = function(){
            var that = this;
            if($webUtil.isNotNull(that.selectTreeOid )){
                $webUtil.showConfirmMsg("您是否要删除这个菜单?它的下级菜单将会被一同删除。",function(r){
                    if(r){
                        $webUtil.deleteRequest(that.url.deleteUrl,{oid:that.selectTreeOid},function(result){
                            if(result.success){
                                $webUtil.showMsg("删除菜单成功");
                                that.refresh();
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function(xhr,error) {
                            $webUtil.showErrorMsg("删除菜单时请求服务器出现了错误");
                        },that.backPath);
                    }
                });
            }else{
                $webUtil.showErrorMsg("没有选择菜单");
            }
        };
        this.export = function(){
            var that = this;
            var  form = layui.form;
            $webUtil.get(that.url.tree,{},function (result) {
                var filter = "export_form_" + that.id;
                var addSaveIndex = layer.open({
                    type:1,
                    title:'请在下方的文本框中拷贝所有的json内容',
                    skin:'layui-layer-lan',
                    content:'<form id=' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                    area:['1200px','500px'],
                    closeBtn:2,
                    shade:true,
                    shadeClose:true,
                    resize:true,
                    resizing:function(layero){
                        form.doResize(filter);
                    },
                    success:function(layero){
 
                        form.addItems(filter,[{
                            field: 'result',
                            text: 'json内容',
                            type:'textarea',
                            inputWidth:1000,
                            height:400
                        }], function(){
                            form.setValues({result:JSON.stringify(result)},filter);
                        },{},{defaultColumnOneRow:2,inDialog:true});
                    }
                });
            },function(xhr,err){},that.backPath);
 
        };
        this.setFormValues = function(attributes){
            var that = this;
            if(attributes){
                that.selectTreeOid =attributes['oid'];
                that.selectTreeAttribute = attributes;
                try{
                    var form = layui.form;
                    form.clear("form_" + that.id,true);
                    form.setValues(attributes,"form_" + that.id);//不需要转换对象,因为attributes已经是对象格式了
                }catch (e){
                    $webUtil.showDebugMsg(e);
                }
                layui.table.reload("table_" + that.id,{
                    where:{
                        functionOid: that.selectTreeOid
                    }
                });
            }
        };
        this.refresh = function(parentNodeOid){
            var that = this;
            var tree = layui.tree;
            if(parentNodeOid){
                tree.reloadNode("tree_" + that.id,parentNodeOid);
            }else {
                that.selectTreeOid = null;
                that.selectTreeAttribute = null;
                tree.reload("tree_" + that.id);
            }
            layui.table.reload("table_" + that.id);
        };
        this.getFormItems = function(onlyShow){
            var that = this;
            var resourceField = {};
            if(that.admin){
                resourceField = {
                    field:'resourceControlType',
                    text:'资源控制类型',
                    type:'combox',
                    required:true,
                    data:[{key:"resourceControlType_bs",value:"B/S"}],
                    defaultValue:'resourceControlType_bs',
                    readOnly: onlyShow
                }
            }else{
                resourceField = {
                    field:'resourceControlType',
                    text:'资源控制类型',
                    type:'combox',
                    required:true,
                    comboxKey:'resourceControlType',
                    hidden:that.admin,
                    readOnly: onlyShow
                }
            }
            return [{
                field: 'id',
                text: '菜单编号',
                required:true,
                readOnly: onlyShow
            }, {
                field: 'name',
                text: '菜单名称',
                required:true,
                readOnly: onlyShow
            },resourceField, {
                field: 'orderNum',
                readOnly: onlyShow,
                text: '排序号',
                required:true,
                type:'text',
                verify:'number'
            },{
                field:'url',
                text:'链接地址',
                readOnly: onlyShow,
                textWidth:530,
                defaultValue:'USEJS:',
                useAllWidth:true
            }, {
                field: 'displayFlag',
                readOnly: onlyShow,
                text: '是否显示',
                defaultValue:true,
                type:'boolean'
            }, {
                field: 'controlRightFlag',
                readOnly: onlyShow,
                text: '是否控制权限',
                required:true,
                defaultValue:true,
                type:'boolean'
            }, {
                field: 'parentFunctionId',
                readOnly: onlyShow,
                text: '上级菜单',
                type:'refer',
                showField:'parentFunctionIdName',
                referConfig:{
                    type:'tree',
                    url:that.url.referTree,
                    backPath:that.backPath,
                    textField:'name',
                    valueField:'oid',
                    isMuti:false
                }
            },{
                field:'iconCss',
                text:'显示图标',
                readOnly: onlyShow
            }, {
                field: 'logName',
                readOnly: onlyShow,
                text: '日志名称',
                readOnly: onlyShow
            }, {
                field: 'helpName',
                readOnly: onlyShow,
                text: '帮助文档名称'
            },{
                field:'usedBySpecifyRole',
                text:'指定访问的角色',
                readOnly: onlyShow,
                textWidth:530,
                useAllWidth:true
            },{
                field:'description',
                text:'备注',
                readOnly: onlyShow,
                textWidth:530,
                useAllWidth:true
            }];
        };
        this.addButton = function(){
            var that = this;
            if($webUtil.isNull(that.selectTreeOid)){
                $webUtil.showErrorMsg("请您先选择菜单");
                return false;
            }
            var filter ="addButtonForm_" + that.id;
            var form = layui.form;
            var addSaveIndex = layer.open({
                type:1,
                title:'添加按钮',
                btn:['保存','取消','保存并新增'],
                skin:'layui-layer-lan',
                content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                area:['800px','510px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:true,
                resizing:function(layero){
                    form.doResize(filter);
                },
                success:function(layero){
                    form.addItems(filter,that.getButtonFormItems(), function(){
                        form.setValues({
                            displayFlag: 'true',
                            controlRightFlag: 'true'
                        }, filter);
                    },{},{defaultColumnOneRow:2,inDialog:true});
                },
                yes:function(layero){
                    if(form.validata(filter)){
                        var values = form.getValues(filter);
                        values['functionOid'] = that.selectTreeOid;
                        $webUtil.post(that.url.addButton,values,function(result){
                            if(result.success){
                                $webUtil.showMsg("添加按钮成功");
                                layer.close(addSaveIndex);
                                that.refreshButton();
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("添加按钮的时候出现了错误");
                        },that.backPath);
                    }
                },
                btn2:function(layero){
                    layer.close(addSaveIndex);
                    that.refreshButton();
                },
                btn3:function(layero){
                    if(form.validata(filter)){
                        var values = form.getValues(filter);
                        values['functionOid'] = that.selectTreeOid;
                        $webUtil.post(that.url.addButton,values,function(result){
                            if(result.success){
                                $webUtil.showMsg("添加按钮成功");
                                form.clear();
                                form.setValues({
                                    displayFlag: 'true',
                                    controlRightFlag: 'true'
                                }, filter);
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("添加按钮的时候出现了错误");
                        },that.backPath);
                    }
                }
            });
        };
        this.editButton = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            var selectRowData = layui.table.checkStatus("table_" + that.id);
            if($webUtil.isNull(that.selectTreeOid)){
                $webUtil.showErrorMsg("请您先选择菜单");
                return false;
            }
            var filter ="addButtonForm_" + that.id;
            var form = layui.form;
            var addSaveIndex = layer.open({
                type:1,
                title:'修改按钮',
                btn:['保存','取消'],
                skin:'layui-layer-lan',
                content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                area:['800px','510px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:true,
                resizing:function(layero){
                    form.doResize(filter);
                },
                success:function(layero){
                    form.addItems(filter,that.getButtonFormItems(), function(){
                        form.setValues(selectRowData.data[0],filter);
                    },{},{defaultColumnOneRow:2,inDialog:true});
                },
                yes:function(layero){
                    if(form.validata(filter)){
                        var values = selectRowData.data[0];
                        var formValues = form.getValues(filter);
                        for(var key in formValues){
                            values[key] = formValues[key];
                        }
                        values['t_oid'] = selectRowData.data[0]['toid'];
                        values['functionOid'] = that.selectTreeOid;
                        $webUtil.put(that.url.editButton,values,function(result){
                            if(result.success){
                                $webUtil.showMsg("修改按钮成功");
                                layer.close(addSaveIndex);
                                that.refreshButton();
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("修改按钮的时候出现了错误");
                        },that.backPath);
                    }
                },
                btn2:function(layero){
                    layer.close(addSaveIndex);
                    that.refreshButton();
                }
            });
        };
        this.deleteButton = function () {
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,false);
            if(!oid){
                return false;
            }
            var selectRowData = layui.table.checkStatus("table_" + that.id);
            if($webUtil.isNull(that.selectTreeOid)){
                $webUtil.showErrorMsg("请您先选择菜单");
                return false;
            }
            $webUtil.showConfirmMsg("您是否确定删除这些按钮",function (r) {
                if(r){
                    var submitValues = {
                        functionOid:that.selectTreeOid
                    };
                    layui.each(selectRowData.data,function(_index,_item){
                        submitValues['buttonDTOList[' + _index + '].t_oid'] = _item['toid'];
                    });
                    $webUtil.deleteRequest(that.url.deleteButton,submitValues,function (result) {
                        if(result.success){
                            $webUtil.showMsg("删除按钮成功");
                            that.refreshButton();
                        }else{
                            $webUtil.showErrorMsg(result.msg);
                        }
                    },function (xhr,err) {
                        $webUtil.showErrorMsg("删除按钮的时候出现了错误");
                    },that.backPath);
                }
            });
        };
        this.selectButton = function(){
            var that = this;
            if($webUtil.isNull(that.selectTreeOid)){
                $webUtil.showErrorMsg("请您先选择菜单");
                return false;
            }
            var filter ="selectButton_" + that.id;
            var addSaveIndex = layer.open({
                type:1,
                title:'从按钮库中选择',
                btn:['确定并继续','确定并关闭','取消'],
                skin:'layui-layer-lan',
                content:'<div layui-filter="search_form_for_table_' + filter + '" class="layui-form" >' +
                            '<div class="layui-form-item" style="height:24px;float:left;display:inline-block"> ' +
                                '<div class="layui-input-inline" style="height:24px;line-height:24px;width:150px">' +
                                    '<select name="search_for_table_'+ filter + '" style="height:24px;width:120px;padding-right: 30px;">' +
                                        '<option value="id" >按钮标识</option>' +
                                        '<option value="name" >按钮名称</option>' +
                                    '</select>' +
                                '</div>' +
                                '<div class="layui-input-inline">' +
                                    '<input type="text" style="height:24px" name="searchvalue_for_table_'+ filter + '" placeholder="输入值后进行模糊查询" class="layui-input" >' +
                                '</div>'+
                            '</div>' +
                         '</div>' +
                         '<table id="table_' + filter + '" lay-filter="' + filter + '" style="margin-top:40px" ></table>',
                area:['800px','510px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:true,
                resizing:function(layero){
                    form.doResize(filter);
                },
                success:function(layero){
                    layui.form.render('select');
                    layui.table.render({
                        elem: '#table_' + filter,
                        id:filter,
                        url:that.backPath + that.url.referButton,
                        page:{
                            limit:20,
                            page:1
                        },
                        where:{
                            functionOid:that.selectTreeOid
                        },
                        cols: [that.getReferButtonColums()]
                    });
                    $('[name="searchvalue_for_table_' + filter + '"]').keydown(function(e){
                        if(e.which == 13){
                            //按下回车键
                            var searchField = $(this).parent().parent().find('select').val();
                            var searchValue = $(this).val();
                            if($webUtil.isNotNull(searchValue)){
                                searchValue = "*" + searchValue + "*";
                            }
                            var requestData = {};
                            requestData['conditionMap["' + searchField + '"]'] = searchValue;
                            layui.table.reload(
                                filter, {
                                    where: requestData
                                }
                            );
                        }
                    });
                },
                yes:function(layero){
                    var selectData = layui.table.checkStatus(filter);
                    if(!selectData || !selectData.data || selectData.data.length == 0){
                        $webUtil.showErrorMsg("没有选择按钮,无法继续");
                        return false;
                    }
                    selectData = selectData.data;
                    var submitValue = {
                        functionOid: that.selectTreeOid
                    };
                    layui.each(selectData,function(_index,_item){
                        submitValue['buttonDTOList[' + _index + '].oid'] = _item.oid;
                        submitValue['buttonDTOList[' + _index + '].id'] = _item.id;
                        submitValue['buttonDTOList[' + _index + '].name'] = _item.name;
                        submitValue['buttonDTOList[' + _index + '].iconCss'] = _item.iconCss;
                        submitValue['buttonDTOList[' + _index + '].displayFlag'] = true;
                        submitValue['buttonDTOList[' + _index + '].controlRightFlag'] = true;
                        submitValue['buttonDTOList[' + _index + '].orderNum'] =  that.buttonTotal? (that.buttonTotal+1 + _index) : (_index + 1);
                        submitValue['buttonDTOList[' + _index + '].uiFlag'] = 'main';
                    });
                    $webUtil.post(that.url.batchAddButton,submitValue,function(result){
                        if(result.success){
                            $webUtil.showAutoMsg("批量添加按钮成功");
                            layui.table.reload(filter);
                            that.refreshButton();
                        }else{
                            $webUtil.showErrorMsg(result.msg);
                        }
                    },function(xhr,error){
                        $webUtil.showErrorMsg("批量添加按钮时出现了错误");
                    },that.backPath);
                },
                btn2:function(layero){
                    var selectData = layui.table.checkStatus(filter);
                    if(!selectData || !selectData.data || selectData.data.length == 0){
                        $webUtil.showErrorMsg("没有选择按钮,无法继续");
                        return false;
                    }
                    selectData = selectData.data;
                    var submitValue = {
                        functionOid: that.selectTreeOid
                    };
                    layui.each(selectData,function(_index,_item){
                        submitValue['buttonDTOList[' + _index + '].oid'] = _item.oid;
                        submitValue['buttonDTOList[' + _index + '].id'] = _item.id;
                        submitValue['buttonDTOList[' + _index + '].name'] = _item.name;
                        submitValue['buttonDTOList[' + _index + '].iconCss'] = _item.iconCss;
                        submitValue['buttonDTOList[' + _index + '].displayFlag'] = true;
                        submitValue['buttonDTOList[' + _index + '].controlRightFlag'] = true;
                        submitValue['buttonDTOList[' + _index + '].orderNum'] =  that.buttonTotal? (that.buttonTotal+1 + _index) : (_index + 1);
                        submitValue['buttonDTOList[' + _index + '].uiFlag'] = 'main';
                    });
                    $webUtil.post(that.url.batchAddButton,submitValue,function(result){
                        if(result.success){
                            $webUtil.showMsg("批量添加按钮成功");
                            layer.close(addSaveIndex);
                            that.refreshButton();
                        }else{
                            $webUtil.showErrorMsg(result.msg);
                        }
                    },function(xhr,error){
                        $webUtil.showErrorMsg("批量添加按钮时出现了错误");
                    },that.backPath);
                },
                btn3:function(layero){
                    layer.close(addSaveIndex);
                    that.refreshButton();
                }
            });
        };
        this.getReferButtonColums = function () {
            var table = layui.table;
            return [table.getIndexColumn(),table.getCheckColumn(),{
                    field:'id',
                    title:'按钮标识',
                    width:150
                },{
                    field:'name',
                    title:'按钮名称',
                    width:200
                },{
                    field:'iconCss',
                    title:'显示图标',
                    width:150
                }];
        };
        this.getButtonFormItems = function () {
            var that = this;
            return [{
                field: 'id',
                text: '按钮标识',
                required:true
            }, {
                field: 'name',
                text: '按钮名称',
                required:true
            },{
                field:'uiFlag',
                text:'显示位置所属页面标识',
                defaultValue:'main'
            }, {
                field: 'orderNum',
                text: '排序号',
                required:true,
                verify:'number'
            }, {
                field: 'displayFlag',
                text: '是否显示',
                required:true,
                type:'boolean'
            }, {
                field: 'controlRightFlag',
                text: '是否控制权限',
                required:true,
                type:'boolean'
            },{
                field:'iconCss',
                text:'显示图标'
            },{
                field:'usedBySpecifyRole',
                text:'指定访问的角色',
                textWidth:530,
                useAllWidth:true
            }];
        };
        this.refreshButton = function(){
            var that = this;
            layui.table.reload("table_" + that.id);
        };
    };
    var c = new Class();
    exports(c.MODELNAME,c);
});