// packageB/member/love/lovePerformance/lovePerformance.js
var app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    language: "",
    activeName: "first",
    recordsList: [],
    dataInfo: {},
    love_name: "",

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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData(); // 初始化数据
  },
  checkrouter() {
    try {
      // 推广中心是否开启该功能，没开启跳转到指定路径
      let basic_info = wx.getStorageSync("yz_basic_info");
      let stop_info = basic_info.popularize_page.mini.vue_route;
      for (let i = 0; i < stop_info.length; i++) {
        if (stop_info[i] == "lovePerformance") {
          console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");

          wx.showToast({
            title: "未开启推广权限",
            duration: 1000,
            icon: "none",
            success: function () {
              setTimeout(() => {
                wx.redirectTo({
                  url: basic_info.popularize_page.mini.mini_url,
                });
              }, 1000);
            },
          });
          return;
        }
      }
    } catch (e) {
      console.log(e);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({ language: language.en });
  },

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

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

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isLoadMore) {
      this.getMoreData();
    } else {
      console.log("没有更多了");
    }
  },

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

  getData() {
    let urlStr = app.getNetAddresss("plugin.love-team.frontend.log.index");
    urlStr += "&page=1";
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var response = resdata.data;
        if (response.result == 1) {
          this.setData({
            dataInfo: response.data,
            love_name: response.data.love_name,
            isLoadMore: true,
            total_page: response.data.list.last_page,
            recordsList: response.data.list.data,
          });
          wx.setNavigationBarTitle({
            title: this.data.love_name + "团队奖励记录",
          });
        } else {
          wx.showToast({
            title: response.msg,
            icon: "none",
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  getMoreData() {
    this.setData({
      isLoadMore: false,
    });
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      this.setData({
        page: this.data.page + 1,
      });
      let urlStr = app.getNetAddresss("plugin.love-team.frontend.log.index");
      urlStr += "&page=" + this.data.page;
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var response = resdata.data;
          if (response.result == 1) {
            this.setData({
              isLoadMore: true,
              recordsList: this.data.recordsList.concat(
                response.data.list.data
              ),
            });
          } else {
            wx.showToast({
              title: response.msg,
              icon: "none",
            });
            this.setData({
              page: this.data.page - 1,
              isLoadMore: false,
            });
          }
        },
        fail: function (res) {
          console.log(res);
        },
      });
    }
  },
});
