var page = 1;
var type = 1; //1我参与的 全部记录 2.进行中 3.已开奖
var toast = new auiToast();

function getData(e) {
  toast.loading({
    title: "加载中",
    duration: 2000
  });
  type = e;
  page = 1;
  _vp.RecordOperation(
    {
      type: type,
      page: page,
      number: 10
    },
    function(res) {
      toast.hide();
      if (res.status == 2001) {
        //需要登录
        top.location.href = "login.html";
        return;
      } else if (res.status == -1) {
        toast.fail({
          title: "系统繁忙",
          duration: 2000
        });
        return;
      } else if (res.status == 1) {
        var ele;
        if (type == 1) {
          ele = $("#all");
        } else if (type == 2) {
          ele = $("#going");
        } else if (type == 3) {
          ele = $("#open");
        }
        var result = res.data;
        ele.html("");
        for (var i = 0; i < result.length; i++) {
          if (result[i].state == 2) {
            var endTime = timestampToTime(result[i].finish_time);
            ele.append(
            	
            	'<div class="indiana-all">'+
	            	'<div class="indiana-phase-time">'+
		        		'<div class="indiana-phase">期号：'+result[i].issue+'</div>'+
		        		'<div class="indiana-time ellipsis-1">'+endTime+'</div>'+
		        	'</div>'+
		        	'<div class="indiana-single-all">'+
		            	'<div class="indiana-single-img"><img src='+result[i].product_image+' /></div>'+
		            	'<div class="indiana-single-details">'+
			            	'<div class="indiana-product-see">'+	
		            			'<div class="indiana-product-name ellipsis-1">'+result[i].product_name+'</div>'+
		            			'<div class="indiana-see"><a class="indiana-see-btn" href="DetailsParticipation.html?id=' +result[i].id +'">查看详情</a></div>'+
		            		'</div>'+
			            	'<div class="indiana-name ellipsis-1">获奖者：'+result[i].winning_vpay_name+'</div>'+
			            	'<div class="indiana-number ellipsis-1">幸运号：'+result[i].winning_number+'</div>'+
			         
			            	'<div class="indiana-count-all">'+
			            		'<div class="indiana-phase-count ellipsis-1">参与人次：'+result[i].participate_number+'</div>'+
			            		'<div class="indiana-all-need ellipsis-1">总需人次：'+result[i].need_number+'</div>'+
			            	'</div>'+
		            	'</div>'+
		            '</div>'+
            	'</div>'
            		
            	
     
            );
          } else {
            var allNum = result[i].need_number;
            var joined = result[i].participate_number;
            var remaining = allNum - joined;
            var percent = ((joined / allNum)*100).toFixed(2);
            ele.append(
            		

                	'<div class="indiana-all">'+
    	            	'<div class="indiana-phase-time">'+
    		        		'<div class="indiana-phase">期号：'+result[i].issue+'</div>'+
    		        	'</div>'+
    		        	'<div class="indiana-single-all">'+
    		            	'<div class="indiana-single-img"><img src='+result[i].product_image+' /></div>'+
    		            	'<div class="indiana-single-details">'+
    			            	'<div class="indiana-product-see">'+	
    		            			'<div class="indiana-product-name ellipsis-1">'+result[i].product_name+'</div>'+
    		            			'<div class="indiana-see"><a class="indiana-see-btn" href="DetailsParticipation.html?id=' +result[i].id +'">查看详情</a></div>'+
    		            		'</div>'+
 
    			            	'<div class="indiana-count-all" style="margin-top: 3px;">'+
				            		'<div class="indiana-phase-count ellipsis-1">参与人次：'+joined+'</div>'+
				            		
				            		'<div class="indiana-all-need ellipsis-1">总需人次：'+allNum+'</div>'+
				            	'</div>'+
				            	'<div class="indiana-progress">'+
			            			'<div class="kj_div">开奖进度：<span><em style=" width:'+percent +'%;"></em></span><label>' +percent +'%</label></div>' +
			            		'</div>'+
				            	/*'<div class="indiana-lis-count ellipsis-1">剩余人次：'+remaining+'</div>'+*/
    		            	'</div>'+
    		            '</div>'+
                	'</div>'
           
            );
          }
        }
      }
    }
  );
}

function getMore() {
  toast.loading({
    title: "加载中",
    duration: 2000
  });
  page++;
  _vp.RecordOperation(
    {
      type: type,
      page: page,
      number: 10
    },
    function(res) {
      toast.hide();
      if (res.status == 2001) {
        //需要登录
        top.location.href = "login.html";
        return;
      } else if (res.status == -1) {
        toast.fail({
          title: "系统繁忙",
          duration: 2000
        });
        return;
      }
      if (res.data.length == 0) {
        page--;
        return;
      }
      var ele;
      if (type == 1) {
        ele = $("#all");
      } else if (type == 2) {
        ele = $("going");
      } else if (type == 3) {
        ele = $("open");
      }
      var result = res.data;
      if (result.length == 0) {
        ele.append(
          '<div class="yy_jl_no">' +
            "<i></i>" +
            "<p>您还没有夺宝记录哦2！</p>" +
            '<a href="index.html">立即夺宝</a>' +
            "</div>"
        );
      }
      for (var i = 0; i < result.length; i++) {
        if (result[i].state == 2) {
          var endTime = result[i];
          ele.append(

              	'<div class="indiana-all">'+
  	            	'<div class="indiana-phase-time">'+
  		        		'<div class="indiana-phase">期号：'+result[i].issue+'</div>'+
  		        		'<div class="indiana-time ellipsis-1">'+endTime+'</div>'+
  		        	'</div>'+
  		        	'<div class="indiana-single-all">'+
  		            	'<div class="indiana-single-img"><img src='+result[i].product_image+' /></div>'+
  		            	'<div class="indiana-single-details">'+
  			            	'<div class="indiana-product-see">'+	
  		            			'<div class="indiana-product-name ellipsis-1">'+result[i].product_name+'</div>'+
  		            			'<div class="indiana-see"><a class="indiana-see-btn"  href="DetailsParticipation.html?id=' +result[i].id +'">查看详情</a></div>'+
  		            		'</div>'+
  			            	'<div class="indiana-name ellipsis-1">获奖者：'+result[i].winning_nickname+'</div>'+
  			            	'<div class="indiana-number ellipsis-1">幸运号：'+result[i].winning_number+'</div>'+
  			         
  			            	'<div class="indiana-count-all">'+
  			            		'<div class="indiana-phase-count ellipsis-1">参与人次：'+result[i].participate_number+'</div>'+
  			            		'<div class="indiana-all-need ellipsis-1">总需人次：'+result[i].need_number+'</div>'+
  			            	'</div>'+
  		            	'</div>'+
  		            '</div>'+
              	'</div>'
          
          );
        } else {
          var allNum = result[i].need_number;
          var joined = result[i].participate_number;
          var remaining = allNum - joined;
          var percent = ((joined / allNum)*100).toFixed(2);
          ele.append(
        		  
        	'<div class="indiana-all">'+
	            	'<div class="indiana-phase-time">'+
		        		'<div class="indiana-phase">期号：'+result[i].issue+'</div>'+
		        		/*'<div class="indiana-time ellipsis-1">'+endTime+'</div>'+*/
		        	'</div>'+
		        	'<div class="indiana-single-all">'+
		            	'<div class="indiana-single-img"><img src='+result[i].product_image+' /></div>'+
		            	'<div class="indiana-single-details">'+
			            	'<div class="indiana-product-see">'+	
		            			'<div class="indiana-product-name ellipsis-1">'+result[i].product_name+'</div>'+
		            			'<div class="indiana-see"><a class="indiana-see-btn" href="DetailsParticipation.html?id=' +result[i].id +'">查看详情</a></div>'+
		            		'</div>'+
		  
			            	'<div class="indiana-count-all" style="margin-top: 3px;">'+
			            		'<div class="indiana-phase-count ellipsis-1">参与人次：'+joined+'</div>'+
			            		
			            		'<div class="indiana-all-need ellipsis-1">总需人次：'+allNum+'</div>'+
			            	'</div>'+
			            	'<div class="indiana-progress">'+
		            			'<div class="kj_div">开奖进度：<span><em style=" width:'+percent +'%;"></em></span><label>' +percent +'%</label></div>' +
		            		'</div>'+
			            	/*'<div class="indiana-lis-count ellipsis-1">剩余人次：'+remaining+'</div>'+*/
		            	'</div>'+
		            '</div>'+
          	'</div>'
         
          );
        }
      }
    }
  );
}

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

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