Vue.config.devtools = true;
var v = new Vue({
	el:".container",
	data:{
		list:[],
		page:1,
		size:10,
		objType:2,
		finished:false,
        loading:false, //出现了 上拉到底出发了两次请求接口的情况  加一个变量控制一下
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf:-1,
        integralType:"",
        integralCount:"",
        hideBtn: 0
	},
    created:function (){
        if($.cookie("memToken")){
            this.memToken = $.cookie("memToken");
            this.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            this.memHeadImg = $.cookie("memHeadImg");
        }
		this.objId=$("#objId").val();
		this.rankingList();
		this.getDetailData();
        this.findUserIntegral();
		window.addEventListener("scroll", this.scrollBottom, true);
        var myobj = getparamcommon();
        if(myobj){
            this.hideBtn = myobj.hideBtn;
            if(this.hideBtn == 1){
                this.addFreeBuyApi();
            }
        }
	},
	methods:{
        findUserIntegral (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/findUserIntegral",
                data : {
                    memToken:that.memToken
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.userJf = data.data;
                    }
                },
                error : function(data) {
                }
            });
        },
		getDetailData(){
			var that = this;
			$.ajax({
				type : 'POST',
				url : serverHttp+"/live/getDetailData",
				data : {
					memToken:that.memToken,
					liveId: that.objId
				},
				success : function(data) {
					if (data.code == 200) {
						that.liveInfo = data.data;
						$("meta[name='sharetitle']").attr("content",that.liveInfo.shareTitle);
						$("meta[name='sharedesc']").attr("content",that.liveInfo.shareDesc);
						$("meta[name='sharepic']").attr("content",that.liveInfo.sharePic);
						$("meta[name='shareurl']").attr("content",serverHttp+"/live/detail?from=H5&liveId="+that.liveInfo.lvId);
					}
				},
				error : function(data) {
				}
			});
		},
		rankingList () {
			var that = this;
			if (that.loading) {
                return ;
            }
            that.loading = true;
            if(that.start == 1){
                that.list = []
            }
			$.ajax({
				type : 'POST',
				url : serverHttp+"/live/rankList",
				data : {
					objType: that.objType,
					objId: that.objId,
					page: that.page,
					size: that.size
				},
				success : function(data) {
					if (data.code == 200) {
                        that.list = that.list.concat(data.data.rankList);
                        that.info = data.data.info;
                        // 请求的数据未加载完成时
                        that.start = that.start + 1;
                        that.loading = false;
                    } else if (data.code == 10005) {
                        that.finished = true;
                    }
				}
			});
		},
		scrollBottom() {
            const that = this;
            // 滚动到页面底部时
            const el = document.getElementById("list");
            const elHeight = $("#list").offset()['top'];//元素距离顶部距离 该计算可能会有一些偏差
            const windowHeight = window.screen.height;
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop;
            const contentHeight = el.clientHeight;
            //316为
            const toBottom = contentHeight - windowHeight - scrollTop-elHeight;
            if (toBottom < 10 && !that.finished) {
                that.rankingList();
            }
        }
	}
})
