roleManage.js 30.9 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
/**
 * Created by mac on 17/5/10.
 */
(function () {
    
    var fun = {
        //查询用户角色-查询按钮
        queryRoles:function(){
            fun.initTable();
        },
        //角色关闭
        roler_close_alert_org:function () {
            // $('#example-getting-started').multiselect('select', '');
            $('#departmentrolerAlert,#alertroler_over').hide();
        },
        //初始化表格数据
        initTable:function(){
            $('#roletable').bootstrapTable('destroy').bootstrapTable({
                striped:true,//表格显示条纹 
                pagination: true, //启动分页  
                pageNumber:1, //当前第几页  
                pageSize: 10,  //每页显示的记录数  
                pageList: [10,15,20],  //记录数可选列表  
                sidePagination: 'server',//表示服务端分页
                queryParamsType: 'limit',
                method:'POST',//请求方法
                paginationPreText: '<',
                paginationNextText: '>',
                ajax:tableLoadRequest,//自定义ajax加载数据
                uniqueId:'id',
                columns: [
                    {field: 'state', title: '',width: '5%',  align: 'left',formatter:fun.checkedFormat},
                    {field: 'id', title: '<span class="id-icon"></span>角色ID',width: '5%',  align: 'left',formatter:commonObj.replacenull},
                    {field: 'roleName', title: '<span class="person-icon"></span>角色名称', width: '15%', align: 'left',formatter:commonObj.replacenull},
                    {field: 'createEmpname', title: '<span class="person-icon"></span>创建人', width: '15%', align: 'left',formatter:commonObj.replacenull},
                    {field: 'createDate', title: '<span class="time-icon"></span>创建时间', width: '15%', align: 'left',formatter:commonObj.timeFormatter},
                    {field: 'roleDesc', title: '<span class="remarks-icon"></span>角色描述', width: '15%', align: 'left',formatter:commonObj.replacenull},
                    {field: 'orgId', width: '15%', align: 'left',visible:false},
                    {field: 'oper', title: '<span class="opration-icon"></span>操作', width: '15%', align: 'left',formatter:fun.operFormatter}
                ],
                onClickRow: function (row,$element) {
                    var id=row.id;
                    _orgId = row.orgId;
                    $('#roletable input:radio[data-value="'+id+'"]').attr("checked","checked");
                },
                formatTableUnit:function(value,row,index){
                    return {
                        css: {
                            "white-space":"nowrap"
                        }
                    }
                },
                formatLoadingMessage:function(){
                       return "数据正在加载中...";
                },
                formatNoMatches: function () { 
                       return '<span>暂无信息,可使用 <a class="addrole">“添加角色”</a> 按钮为系统添加角色信息</span>';
                }
            });
        },
        //转换系统名称
        getSysCodeName:function(value,row,index){
            var sysCodeName =sessionStorage.getItem("sysName");
            return sysCodeName;
        },
        checkedFormat:function(value,row,index) {
            var checkStr="<input type='radio' name='checkTr' class='radio radio-danger' data-value='"+row.id+"'/>";
            return checkStr;
        },
        //操作显示
        operFormatter:function(value,row,index){
            var operStr ='<span  style="margin-right: 3px;" class="ITD-oper-green" jobreadMsg data-value="'+row.id+'">职能详情</span>'+
                '<span  style="margin-right: 3px;" class="ITD-status-blue" modifyRole data-value="'+row.id+'">修改</span>'+
            '<span class="ITD-status-abnormal" deleteRole rolename="'+row.roleName+'" data-value="'+row.id+'">删除</span>';
            return operStr;
        },

        
        //添加角色
        addRole:function(){
           
            $('#role_alert_error').text('');
            //$('#jobfuncIds').selectpicker('val', '');
            //$('input').val('');
             //selectAllInput.prop("checked", false);
            $('#jobfuncIds').multiselect('select', '');
            var a=$('#jobfuncIds').val();
            $('#jobfuncIds').multiselect('deselect', a);
            $('#roleDesc').val(''),
            $('#roleName').val(''),
            $('textarea').val('');
            $('select').val('');
            $('#alert_over').append($('#role_alert_con'));
            $('#role_alert_title').html('添加角色');
            $('#alert_ok').html('确定');
            $('#alert_ok').attr('oper','save');
            var sysName = sessionStorage.getItem("sysName");
            $("#sysCodeNameView").val(sysName);
                $('#alert_over,#role_alert_con').show();
        },
        //修改角色
        modifyRole:function(element){
            $('.popMask').remove();
            $('#role_alert_error').text('');
            //$('#jobfuncIds').selectpicker('val', '');
            //设置值
            var roleid = $(element).attr('data-value');
            //根据唯一值获取行数据
            var modifyRow = $('#roletable').bootstrapTable('getRowByUniqueId', roleid);
            $('#roleid').val(roleid);
            $('#roleName').val(modifyRow.roleName);
            $('#roleDesc').val(modifyRow.roleDesc);
            $('#alert_over').append($('#role_alert_con'));
            $('#role_alert_title').html('修改角色');
            $('#alert_ok').html('确定');
            var sysName = sessionStorage.getItem("sysName");
            $("#sysCodeNameView").val(sysName);
            $('#alert_ok').attr('oper','update');
            $('#alert_over,#role_alert_con').show();
        },
        jobreadMsg:function(element){
            //设置值
            var roleid = $(element).attr('data-value');
            //根据唯一值获取行数据
            //var modifyRow = $('#roletable').bootstrapTable('getRowByUniqueId', roleid);

            $("#rolejobMsgcont").empty();

            var sysCode = sessionStorage.getItem("sysCode");
            var req={sysCode:sysCode,roleId:roleid};
            sysAjax({
                method: 'GET',
                url: dataUrl.util.queryJobFuncsByRoleId(),
                data: req,
                async:false,
                success: function (res) {
                    console.log(res);
                    if(isError(res)){
                        return false;
                    }
                    var html='';
                    for(var index in res.data){
                        html+='<span class=" float-left role-pop-panel-wid50" >'+res.data[index].NAME+'</span>';
                    }

                    $("#rolejobMsgcont").html(html);
                }
            });



           /* $('#roleid').val(roleid);
            $('#roleName').val(modifyRow.roleName);
            $('#roleDesc').val(modifyRow.roleDesc);
            $('#alert_over').append($('#role_alert_con'));
            var sysName = sessionStorage.getItem("sysName");
            $("#sysCodeNameView").val(sysName);
            $('#alert_ok').attr('oper','update');*/
            $('#jobreadMsg_modal').modal('show');

        },
        //删除角色
        deleteRole:function(element){
            $('.popMask').remove();
            var roleid = $(element).attr('data-value');
            var rolename = $(element).attr('rolename');
            var content = $('<span class="common_span">确定要删除角色('+rolename+')吗?</span>');
            var isUsed = '';
            swal({
                  title: '提示',
                  text: '确定要删除?',
                  type: 'warning',
                  showCancelButton: true,
                  allowOutsideClick:false,
                  confirmButtonText: '确定',
                  cancelButtonText: '关闭',
                }).then(function(isConfirm) {
                  if (isConfirm === true) {
                      //判断该角色是否已经被占用 
                       isUsedForRoleByRoleId();
                       if(isUsed=='true'){
                              deleteRoleForce(rolename);
                        }else{//没有被占用
                                  //删除角色
                                realDeleteRole();
                                //刷新table
                                refreshTable();
                        }
                  } else if (isConfirm === false) {
                         swal.close() 
                  } 
                }); 
           
            //强制删除
           function deleteRoleForce(roleName){
               swal({
                  title: '提示',
                  text: '角色['+roleName+']已经被使用,是否强制删除?',
                  type: 'warning',
                  showCancelButton: true,
                   allowOutsideClick:false,
                  confirmButtonText: '强制删除',
                  cancelButtonText: '关闭',
                }).then(function(isConfirm) {
                  if (isConfirm === true) {
                            //删除角色
                            realDeleteRole();
                            //刷新table
                                refreshTable();
                  
                  } else if (isConfirm === false) {
                    swal.close() 
                  
                  } 
                }); 
           }
           function refreshTable(){
               var opt = {
                     url: dataUrl.util.getQueryRoles(),
                     silent: true
                };

            $("#roletable").bootstrapTable('refresh', opt);
           }
           //正式删除角色
           function realDeleteRole(){
               var sysCode = sessionStorage.getItem("sysCode");
                sysAjax({
                    method: 'POST',
                    url: dataUrl.util.deleteRole(),
                    data: "sysCode="+sysCode+"&roleIds="+roleid,
                    contentType: 'application/x-www-form-urlencoded',
                    dataType:'json',
                    async:false,
                    success: function (res) {
                        if(isError(res)){
                            return false;
                        }
                    }
                });
           }
           
           //判断该角色是否已经被占用 
           function isUsedForRoleByRoleId(){
            var sysCode = sessionStorage.getItem("sysCode");
                sysAjax({
                    method: 'post',
                    url: dataUrl.util.isUsedForRoleByRoleId(),
                    data: "sysCode="+sysCode+"&roleId="+roleid,
                    contentType: 'application/x-www-form-urlencoded',
                    dataType:'json',
                    async:false,
                    success: function (res) {
                        if(isError(res)){
                            return false;
                        }
                        isUsed = res.data+'';
                    }
                });
           }
            
        },
        //保存角色信息
        saveJobFunRole:function(){
            var sysCode = sessionStorage.getItem("sysCode");
            //1.获取角色id
            var roleId = $('#roletable input:radio:checked').attr("data-value");
            var orgId=_orgId;
            //2.获取选择的角色ids
            var jobFunIds = new Array();
            //查找右侧所有选择的职能id
            var li =$('#addroler-content').find('li');
            $.each(li, function(index,row) {
                var jobFunId=$(this).attr('data-value');
                //orgId=$(this).attr('data-orgId');
                if(jobFunId != null){
                    jobFunIds[index] = jobFunId;
                }
            });
            var req={
                "roleId": roleId,
                "sysCode":sysCode,
                "orgId":orgId,
                "jobFunIds":jobFunIds,
                "dataState":1
            };
            sysAjax({
                method: 'POST',
                url: dataUrl.util.batchSaveRoleJobFunByRoleId(),
                data: JSON.stringify(req),
                dataType:'json',
                async:false,
                success: function (res) {
                    if(res != null && res.code == "8888"){
                        var data=res.data;
                        if(data){
                            $('#departmentrolerAlert,#alertroler_over').hide();
                            $('#roletable').bootstrapTable('refresh', {silent: true});
                            swal({title:"提示",text:"保存成功",type:"success",width:350,timer:3000,allowOutsideClick:true});
                        }else{
                            swal({title:"提示",text:"保存失败,请重新添加",type:"error",width:350,timer:3000,allowOutsideClick:true});
                            return false;
                        }

                    }else{
                        swal({title:"提示",text:res.msg,type:"error",width:350,timer:3000,allowOutsideClick:true});
                        return false;
                    }

                }
            });

        },
        //职能弹窗
        departmentJobFunAlert:function () {
            //查询所有职能信息
            fun.departmentJobFunAlert();
        },
        //分配职能
        departmentJobFunAlert:function () {
            //1.判断是否选中
            var isChecked= $('#roletable input:radio:checked').attr("checked");
            var roleId="";
            if(!isChecked){
                //sweetAlert("提示", "请选择一行用户记录", "warning");
                swal({title:"提示",text:"请选择一行用户记录",type:"warning",width:350,timer:3000,allowOutsideClick:true});
                return false;
            }else{
                roleId = $('#roletable input:radio:checked').attr("data-value");
            }
            //2.获取所有职能信息
            //var sysCodeS = sessionStorage.getItem("sysCode");
            var req = {
                baseRequest: {
                    pageNum: 1,
                    pageSize:0
                },
                sysCode: sysComm.sysCode,
                jobfuncId: null,
                jobfuncName: null  
            };
            sysAjax({
                method: 'POST',
                url: dataUrl.util.getQueryJobFunc(),
                data:JSON.stringify(req),
                contentType: 'application/json; charset=utf-8',
                dataType:'json',
                async:false,
                success: function (res) {
                    console.log(res);
                    if(res.code=='8888' && res.data != null && res.data.rows != null){
                        var data=res.data.rows;
                        $('#roler-conten').empty(); //左侧
                        var roles = '';
                        $.each(data, function(index,row) {
                            roles +='<li class="roler-mes" data-value='+row.id+' data-orgId='+row.id+'>'+row.jobfuncName+'</li>';
                        });
                        $('#roler-conten').html(roles);
                        $('#alertroler_over,#departmentrolerAlert').show();
                    }

                }
            });
            //通过角色ID查询当前角色对应的职能
            var req= {
                roleId: roleId,
                sysCode:sysComm.sysCode
            };
            sysAjax({
                method: 'GET',
                url: dataUrl.util.queryJobFuncsByRoleId(),
                data: req,
                async:false,
                success: function (res) {
                    console.log(res);
                    if(isError(res)){
                       swal({title:"错误提示",text:res.msg,type:"error",width:350,timer:3000,allowOutsideClick:true});
                        return false;
                    }
                    var data = res.data;
                    $('#addroler-content').empty(); //右侧
                    var roles = '';
                    $.each(data, function(index,row) {
                        roles +='<li class="roler-mes" data-value='+row.CODE+' data-orgId='+row.CODE+'>'+row.NAME+'</li>';
                    });
                    $('#addroler-content').html(roles);
                    
                }
            });
            

        },
        //show
        show_alert:function () {
            $('#alert_over').append($('#role_alert_con'));
            $('#alert_over,#role_alert_con').show();
        },
        //clsoe
        close_alert:function () {
            $('#alert_over,#role_alert_con').hide();
        },
        //cancel
        alert_cancel:function () {
            $('#alert_over,#role_alert_con').hide();
        },
        //alert_ok
        alert_ok:function () {
                var sysCode = sessionStorage.getItem("sysCode");
            //验证参数
            fun.validateRole();
            var errmsg = $('#role_alert_error').text();
            if(errmsg !=''){
                return false;
            }
            //拼接请求参数
            var url = '';
            if($('#alert_ok').attr("oper")=='save'){
                url = dataUrl.util.saveRole();
            }else if($('#alert_ok').attr("oper")=='update'){
                url = dataUrl.util.updateRole();
            }
            
            var req= {
                "id": $('#roleid').val(),
                "roleDesc": $('#roleDesc').val(),
                "roleName": $('#roleName').val(),
                "sysCode":sysCode,
                "operId":fn.getUserId(),
                "operName":fn.getUserName()
            };
            var easyUIOps = {
                method:'POST',
                url: url,
                data: JSON.stringify(req),
                success: function(res){
                    if(isError(res)){
                        return false;
                    }
                    $('#alert_over,#role_alert_con').hide();
                    $('#roleId').val('');
                    //刷新table
                    $('#roletable').bootstrapTable('refresh', {silent: true});
                }
            };
            sysAjax(easyUIOps);     
       },
       //验证参数
       validateRole:function(){
            var roleVal = $('#roleName').val();
            var errorIfo = $('#role_alert_error');
            var roleDescription = $('#roleDesc').val();
            //角色名字
            if(StrUtil.isEmpty(roleVal)){
                errorIfo.text('请填写角色名称');
                $('#roleName').focus()
                return false;
            }else if(roleVal.indexOf(' ')>=0){
                errorIfo.text('角色名不能包含空格或者标点符号');
                $('#roleName').focus()
                return false;
            }else{
                errorIfo.text('');
            }
            //角色描述
            if(StrUtil.isEmpty(roleDescription)){
                errorIfo.text('请输入角色描述');
                $('#roleDesc').focus();
                return false;
            }else{
                errorIfo.text('');
            };
       }
    };

   //初始执行
    init();
    
    function init(){
        //close弹窗
        $('.close_alert').on('click',function () {
            fun.close_alert();
        });
        //cancel弹窗
        $('#alert_cancel').on('click',function () {
            fun.close_alert();
        });
        //alert_ok弹窗
        $('#alert_ok').on('click',function () {
            fun.alert_ok();
        });
        //分配角色
        documentBindFunc.on('click','#add_jobfun',function () {
            fun.departmentJobFunAlert();
        });
        //删除角色
        $(document).on('click','[deleteRole]',function(){
            fun.deleteRole(this);
        });
        //修改角色
        $(document).on('click','[modifyRole]',function(){
            fun.modifyRole(this);
        });
        //职能详情
        $(document).on('click','[jobreadMsg]',function(){
            fun.jobreadMsg(this);
        });
        //添加角色
        $(document).on('click','.addrole',function(){
            fun.addRole();
        });
        //查询角色
        $(document).on('click','#select_role_btn',function(){
            fun.queryRoles();
        });
        //分配角色内容
        $('#roler-conten li').live('click',function () {
            $(this).addClass('roler-mes-active').siblings('li').removeClass('roler-mes-active')
        });
        //关闭角色弹窗
        documentBindFunc.on('click','.roler_close_alert_org',function () {
            fun.roler_close_alert_org();
        });
        documentBindFunc.on('click','.departmentrolercancel_btn',function () {
            fun.roler_close_alert_org();
        });
        //分配角色内容
        $('#roler-conten li').live('click',function () {
            $(this).addClass('roler-mes-active').siblings('li').removeClass('roler-mes-active')
         });
        $('#addroler-content li').live('click',function () {
            $(this).addClass('roler-mes-active').siblings('li').removeClass('roler-mes-active')
        });
        //保存职能
        documentBindFunc.on('click','#departmentrolerAlert_btn',function () {
            fun.saveJobFunRole();
        });
        //添加按钮
        documentBindFunc.on('click','#add_opt',function () {
            var _that = $(this);
            $.each($('#roler-conten li'),function () {
                   
                if($(this).hasClass('roler-mes-active')){
                            var text = $(this).text();
                            var id = $(this).attr('data-value');
                            var orgId=$(this).attr('data-orgId');
                            
                        //判断右侧是否已经存在了
                        var getli = $("#addroler-content").find('li');
                        if(getli != null && getli.length > 0){
                                   var existId= false;
                                   $.each(getli, function(index,rows) {
                                var getId = $(this).attr('data-value');
                                if(getId == id){
                                    existId =true;
                                }
                            });
                            if(!existId){
                                 $(this).remove();
                                var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                                $('#addroler-content').append(roles);
                            }else{
                              $(this).remove();
                            }
                        }else{
                             $(this).remove();
                              var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                                    $('#addroler-content').append(roles);
                        }
                        
                        
                        }
               })
     });
     //添加所有
        documentBindFunc.on('click','#addall_opt',function () {
              $.each($('#roler-conten li'),function () {
                        var text = $(this).text();
                        var id = $(this).attr('data-value');
                        var orgId=$(this).attr('data-orgId');
                        //判断右侧是否已经存在了
                        var getli = $("#addroler-content").find('li');
                        if(getli != null && getli.length > 0){
                               var existId= false;
                                   $.each(getli, function(index,rows) {
                                var getId = $(this).attr('data-value');
                                if(getId == id){
                                    existId =true;
                                }
                            });
                            if(!existId){
                                 $(this).remove();
                                var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                                $('#addroler-content').append(roles);
                            }else{
                              $(this).remove();
                            }
                        }else{
                               $(this).remove();
                               var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                           $('#addroler-content').append(roles);
                        }
                  });
          });
        //删除所有
        documentBindFunc.on('click','#removeall_opt',function () {
              $.each($('#addroler-content li'),function () {
                   var text = $(this).text();
                    var id = $(this).attr('data-value');
                    var orgId=$(this).attr('data-orgId');
                     //判断左侧
                     var getli = $("#roler-conten").find('li');
                     if(getli != null && getli.length > 0){
                        var existId= false;
                                $.each(getli,function(index,row){
                                    var getId = $(this).attr('data-value');
                                    if(getId == id){
                                        existId =true;
                                    }
                                });
                                if(!existId){
                                    $(this).remove();
                                    var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                                    $('#roler-conten').append(roles);
                                }else{
                                    $(this).remove();
                                    
                                }
                     }else{
                         $(this).remove();
                        var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                        $('#roler-conten').append(roles);
                     }
                  })
          });
      //删除
        documentBindFunc.on('click','#remove_opt',function () {
              var _that = $(this);
              $.each($('#addroler-content li'),function () {
                      if($(this).hasClass('roler-mes-active')){
                             var text = $(this).text();
                             var id = $(this).attr('data-value');
                             var orgId=$(this).attr('data-orgId');
                             //判断左侧
                             var getli = $("#roler-conten").find('li');
                             if(getli != null && getli.length > 0){
                                var existId= false;
                                $.each(getli,function(index,row){
                                    var getId = $(this).attr('data-value');
                                    if(getId == id){
                                        existId =true;
                                    }
                                });
                                if(!existId){
                                    $(this).remove();
                                    var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                                    $('#roler-conten').append(roles);
                                }else{
                                    $(this).remove();
                                }
                             }else{
                                 $(this).remove();
                                var roles ='<li class="roler-mes" data-value='+id+' data-orgId='+orgId+'>'+text+'</li>';
                                $('#roler-conten').append(roles);
                             }
                          }
                   })
          });
        //初始化table
        fun.initTable();
    }
    /**
     * 处理错误信息
     * @param {Object} res
     */
    function isError(res){
        if(res == null || res == undefined){
            return true;
        }
        if(res.code!='8888'){
            swal({title:"错误提示",text:res.msg,type:"error",timer:6000,allowOutsideClick:true});
            return true;
        }else{
            return false;
        }
    }
    
    /**
     * 判断角色名称是否已经存在.<br/>
     */
    
    $('#roleName').blur(function() {
        var roleName = $("#roleName").val();
        var sysCode=sessionStorage.getItem("sysCode");
        var errorIfo = $('#role_alert_error');
        if(roleName != null){
            var req= {
                roleName: roleName,
                sysCode:sysCode
            };
            sysAjax({
                    method: 'post',
                    url: dataUrl.util.queryRoleExistByRoleName(),
                    data: JSON.stringify(req),
                    dataType:'json',
                    async:false,
                    success: function (res) {
                        if(res != null ){
                              var data= res.data;
                              if(data){
                                errorIfo.text('该角色名称已经存在!');
                            $('#roleName').focus()
                            return false;
                              }else{
                                errorIfo.text('');
                              }
                        }else{
                              swal({title:"错误提示",text:res.msg,type:"error",timer:3000,allowOutsideClick:true});
                          return false;
                        }
                    }
                });
        }
    });
    
    /**
     * 自定义table AJAX请求
     * @param {Object} params
     */
    function tableLoadRequest(params){
        var id= $('#select_page_role_id').val();
            if(isNaN(id)){
                id= 0;
            }
         var roleName=$('#select_page_role_ame').val();
         if(roleName == null || roleName ==''){
            roleName = '';
         }
         var sysCode=sessionStorage.getItem("sysCode");
        if(sysCode == null || sysCode ==''){
              sysCode = sysComm.sysCode;
        }
        //设置请求参数
        var pageNum = (params.data.offset/params.data.limit)+1;
        var req= {
            baseRequest:{
                pageNum:pageNum,
                pageSize:params.data.limit
            },
            sysCode:sysCode,
            roleName:roleName,
            id:id,
            roleCode:''
        };
        var easyUIOps = {
            method: params.type,
            url: dataUrl.util.getQueryRoles(),
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType:'json',
            success: function(res){
                //console.log(res);
                if(isError(res)){
                    return false;
                }
                params.success(res.data);
            }
        };
        sysAjax(easyUIOps);
    }
})();