// pages/ticketCenter/ticketCenter.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    chooseWhich:1,
    dataList:[],//需要展示的数据
    newData:[],
    pageNum:1,//页码，
    count:10,//每页条数
    total:0,//总条数
    total_page:0,//总页数
    scrollHig:0,
    type:"",
    hotType:2,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.globalData.openId){
      this.getDataList();
    }else{
      app.globalData.openidSuccessFuc = this.getDataList;
    }
console.log(wx.getSystemInfoSync().windowHeight)
    this.setData({
      scrollHig: wx.getSystemInfoSync().windowHeight-44-12,
    });
  },
  getDataList:function(type,hotType){
    if(type || hotType){
      this.data.type = type
      this.data.hotType = hotType
    }else{
      this.data.type = ""
      this.data.hotType = 2
    }
    let params = {
      list_type:2,
      cur_page:this.data.pageNum,
      show_num:this.data.count,
      item_type:this.data.type,
      item_state:1,
      hot_state:this.data.hotType
    }
    app.wxRequest(app.globalData.httpUrl + 'front/sell/listing', params, e => {
      console.log(e)
      if (e.code == 200) {
        for(var i=0;i<e.data.length;i++){
          this.data.newData.push(e.data[i]);
        }
        this.setData({
          dataList:this.data.newData
        })
        this.data.total_page = e.total_page;
      }
    }, this)
  },
  getBot:function(){//scroll触底事件
    if(this.data.pageNum<this.data.total_page){
      this.data.pageNum++;
      this.getDataList();
    }else{
      wx.showToast({
        title: '没有更多数据了',
        icon:"none"
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  chooseFn: function(e){//选择
    this.setData({
      chooseWhich:e.currentTarget.dataset.index
    })
    console.log(this.data.chooseWhich)
    if(this.data.chooseWhich==1){
      this.data.type = "";
      this.data.hotType = 2;
    }else{
      this.data.type = this.data.chooseWhich-1;
      this.data.hotType = "";
    }
    this.data.pageNum = 1;
    this.data.dataList = [];
    this.data.newData = [];
    this.getDataList(this.data.type,this.data.hotType);
  },
  
  skipPage:function(e){//跳转到购买页面
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    console.log(e)
    wx.navigateTo({
      url: '../buyTicket/buyTicket?id=' + id+"&type="+type
    })
  },
})