// subPackage/page/pages/myInviteRecords/myInviteRecords.js
const app = getApp()
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    inviteMemberList : [],
    pageNo : 1,
    pageSize : 50,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu();
    this.getInviteMemberList();
  },

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

  },

  // 邀请会员列表
  getInviteMemberList(isRefreesh) {
    const { memberId } = wx.getStorageSync('_baseUserInfo')
    let params = {
      userId: memberId,
      tentacleType: 3
    }
    wx.showLoading({
      title: '加载中',
      mask: true
    });
    let pageSize = this.data.pageSize;
    let pageNo = this.data.pageNo;
    wxService.post(`/member/share/inviteFriends/buyer/findPage?pageNo=${pageNo}&pageSize=${pageSize}`, params).then(res => {
      if (res) {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading();
          this.setData({
            inviteMemberList: data
          })
        }
      }

      if(isRefreesh){
        wx.stopPullDownRefresh();
        wx.showToast({
          title: '刷新成功',
        });
      }

    })
  },

  //跳转到我的收益界面
  ontapToMyBenifit(e){
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/subPackage/page/pages/orderBenefit/orderBenefit?type=10&id=' + item.memberId,
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.pageNo = 1;
    this.data.inviteMemberList = [];
    this.getInviteMemberList(true);
  },

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

  },

})