//查询人员
function load(page, limit, phone){
    layer.load(3);
    $.ajax({
        url: "/personal/getEmployees",
        type: "get",
        data: {
            "page": page,
            "limit": limit,
            "phone": phone
        },
        headers: {"token": localStorage.getItem("token")},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                $(".content_div div").remove();
                $.each(data.data, (index, item) => {
                    $(".content_div").append("<div id="+ item.code +" class=\"content_column\">\n" +
                        "<div class=\"content_div_input\">\n" +
                        "<div class=\"head_name\" style=\"width: 5%;\">"+ (index + 1) +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 37.5%;\">"+ item.name +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 37.5%;\">"+ item.phone +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 20%;\">" +
                        "<button class=\"offer_button button_div_head\" onclick='modify(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"quanxianfuyu\">"+ paramReturn("权限赋予", parent.type) +"</span></button>\n" +
                        // "<button class=\"button_div_head layui-btn-danger\" onclick='delChild(this)'><img src=\"/images/demandForSingle/offer.png\"/><span>删除</span></button></div>\n" +
                        "</div>\n" +
                        "</div>")
                });
                //自定义样式分页
                laypage.render({
                    elem: 'demo2'
                    ,count: data.count
                    ,theme: '#1E9FFF'
                    , limit: limit
                    , curr: page
                    , jump: function (obj,first) {
                        if (!first) {
                            load(obj.curr,obj.limit, phone);
                        }
                    }
                    , prev: '<em><i class="layui-icon">&#xe603;</i></em>'
                    , next: '<em><i class="layui-icon">&#xe602;</i></em>'
                });
            } else {
                layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//权限修改
function modify(obj){
    let id = $(obj).parent().parent().parent().attr("id");
    layer.open({
        type: 2,
        title: false,
        anim: 1,
        closeBtn: 1,
        area: ['500px', '580px'],
        content: '/page/modify?id=' + id
    });
}
//删除子账号
function delChild(obj){
    layer.load(3);
    let id = $(obj).parent().parent().parent().attr("id");
    $.ajax({
        url: "/personal/delChild",
        type: "delete",
        data: {
            "id": id
        },
        headers: {"token": localStorage.getItem("token")},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                layer.msg("删除成功", {icon: 1, function(){
                    load(1, 7, phone);
                }});
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}