/// <reference path="jquery-1.10.2.min.js" />


var pageindex = 1;
var pagesize = 10;
var pagecount = 0;
$(function () {
    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": "4" }, function (data) {
        var data = eval('(' + data + ')');
        pagecount = data.pagecount;
        $("#userlist").html("").append(data.pagelist);
        layui.use(['laypage', 'layer'], function () {
            var nums = pagesize; //每页出现的数据量
            var laypage = layui.laypage
            , layer = layui.layer;
            laypage.render({
                elem: 'pager'
               , count: pagecount //总页数
               , groups: 1
                , jump: function (obj) {
                    pageindex = obj.curr;//获取到当前页
                    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": "4" }, function (data) {
                        var data = eval('(' + data + ')');
                        pagecount = data.pagecount;
                        $("#userlist").html("").append(data.pagelist);
                    });

                }
            });
        });
    });


});



function QueryMail_btn() {
    var QueryMail = $.trim($("#User_mail").val());
    $("#userlists ul").not(":eq(0)").remove();
    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": 1, "QueryMail": QueryMail }, function (data) {
        var data = eval('(' + data + ')');
        pagecount = data.pagecount;
        $("#userlists").html("").append(data.pagelist);
        layui.use(['laypage', 'layer'], function () {
            var nums = pagesize; //每页出现的数据量
            var laypage = layui.laypage
            , layer = layui.layer;
            laypage.render({
                elem: 'pager'
               , count: pagecount //总页数
               , groups: 1
                , jump: function (obj) {
                    pageindex = obj.curr;//获取到当前页
                    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": 1, "QueryMail": QueryMail }, function (data) {
                        var data = eval('(' + data + ')');
                        pagecount = data.pagecount;
                        $("#userlists").html("").append(data.pagelist);
                    });

                }
            });
        });
    });

}






function QueryID_btn() {
    var QueryID = $.trim($("#User_ID").val());
    $("#userlists ul").not(":eq(0)").remove();
    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": 2, "QueryID": QueryID }, function (data) {
        var data = eval('(' + data + ')');
        pagecount = data.pagecount;
        $("#userlists").html("").append(data.pagelist);
        layui.use(['laypage', 'layer'], function () {
            var nums = pagesize; //每页出现的数据量
            var laypage = layui.laypage
            , layer = layui.layer;
            laypage.render({
                elem: 'pager'
               , count: pagecount //总页数
               , groups: 1
                , jump: function (obj) {
                    pageindex = obj.curr;//获取到当前页
                    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": 2, "QueryID": QueryID }, function (data) {
                        var data = eval('(' + data + ')');
                        pagecount = data.pagecount;
                        $("#userlists").html("").append(data.pagelist);
                    });

                }
            });
        });
    });

}





function QueryName_btn() {
    var QueryName = $.trim($("#User_Name").val());
    $("#userlists ul").not(":eq(0)").remove();
    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": 3, "QueryName": QueryName }, function (data) {
        var data = eval('(' + data + ')');
        pagecount = data.pagecount;
        $("#userlists").html("").append(data.pagelist);
        layui.use(['laypage', 'layer'], function () {
            var nums = pagesize; //每页出现的数据量
            var laypage = layui.laypage
            , layer = layui.layer;
            laypage.render({
                elem: 'pager'
               , count: pagecount //总页数
               , groups: 1
                , jump: function (obj) {
                    pageindex = obj.curr;//获取到当前页
                    $.post("/ajax/Admin_UserList.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": 3, "QueryName": QueryName }, function (data) {
                        var data = eval('(' + data + ')');
                        pagecount = data.pagecount;
                        $("#userlists").html("").append(data.pagelist);
                    });

                }
            });
        });
    });

}







function FormatToDate(val) {
    if (val != null) {
        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
        //月份为0-11，所以+1，月份小于10时补个0
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
    }
    return "";
}


function userdel_btn(userdelid) {
    if (!confirm("确定要删除吗？") == true) {

        return true;

    } else {
    $.post("/ajax/Admin_UserList.ashx", { "type": "del", "userdelid": userdelid }, function (data) {
        if (data == "ok") {
            alert("删除成功");
            window.location.href = "./Admin_UserList.aspx";
        } else {
            alert("删除失败");
        }


    });
    }
}






//function QueryName_btn() {
//    var QueryName = $.trim($("#User_Name").val());
//    $("#userlists ul").not(":eq(0)").remove();
//    $.post("/ajax/Admin_UserList.ashx", { "type": 3, "QueryName": QueryName }, function (data) {
//        var d = JSON.parse(data);
//        var s = "";
//        for (var i = 0; i < d.length; i++) {
//            s = "<ul class='userlist'>";
//            s += "<li class='l2'>" + d[i].UserId + "</li>";
//            s += "<li class='l3'>" + d[i].UserName + "</li>";
//            s += "<li class='l4'>" + d[i].UserPhone + "</li>";
//            s += "<li class='l5'>" + d[i].UserCard + "</li>";
//            s += "<li class='l9'>" + d[i].UserQQ + "</li>";
//            s += "<li class='l9'>" + d[i].Useremail + "</li>";
//            s += "<li class='l7'>" + FormatToDate(d[i].CreatedTime) + "</td>";
//            s += "<li class='l8'>" + "<a href='Admin_UserEdit.aspx?id=" + d[i].UserId + "'>编辑</a>|<a href='Admin_userms.aspx?id=" + d[i].UserId + "'>站内信</a>|<a href='Admin_userem.aspx?id=" + d[i].UserId + "'>发邮箱</a>|<button onclick='del(" + d[i].UserId + ")'>删除</button>" + "</li>";
//            $("#userlists").append(s);


//        }


//    })

//}













































//$(function () {
//    //$("#userlists ul").not(":eq(0)").remove();
//    $.post("/ajax/Admin_UserList.ashx", { "type": "4" }, function (data) {
//        var d = JSON.parse(data);
//        var s = "";
//        for (var i = 0; i < d.length; i++) {
//            s += "<ul class='userlist'>"
//            s += "<li class='l2'>" + d[i].UserId + "</li>";
//            s += "<li class='l3'>" + d[i].UserName + "</li>";
//            s += "<li class='l4'>" + d[i].UserPhone + "</li>";
//            s += "<li class='l5'>" + d[i].UserCard + "</li>";
//            s += "<li class='l9'>" + d[i].UserQQ + "</li>";
//            s += "<li class='l9'>" + d[i].Useremail + "</li>";
//            s += "<li class='l7'>" + FormatToDate(d[i].CreatedTime) + "</li>";
//            s += "<li class='l8'>" + "<a href='Admin_UserEdit.aspx?id=" + d[i].UserId + "'>编辑</a>|<a href='Admin_userms.aspx?id=" + d[i].UserId + "'>站内信</a>|<a href='Admin_userem.aspx?id=" + d[i].UserId + "'>发邮箱</a>|<button onclick='del(" + d[i].UserId + ")'>删除</button>" + "</li>";
//            s += "</ul>"
            

//        }
//        $("#userlists").append(s);
//    })

//});


//function QueryMail_btn() {
//    var QueryMail = $.trim($("#User_mail").val());
//    $("#userlists ul").not(":eq(0)").remove();
//    $.post("/ajax/Admin_UserList.ashx", {"type": 1, "QueryMail": QueryMail }, function (data) {
//        var d = JSON.parse(data);
//        var s = "";
//        for (var i = 0; i < d.length; i++) {
//            s += "<ul class='userlist'>"
//            s += "<li class='l2'>" + d[i].UserId + "</li>";
//            s += "<li class='l3'>" + d[i].UserName + "</li>";
//            s += "<li class='l4'>" + d[i].UserPhone + "</li>";
//            s += "<li class='l5'>" + d[i].UserCard + "</li>";
//            s += "<li class='l9'>" + d[i].UserQQ + "</li>";
//            s += "<li class='l9'>" + d[i].Useremail + "</li>";
//            s += "<li class='l7'>" + FormatToDate(d[i].CreatedTime) + "</li>";
//            s += "<li class='l8'>" + "<a href='Admin_UserEdit.aspx?id=" + d[i].UserId + "'>编辑</a>|<a href='Admin_userms.aspx?id=" + d[i].UserId + "'>站内信</a>|<a href='Admin_userem.aspx?id=" + d[i].UserId + "'>发邮箱</a>|<button onclick='del(" + d[i].UserId + ")'>删除</button>" + "</li>";
//            s += "</ul>"

//                    }

//        $("#userlists").append(s);
//                });

//}


//function QueryID_btn() {
//    var QueryID = $.trim($("#User_ID").val());
//    $("#userlists ul").not(":eq(0)").remove();
//$.post("/ajax/Admin_UserList.ashx", { "type": 2, "QueryID": QueryID }, function (data) {
//    var d = JSON.parse(data);
//    var s = "";
//    for (var i = 0; i < d.length; i++) {
//        s += "<ul class='userlist'>"
//        s += "<li class='l2'>" + d[i].UserId + "</li>";
//        s += "<li class='l3'>" + d[i].UserName + "</li>";
//        s += "<li class='l4'>" + d[i].UserPhone + "</li>";
//        s += "<li class='l5'>" + d[i].UserCard + "</li>";
//        s += "<li class='l9'>" + d[i].UserQQ + "</li>";
//        s += "<li class='l9'>" + d[i].Useremail + "</li>";
//        s += "<li class='l7'>" + FormatToDate(d[i].CreatedTime) + "</li>";
//        s += "<li class='l8'>" + "<a href='Admin_UserEdit.aspx?id=" + d[i].UserId + "'>编辑</a>|<a href='Admin_userms.aspx?id=" + d[i].UserId + "'>站内信</a>|<a href='Admin_userem.aspx?id=" + d[i].UserId + "'>发邮箱</a>|<button onclick='del(" + d[i].UserId + ")'>删除</button>" + "</li>";
//        s += "</ul>"
//                }

//    $("#userlists").append(s);
//            });


//        }


//function QueryName_btn() {
//    var QueryName = $.trim($("#User_Name").val());
//    $("#userlists ul").not(":eq(0)").remove();
//    $.post("/ajax/Admin_UserList.ashx", { "type": 3, "QueryName": QueryName }, function (data) {
//        var d = JSON.parse(data);
//        var s = "";
//        for (var i = 0; i < d.length; i++) {
//            s += "<ul class='userlist'>"
//            s += "<li class='l2'>" + d[i].UserId + "</li>";
//            s += "<li class='l3'>" + d[i].UserName + "</li>";
//            s += "<li class='l4'>" + d[i].UserPhone + "</li>";
//            s += "<li class='l5'>" + d[i].UserCard + "</li>";
//            s += "<li class='l9'>" + d[i].UserQQ + "</li>";
//            s += "<li class='l9'>" + d[i].Useremail + "</li>";
//            s += "<li class='l7'>" + FormatToDate(d[i].CreatedTime) + "</li>";
//            s += "<li class='l8'>" + "<a href='Admin_UserEdit.aspx?id=" + d[i].UserId + "'>编辑</a>|<a href='Admin_userms.aspx?id=" + d[i].UserId + "'>站内信</a>|<a href='Admin_userem.aspx?id=" + d[i].UserId + "'>发邮箱</a>|<button onclick='del(" + d[i].UserId + ")'>删除</button>" + "</li>";
//            s += "</ul>"
//        }

//        $("#userlists").append(s);
//    });


//}

//function FormatToDate(val) {
//    if (val != null) {
//        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
//        //月份为0-11，所以+1，月份小于10时补个0
//        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
//        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//        return date.getFullYear() + "-" + month + "-" + currentDate + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
//    }
//    return "";
//}


//function del(id) {
//    $.post("/ajax/Admin_UserList.ashx", { "type": "del", "id": id }, function (data) {
//        if (data == "ok") {
//            alert("删除成功");
//            window.location.href = "./Admin_UserList.aspx";
//        } else {
//            alert("删除失败");
//        }


//    });
//}