var page = 1;

$(function() {getData()});

function getData() {
  _vp.ParticipationRecord(
    {
        page: 1,
        number: 10,
    },
    function(res) {
        if (res.status == 2001) {
            //需要登录
            top.location.href = "login.html";
            return;
        }else if(res.status == -1) {
            toast.fail({
                title:"系统繁忙",
                duration:2000
            });
            return;
        }
        var ele = $(".content");
        var result = res.data;
        ele.html("");
        for (var i = 0; i < result.length; i++) {
            ele.append(
            	
            	 '<li>'+
            	 	'<div class="record-par-all">'+
	            	 	 '<div class="record-img" ><img src='+result[i].product_image+' /> </div>'+
	                    /* '<i style="background: url('+result[i].product_image+') no-repeat;background-size: 0.56rem 0.56rem;"></i>'+   */  
	            	 	 '<div class="record-single-all">'+
		            	 	 '<div class="record-single">'+
		            	 	 	'<div class="record-product-name  ellipsis-1">'+result[i].product_name+'</div>'+
		            	 	 	'<div class="record-single-time ellipsis-1">'+timestampToTime(result[i].time)+'</div>'+
		                     '</div>'+
		                     '<div class="record-single">'+
		                     	'<div class="record-person-name ellipsis-1">'+result[i].vpay_name+'</div>'+
		                     	'<div class="record-single-number ellipsis-1">幸运号：'+result[i].lucky_number+'</div>'+
		                     '</div>'+ 
		                     
		                   /*  '<div class="record-single">'+
		                     '<div class="record-product-name  ellipsis-1">参与了'+result[i].product_name+'夺宝</div>'+
		                     '</div>'+*/
		                 '</div>'+  
	                 '</div>'+
                 '</li>'	
            		
              
            )
        }
    }
  );
}

function getMore() {
    page++;
    _vp.ParticipationRecord(
      {
          page: page,
          number: 10,
      },
      function(res) {
          if (res.status == 2001) {
              //需要登录
              top.location.href = "login.html";
              return;
          }else if(res.status == -1) {
              toast.fail({
                  title:"系统繁忙",
                  duration:2000
              });
              return;
          }else if(res.data.length ==0){
            page--;
            return;
          }
          var ele = $(".content");
          var result = res.data;
          for (var i = 0; i < result.length; i++) {
              ele.append(
            		  '<li>'+
	              	 	'<div class="record-par-all">'+
	  	            	 	 '<div class="record-img" ><img src='+result[i].product_image+' /> </div>'+
	  	                    /* '<i style="background: url('+result[i].product_image+') no-repeat;background-size: 0.56rem 0.56rem;"></i>'+   */  
	  	            	 	 '<div class="record-single-all">'+
	  		            	 	 '<div class="record-single">'+
	  		            	 	 	'<div class="record-product-name  ellipsis-1">'+result[i].product_name+'</div>'+
	  		            	 	 	'<div class="record-single-time ellipsis-1">'+timestampToTime(result[i].time)+'</div>'+
	  		                     '</div>'+
	  		                     '<div class="record-single">'+
	  		                     	'<div class="record-person-name ellipsis-1">'+result[i].vpay_name+'</div>'+
	  		                     	'<div class="record-single-number ellipsis-1">幸运号：'+result[i].lucky_number+'</div>'+
	  		                     '</div>'+ 
	  		                     
	  		                   /*  '<div class="record-single">'+
	  		                     '<div class="record-product-name  ellipsis-1">参与了'+result[i].product_name+'夺宝</div>'+
	  		                     '</div>'+*/
	  		                 '</div>'+  
	  	                 '</div>'+
	                   '</li>'	
            		 /* '<li>'+
                      '<i style="background: url('+result[i].product_image+') no-repeat;background-size: 0.56rem 0.56rem;"></i>'+                     
                      '<div class="record-single">'+
                      '<div class="record-single-number ellipsis-1">幸运号：'+result[i].lucky_number+'</div>'+
                      '<div class="record-single-time ellipsis-1">'+timestampToTime(result[i].time)+'</div>'+
                      '</div>'+      
                      '<div class="record-single">'+
                      '<div class="record-product-name">参与了'+result[i].product_name+'夺宝</div>'+
                      '</div>'+
                      '</li>'	*/
               
              )
          }
      }
    );
  }

window.onscroll = function() {
    //监听事件内容
    if (getScrollHeight() == getWindowHeight() + getDocumentTop()) {
      //当滚动条到底时,这里是触发内容
      //异步请求数据,局部刷新dom
      getMore();
    }
  };