// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
// const URL_MEMBER = 'plugin.mryt.api.home.get-member-list';
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    active: 0,
    type: '',
    rewardsData: {},
    recordsList: [],
    activeName: '-1',
    WXtitle: '',
    api: '',
    listApi: '',

    // more
    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.setData({
      type: options.name,
      WXtitle: options.reward_name
    });
    if (this.data.WXtitle) {
      wx.setNavigationBarTitle({
        title: this.data.WXtitle
      });
    }
    if (this.options.fromHome == 1) { // 保持原来状态
      this.initData(this.data.type);
      this.getIndex();
      this.getData();
    }
  },

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

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

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

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

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

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

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},
  toDetail(item) {
    let items = item.currentTarget.dataset.item || item.target.dataset.item;
    wx.navigateTo({
      url: '/packageB/member/enterprise/AwardDetail/AwardDetail' + '?name=' + this.data.type + '&id=' + items.id
    });
  },
  getTab(tab) {
    // 赋值
    if (tab.detail.index == 0) {
      this.setData({
        activeName: '-1'
      });
    } else if (tab.detail.index == 1) {
      this.setData({
        activeName: '1'
      });
    } else if (tab.detail.index == 2) {
      this.setData({
        activeName: '0'
      });
    }
    this.getData();
  },
  initData(type) {
    switch (type) {
    case 'teamManagement':
      this.setData({
        api: 'plugin.mryt.api.team-manage.index',
        listApi: 'plugin.mryt.api.team-manage.getList'
      });
      break;
    case 'team':
      this.setData({
        api: 'plugin.mryt.api.team.index',
        listApi: 'plugin.mryt.api.team.getList'
      });
      break;
    case 'thanks':
      this.setData({
        api: 'plugin.mryt.api.thanksgiver.index',
        listApi: 'plugin.mryt.api.thanksgiver.getList'
      });
      break;
    case 'education':
      this.setData({
        api: 'plugin.mryt.api.train.index',
        listApi: 'plugin.mryt.api.train.getList'
      });
      break;
    case 'immediate':
      this.setData({
        api: 'plugin.mryt.api.direct-award.index',
        listApi: 'plugin.mryt.api.direct-award.getList'
      });
      break;
    case 'tier':
      this.setData({
        api: 'plugin.mryt.api.tier.index',
        listApi: 'plugin.mryt.api.tier.getList'
      });
      break;
    default:
      this.setData({
        WXtitle: '奖励记录'
      });
      break;
    }
  },
  getIndex() {
    let urlStr = app.getNetAddresss(this.data.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() {
    let urlStr = app.getNetAddresss(this.data.listApi);
    urlStr += '&status=' + this.data.activeName;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          this.setData({
            recordsList: resdata.data.data,
            total_page: resdata.data.last_page,
            isLoadMore: true

          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  }

});
