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


var pageindex = 1;
var pagesize = 10;
var pagecount = 0;
$(function () {
    $.post("/ajax/Admin_Other.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": "1" }, function (data) {
        var data = eval('(' + data + ')');
        pagecount = data.pagecount;
        $("#linklist").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_Other.ashx", { "pageindex": pageindex, "pagesize": pagesize, "type": "1" }, function (data) {
                        var data = eval('(' + data + ')');
                        pagecount = data.pagecount;
                        $("#linklist").html("").append(data.pagelist);
                    });

                }
            });
        });
    });

  
});


$(function () {
    $("#Link_Edit_Btn").click(function () {
        var link_sh_id = $.trim($("#Link_Edit_Id").val());
        var link_sh_cate = $.trim($("#Link_Status").children("option:selected").val());
        $.post("/ajax/Admin_Other.ashx", { "type": 2, "link_sh_cate": link_sh_cate, "link_sh_id": link_sh_id }, function (data) {
            var data = eval('(' + data + ')');
            if (data.Success = true) {
                alert("提交成功");
                window.location.href = "./Admin_Link.aspx";
            } else {
                alert("提交失败");
            }

        })
    })





    $("#Link_Add_Btn").click(function () {
        var link_add_name = $.trim($("#Link_Add_Name").val());
        var link_add_link = $.trim($("#Link_Add_Link").val());
        $.post("/ajax/Admin_Other.ashx", { "type": 3, "link_add_name": link_add_name, "link_add_link": link_add_link }, function (data) {

            var data = eval('(' + data + ')');
            if (data.Success = true) {
                alert("添加成功");
                window.location.href = "./Admin_Link.aspx";
            } else {
                alert("添加失败")

            }


        })



    })





})



function linkdel_btn() {
    var linkdelid = $.trim($("#link_del_id").val());

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

        return true;

    } else {
    $.post("/ajax/Admin_Other.ashx", { "type": "linkdel", "linkdelid": linkdelid }, function (data) {
        if (data == "ok") {
            alert("删除成功");
            window.location.href = "./Admin_Link.aspx";

        } else {
            alert("删除失败");
        }




    })
    }

}









//$(function () {
//    $.post("/ajax/LinkBase.ashx", { "cmd": 2 }, function (data) {
//        var d = JSON.parse(data);
//        var s = "";
//        for (var i = 0 ; i < d.length; i++) {
//            s = "<tr>";
//            s += "<td>" + d[i].LinkId + "</td>";
//            s += "<td>" + d[i].LinkName + "</td>";
//            s += "<td>" + d[i].HyperLink + "</td>";
//            s += "<td>" + d[i].Weight + "</td>";
//            s += "<td>" + "<font color='red'>未显示</font>" + "</td>";
//            s += "<td>" + FormatToDate(d[i].LinkTime) + "</td>";
//            s += "<td>" + "<a href='Admin_LinkEdit.aspx?linkid=" + d[i].LinkId + "'>审核</a>" + "</td>";
//            s += "<td>" + "<button onclick='del(" + d[i].LinkId + ")'>删除</button>" + "</td>";
//            $("#linklist_A table").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 "";
}
