/**
 * Created by webshow on 2018/8/13.
 */
//$ip="http://test.api.lvdou66.com/";
$ip = 'https://zhibo.lvdou66.com/';
cdn="https://zhibocdn.lvdou66.com/comm";
$(function () {
    if($.cookie("ukk")!=undefined){
        $.ajax({
            url:$ip+"weblive/user/myinfo.html",
            data:{
                uid:$.cookie("ukk"),
                token: $.cookie("tbb")
            },
            type:"post",
            error: function (msg) {
                console.log('请求出错');
                $.cookie("ukk", null, {
                    path: "/",
                    expires: -1
                });
                $.cookie("tbb", null, {
                    path: "/",
                    expires: -1
                });
                layer.msg("登录失效,请重新登录。")
                setTimeout(function () {
                    window.location.reload()
                },1500)
            },
            success: function (msg) {
                var data=JSON.parse(msg);
                // console.log(data)
                if(data.code==1){
                    $(".login-no").hide();
                    $(".lonin-yes").css("display","inline-block");
                    $(".header-avatar").attr("src",cdn+data.user.face+'?x-oss-process=image/resize,w_100');
                    $(".header-name").text(data.user.nickname);
                    $(".info-avatar").attr("src",cdn+data.user.face+'?x-oss-process=image/resize,w_100');
                    $(".info-name").text(data.user.nickname);
                    $(".level1").attr("src","https://zhibocdn.lvdou66.com/comm/level/"+data.user.richlevel+".png")
                    $(".level2").attr("src","https://zhibocdn.lvdou66.com/comm/level/"+(data.user.richlevel+1)+".png")
                    $(".info-score").html()
                    $(".info-uid").text("Yabo ID:"+data.user.uid);
                    $(".diamond").text(data.diamond);
                    $(".coin").text(data.coin);
                    $(".login-out").on("click", function () {
                        $.ajax({
                            url:$ip+"/weblive/user/logout.html",
                            data:{
                                uid:$.cookie("ukk"),
                                token: $.cookie("tbb")
                            },
                            type:"post",
                            error: function (msg) {
                                console.log('请求出错');
                            },
                            success: function (msg) {
                                var data=JSON.parse(msg);
                                // console.log(data)
                                if(data.code==1){
                                    $.cookie("__qc__k", null, {
                                        path: "/",
                                        expires: -1
                                    });
                                    $.cookie("ukk", null, {
                                        path: "/",
                                        expires: -1
                                    });
                                    $.cookie("tbb", null, {
                                        path: "/",
                                        expires: -1
                                    });
                                    window.location.reload()
                                }
                            }
                        })
                    })

                    $.ajax({
                        url:$ip+"/weblive/level.html",
                        type:"post",
                        success: function (msg) {
                            var richList=JSON.parse(msg)
                            console.log(richList);
                            var richMax=richList.data[data.user.richlevel].score;
                            $(".info-score span").eq(1).text(richMax)
                            $('.info-score span').eq(0).text(data.user.richnum)
                            if(data.user.richlevel==0){
                                var percentage=Math.floor((data.user.richnum/richMax)*100);
                                if(percentage>96)percentage=96
                                $(".propress").css("width",percentage+"%")
                            }else{
                                var percentage=Math.floor(((data.user.richnum-richList.data[data.user.richlevel-1].score)/(richMax-richList.data[data.user.richlevel-1].score))*100);
                                if(percentage>96)percentage=96
                                $(".propress").css("width",percentage+"%")
                            }
                        }
                    })
                }else{
                    $.cookie("ukk", null, {
                        path: "/",
                        expires: -1
                    });
                    $.cookie("tbb", null, {
                        path: "/",
                        expires: -1
                    });
                    layer.msg("登录失效,请重新登录。")
                    setTimeout(function () {
                        window.location.reload()
                    },1500)
                }
            }
        })
    }else{

    }

})
$(".login-btn").on("click", function () {
    layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        skin: "yourclass",
        area: ["760px", "620px"],
        content: "../pop/login.html?v='2019053001'",

    })
})
if($.cookie("ukk")!=undefined){
    $(".yaboDown").on("click", function () {
        layer.open({
            type: 2,
            title: false,
            shadeClose: true,
            skin: "yourclass",
            area: ["480px", "820px"],
            content: "../room/activity.html?uid="+ $.cookie("ukk")+"&token="+ $.cookie("tbb"),
        })
    })
}else{
    $(".yaboDown").on("click", function () {
        layer.open({
            type: 2,
            title: false,
            shadeClose: true,
            skin: "yourclass",
            area: ["480px", "820px"],
            content: "../room/activity.html?v='201902140401&uid=7878549",
        })
    })
}
$(".register").on("click", function () {
    layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        skin: "yourclass",
        area: ["760px", "790px"],
        content: "../pop/registered.html?v='2019053001'",
    })
})
$(".pay").on("click", function () {
    layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        skin: "yourclass",
        area: ["760px", "600px"],
        content: "../pop/pay.html?v='2019053001'",

    })
})
$(".lonin-yes").hover(function () {
    $(this).find(".info-pop-box").stop();
    $(this).find(".info-pop-box").slideDown(100);
},function () {
    $(this).find(".info-pop-box").stop();
    $(this).find(".info-pop-box").slideUp(100);
});

/*退出登录*/
$(".outlogin").click(function () {
    $(".pop-outlogin").fadeIn(100);
    $(".black-bg").fadeIn(100);
});
$(".pop-outlogin .close").click(function () {
    $(".pop-outlogin").fadeOut(100);
    $(".black-bg").fadeOut(100);
});
$(".pop-outlogin .canceloutlogin").click(function () {
    $(".pop-outlogin").fadeOut(100);
    $(".black-bg").fadeOut(100);
});