define (['doT', 'text!temp/auth_rule_index_template_tpl.html', 'css!style/home.css','pagination','bootstrapJs'], function (doT, template) {
authRule={
    pageNo:1,
    pageSize:15,
    init:function () {
       //初始化dot
       $("body").append(template);
       authRule.getList();
       authRule.event();
    },
    event:function () {
        $ (document).delegate (".edit", "click", function () {//点击编辑
            authRule.house_id = $ (this).attr ("data-id");
            authRule.Edid_add();
            authRule.Edit();
        });
        $ (document).delegate (".submit_edit", "click", function () {//提交编辑
            authRule.Submit_edit();
            authRule.getList();
        });
        $ (document).delegate (".edit_add", "click", function () {//新增
            authRule.Edid_add();
        });

    },
    Edid_add:function(){
        $.ajax({
            url: '/index/classList/type/1',//获取后台菜单
            type: 'GET',
            async: true,
            dataType: 'json',
            success: function (data) {
                var temp=document.getElementById('auth_class_tpl').innerHTML;
                var doTempl=doT.template(temp);
                $("#pid").html(doTempl(data.data));//赋值
            }
        });
    },
    Edit:function(){//获取
        $.ajax({
            'type': 'GET',
            'url' : '/index/updateAuthRule/group_id/',//获取编辑数据
            data: {"id":authRule.house_id},
            dataType: "json",
            success: function (data) {
                $("input[name = id]").val(data.data.id);
                $("input[name = title]").val(data.data.title);
                $("input[name = name]").val(data.data.name);
                $("input[name = sort]").val(data.data.sort);
                $("#pid").val(data.data.pid);
                if(data.data.is_menu==0){
                    $("#is_menu2").attr('checked',true);
                }else{
                    $("#is_menu1").attr('checked',true);
                }
            }
        });
    },
    Submit_edit:function(){//提交编辑的信息
        var par={}
        par.id= authRule.house_id;
        par.title= $("input[name = title]").val();
        par.name= $("input[name = name]").val();
        par.sort= $("input[name = sort]").val();
        par.pid=$("#pid").val();
        par.is_menu=$("input[name =is_menu]:checked").val();
        $.ajax({
            'type': 'POST',
            'url' : '/index/updateAuthRule',
            data:par,
            dataType: "json",
            success: function(data){
                if(data.code==200){

                }else{
                    alert(data.msg);
                }
            }
        });
    },
    getList:function(pageNo){
        authRule.pageNo =pageNo;
        var params ={};
        params.pageNo =authRule.pageNo;
        params.pageSize=authRule.pageSize;
        $.ajax({
            url: '/index/AuthRulelist.html',
            type: 'GET',
            async: true,
            data: params,
            dataType: 'json',
            success: function (data) {
            var temp=document.getElementById('auth_rule_index_tpl').innerHTML;
            var doTempl=doT.template(temp);
            $("#auth_rule_list").html(doTempl(data.data.list));
                /*分页代码*/
                $ ("#pagediv").pagination ({
                    length: data.data.total,
                    current: pageNo,
                    every: authRule.pageSize,
                    onClick: function (el) {
                        authRule.getList (el.num.current);
                    }
                });
            }
        })
    }

}
    return authRule;
});