apiready = function() {
  api.parseTapmode();
};
var tab = new auiTab(
  {
    element: document.getElementById("tab")
    // callback:function(o,dom){
    //     console.log(o);
    // }
  },
  function(ret) {
    console.log(ret);
  }
);

var dialog = new auiDialog({});

function DeleteQrder() {
  dialog.alert(
    {
      msg: "是否删除订单",
      buttons: ["取消", "确定"]
    },
    function(ret) {
      console.log(ret);
    }
  );
}

var page = 1;

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

/**
 * 获取数据
 */
function getData() {
  _vp.myWinningRecord(
    {
      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;
      } else if (res.status == 1) {
        var ele = $(".product-con");
        var result = res.data;
        var i = result.length;
        ele.html("");
        while (i--) {
          var word;
          if (result[i].state == 1) {
            word = "待开奖";
          } else if (result[i].state == 2) {
            word = "已开奖";
          }
          ele.append(
        	
        		  '<div class="order-list-single">' +
                  
                  '<div class="order-product-list" onclick="test(&quot;order-details.html?id='+result[i].participant_id+'&quot;)">' +
                  '<div class="order-product-img">' +
                  '<img src="' +
                  result[i].product_image +
                  '" />' +
                  "</div>" +
                  '<div class="order-product-con">' +
                  '<div class="order-product-display">'+
                  '<div class="list-num">' +
                  "<div>期号：" +
                  result[i].issue +
                  "</div>" +
                  "<div><span>" +
                  word +
                  "</span></div>" +
                  "</div>" +
                  '<div class="list-single-count">' +
                  '<div class="aui-ellipsis">' +
                  result[i].product_name +
                  "</div>" +
                  "<div>x"+result[i].number+"</div>" +
                  "</div>" +
                  "<div class='order-price-count'>"+
                  "<div class='order-product-price' style='color: #DD191B;' >价格：￥" +
                  result[i].price +
                  "</div>" +  
                  "<div class='order-product-count'>共<span>1</span>件商品</div>" +
                  "</div>"+ 
                  "</div>" +
                  "</div>" +
                  "</div>" +
                  "<div class='aui-ellipsis-2 order-product-desc '>商品描述：" +
                  result[i].product_desc +
                  "</div>" +
                  "</div>"
        		  
           /* '<div class="order-list-single">' +
              '<div class="list-num">' +
              "<div>期号：" +
              result[i].issue +
              "</div>" +
              "<div>" +
              word +
              "</div>" +
              "</div>" +
              '<div class="order-product-list" onclick="test(&quot;order-details.html&quot;)">' +
              '<div class="order-product-img">' +
              '<img src="' +
              result[i].product_image +
              '" />' +
              "</div>" +
              '<div class="order-product-con">' +
              '<div class="list-single-count">' +
              '<div class="aui-ellipsis">' +
              result[i].product_name +
              "</div>" +
              "<div>x"+result[i].number+"</div>" +
              "</div>" +
              "<div>￥" +
              result[i].price +
              "</div>" +
              "<div>共<span>1</span>件商品</div>" +
              "</div>" +
              "</div>" +
              "</div>"*/
          );
        }
      }
    }
  );
}

/**
 * 加载更多
 */
function getMore() {
  page++;
  _vp.pendingReview(
    {
      page: page,
      number: 10
    },
    function(res) {
      if (res.status == 2001) {
        //需要登录
        top.location.href = "login.html";
        page--;
        return;
      } else if (res.status == -1) {
        toast.fail({
          title: "系统繁忙",
          duration: 2000
        });
        page--;
        return;
      } else if (res.status == 1) {
        if (res.data.length == 0) {
          page--;
          return;
        }
        var ele = $(".product-con");
        var result = res.data.reverse();
        var i = result.length;
        while (i--) {
          var word;
          if (result[i].state == 1) {
            word = "待开奖";
          } else if (result[i].state == 2) {
            word = "已开奖";
          }
          ele.append(
            '<div class="order-list-single">' +
              '<div class="list-num">' +
              "<div>期号：" +
              result[i].issue +
              "</div>" +
              "<div>" +
              word +
              "</div>" +
              "</div>" +
              '<div class="order-product-list" onclick="test(&quot;order-details.html&quot;)">' +
              '<div class="order-product-img">' +
              '<img src="' +
              result[i].product_image +
              '" />' +
              "</div>" +
              '<div class="order-product-con">' +
              '<div class="order-product-display">'+
              '<div class="list-single-count">' +
              '<div class="aui-ellipsis">' +
              result[i].product_name +
              "</div>" +
              "<div>x1</div>" +
              "</div>" +
              "<div>价格：￥" +
              result[i].price +
              "</div>" +
              "<div>共<span>1</span>件商品</div>" +
              "</div>" +
              "</div>" +
              "</div>" +
              "</div>"
          );
        }
      }
    }
  );
}

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