define (['doT', '', 'css!style/home.css','bootstrapJs'], function (doT, template) {
    aagent={
        init:function () {
            //初始化dot
            $("body").append(template);
            aagent.getList();
            aagent.event();
        },
        event:function () {

            $ ("#submit").click(function () {
                var par={}
                par.id= $("input[name = id]").val();
                par.name= $("input[name = name]").val();
                par.store_id= $("input[name = store_id]").val();
                par.phone= $("input[name = phone]").val();
                par.admin_off= $("input[name = admin_off]").val();
                par.sex=$("input[name =sex]:checked").val();
                par.remarks=$("input[name =remarks]").val();
                $.ajax({
                    url: '/index/saveAgent',
                    data:par,
                    type: 'post',
                    async: true,
                    dataType: 'json',
                    success: function (data) {
                        alert(data.msg);
                        console.log(data);
                    }

                });

            })


        },
        getList:function(){

            var id=  getUrlParam('id');
            //判断是否有id参数
            if(!id){
                return false;
            }
            $.ajax({
                url: '/index/updateAuthRule/group_id/'+id,
                type: 'post',
                async: true,
                dataType: 'json',
                success: function (data) {
                    $("input[name = id]").val(data.data.id);
                    $("input[name = phone]").val(data.data.phone);
                    $("input[name = name]").val(data.data.name);
                    $("input[name = store_id]").val(data.data.store_id);
                    $("input[name = remarks]").val(data.data.remarks);

                    if(data.data.sex=='0'){
                        $("#sex0").attr('checked',true);
                    }else if(data.data.sex=='1'){
                        $("#sex1").attr('checked',true);
                    }else{
                        $("#sex2").attr('checked',true);

                    }
                }
            })

        }

    }
    return aagent;
});
