var page = 1;
var toast = new auiToast();
$(function() {
  getData();
});

function getData() {
  _vp.homeAllRecord(
    {
      type: 1,
      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 = $(".wq_list");
      var result = res.data;
      ele.html('');
      for (var i = 0; i < result.length; i++) {
        ele.append(
        		
        		  "<ul>" +
                  "<h2>期号： " +
                  result[i].issue +
                  " <span>开奖时间：" +
                  timestampToTime(result[i].finish_time) +
                  "</span></h2>" +
                  "<div class='win-pro-revealed'>"+
                  "<div class='win-pro-img'><img src="+result[i].product_image+" />"+
                  "</div>"+
              /*    "<li>" +
                  '<i style="background: url(' +
                  result[i].product_image +
                  ') no-repeat;background-size: 0.56rem 0.56rem;"></i>' +*/
                  "<div class='win-details-all'>"+
                  "<div class='win-single'>"+
                  "<div class='win-name ellipsis-1'>获奖者："+result[i].vpay_name +"</div>"+
                  "<div class='win-number ellipsis-1' >幸运号："+ result[i].winning_number +"</div>"+
                  "</div>"+
                  "<div class='win-product_name ellipsis-1'>商品名称："+ result[i].product_name +"</div>"+
                  "<div class='win-single'>"+
                  "<div class='win-join ellipsis-1'>本期参与人次："+result[i].need_number +"</div>"+
                  "<div class='win-need ellipsis-1'>总需人次："+result[i].need_number +"</div>"+
                  "</div>"+
                  '</div>'+
                  '</div>'+
                  "</li>" +
                  "</ul>"
        );
      }
    }
  );
}

function getMore() {
    page++;
    _vp.homeAllRecord(
      {
        type: 1,
        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 = $(".wq_list");
        var result = res.data;
        for (var i = 0; i < result.length; i++) {
          ele.append(

        		  "<ul>" +
                  "<h2>期号： " +
                  result[i].issue +
                  " <span>开奖时间：" +
                  timestampToTime(result[i].finish_time) +
                  "</span></h2>" +
                  "<li>" +
                  '<i style="background: url(' +
                  result[i].product_image +
                  ') no-repeat;background-size: 0.56rem 0.56rem;"></i>' +
                  "<div class='win-single'>"+
                  "<div class='win-name ellipsis-1'>获奖者："+result[i].vpay_name +"</div>"+
                  "<div class='win-number ellipsis-1' >幸运号："+ result[i].winning_number +"</div>"+
                  "</div>"+
                  "<div class='win-product_name ellipsis-1'>商品名称："+ result[i].product_name +"</div>"+
                  "<div class='win-single'>"+
                  "<div class='win-join ellipsis-1'>本期参与人次："+result[i].need_number +"</div>"+
                  "<div class='win-need ellipsis-1'>总需人次："+result[i].need_number +"</div>"+
                  "</div>"+
                  "</li>" +
                  "</ul>"	  
        		  
           /* "<ul>" +
              "<h2>期号： " +
              result[i].issue +
              " <span>开奖时间：" +
              timestampToTime(result[i].finish_time) +
              "</span></h2>" +
              "<li>" +
              '<i style="background: url(' +
              result[i].product_image +
              ') no-repeat;background-size: 0.56rem 0.56rem;"></i>' +
              "<p><span>获得者：</span> <em>" +
              result[i].vpay_name +
              "</em> （本期参与" +
              result[i].need_number +
              "人次）</p>" +
              "<p><span>幸运号： </span> <em>" +
              result[i].winning_number +
              "</em></p>" +
              "<p><span>总 需：</span> " +
              result[i].need_number +
              "人次</p>" +
              "</li>" +
              "</ul>"*/
          );
        }
      }
    );
  }

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