// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    type: '',
    record_title: '',
    activeName: '-1',
    title_api: '',
    list_api: '',
    rewardsData: {},
    recordsList: [],
    // more
    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.setData({
      type: options.name,
      record_title: options.reward_name
    });
    if (this.data.record_title) {
      wx.setNavigationBarTitle({
        title: this.data.record_title
      });
    }
    this.initData(this.data.type);
    this.getData();
    this.getRecord_title();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {},

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

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

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

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

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

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},
  initData(type) {
    switch (type) {
    case 'DirectReward':
      this.setData({
        title_api: 'plugin.nominate.frontend.prize-home.nominate-prize-home',
        list_api: 'plugin.nominate.frontend.prize-home.nominate-prize-list'
      });
      break;
    case 'PoorPrize':
      this.setData({
        title_api: 'plugin.nominate.frontend.prize-home.nominate-poor-prize-home',
        list_api: 'plugin.nominate.frontend.prize-home.nominate-poor-prize-list'
      });

      break;
    case 'TeamAward':
      this.setData({
        title_api: 'plugin.nominate.frontend.prize-home.team-prize-home',
        list_api: 'plugin.nominate.frontend.prize-home.team-prize-list'
      });
      break;
    case 'TeamPerformance':
      this.setData({
        title_api: 'plugin.nominate.frontend.prize-home.team-manage-prize-home',
        list_api: 'plugin.nominate.frontend.prize-home.team-manage-prize-list'
      });
      break;
    }
  },
  getRecord_title() {
    let urlStr = app.getNetAddresss(this.data.title_api);
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          this.setData({
            rewardsData: resdata.data
          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  getData() {
    this.setData({
      recordsList: [],
      isLoadMore: false,
      page: 1
    });
    let urlStr = app.getNetAddresss(this.data.list_api);
    urlStr += '&status=' + this.data.activeName + '&page=' + this.data.page;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          this.setData({
            isLoadMore: true,
            total_page: resdata.data.last_page
          });
          if (!this.data.total_page) {
            this.setData({
              total_page: 0
            });
          }
          this.setData({
            recordsList: resdata.data.list.data
          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  handleClick(val) {
    if (val.detail.index == 0) {
      this.setData({
        activeName: '-1'
      });
    } else if (val.detail.index == 1) {
      this.setData({
        activeName: '1'
      });
    } else if (val.detail.index == 2) {
      this.setData({
        activeName: '0'
      });
    } else if (val.detail.index == 3) {
      this.setData({
        activeName: '2'
      });
    }
    // 获取数据
    this.getData();
  }

});
