// packageE/extension/dealer_award/peerAward/peerAward.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    activeName: 0,
    loading: false,
    dataList: [
      {
        level: {},
        statistics: {},
        isLoadMore: true,
        total_page: null,
        page: 1,
        list: [],
      },
      {
        level: {},
        statistics: {},
        isLoadMore: true,
        total_page: null,
        page: 1,
        list: [],
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData({ detail: { index: this.data.activeName } });
  },

  //发起http请求
  getData(_tag) {
    let tag = _tag.detail.index;
    let that = this;
    this.setData({
      loading: true,
    });
    let urlStr = app.getNetAddresss(
      "plugin.team-sideways.frontend.center.index"
    );
    urlStr += "&award_type=" + tag;
    urlStr += "&page=1";
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result === 1) {
          let dataList = that.data.dataList;
          dataList[tag].level = res.data.data.level;
          dataList[tag].statistics = res.data.data.statistics;

          dataList[tag].isLoadMore = true;
          dataList[tag].total_page = res.data.data.list.last_page;
          if (!res.data.data.list.last_page) {
            dataList[tag].total_page = 0;
          }
          dataList[tag].list = res.data.data.list.data;
          that.setData({
            dataList: dataList,
            activeName: tag,
            loading: false,
          });
          console.log(dataList);
        } else {
          that.setData({
            loading: false,
          });
          wx.showToast({
            title: res.data.msg,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  // 跳转到提现
  teamCode() {
    wx.navigateTo({
      url:
        "/packageE/extension/dealer_award/peerAwardes_withdraw/peerAwardes_withdraw",
    });
  },

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

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

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

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.dataList[this.data.activeName].isLoadMore) {
      this.getData({ detail: { index: this.data.activeName } });
    } else {
      wx.showToast({
        title: "没有更多数据",
        icon: "none",
      });
    }
  },

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