(function(){
    X.pageLogic['addrole'] = {
        init : function(parms){
            var me = this;
            
            var data;
            X.api("authz/api_list","get",{},function(d){
                data = d;
                X.laytpldata("#addrole-info-table-con-dot",d,".addrole-info-table-con");
                layui.form.render();
            });

            if(parms){
                this.parms = parms;
                var passdata = parms;
                console.log(passdata);
                X.api("authz/get_permissions_for_user_in_domain","post",{role_id:passdata.id,game:X['DATA']['game']},function(d){
                   console.log(d);
                    $('.addrole-tit').val(passdata.title);
                    var selinput = {}
                    for(let i in d){
                        selinput[d[i]['_id']] = true
                    }
                    console.log(selinput);
                    layui.form.val('addroleexample', selinput)
                });
            }
            $(".addrole-qd").click(function(){
                var tit = $(".addrole-tit").val();
                var addroledata = layui.form.val("addroleexample");
                console.log(addroledata);
                var dataArr =[];
                for(let i in addroledata){
                    dataArr.push(i);
                }
                if(passdata){
                    // X.api("authz/add_roles","post",{name:tit,game:X['DATA']['game'],desc:'111'},function(d){
                    
                    //     X.api("authz/add_policy","post",{role_id:d,game:X['DATA']['game'],act:"*",path_list:dataArr},function(d){
                    //         layer.msg("创建成功");
                    //         $(".addrole-qx a").click();
                    //     })
                    // })
                }else{
                    X.api("authz/add_roles","post",{name:tit,game:X['DATA']['game'],desc:'111'},function(d){
                    
                        X.api("authz/add_policy","post",{role_id:d,game:X['DATA']['game'],act:"*",path_list:dataArr},function(d){
                            layer.msg("创建成功");
                            $(".addrole-qx a").click();
                        })
                    })
                }
                
            });

        }
    };
})();