index.js 5.93 KB
// packageIndex/pages/integral/index/index.js

let navBarHeight = 38
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nothing: false,
    triggered: true,
    isFlag: true,
    scoreSummary: {
      currentScore: '', //当前积分
      bankCardSize: '',
      totalGoodExchangeScore: '', //累计兑换积分
      totalRewardScore: '', //累计收益积分
      totalWithdrawalScore: '', //累计提现积分
    },
    open: false,
    staffBankFlag: false,
    showAccountModal: false,
    pageSize: 10,
    pageNum: 1,
    total: 0,
    scoreList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    if (options.scene === 1047) { // 1047 表示从另一个小程序跳转过来的场景值
      console.log('extraData:', options.referrerInfo.extraData);
      if (options.referrerInfo.extraData && options.referrerInfo.extraData.external) {
        this.loginOut()
      }

    }
    let userInfo = wx.p.storage.get('userInfo');
    this.setData({
      userInfo
    })
    //是否开通
    await this.getPointsWalletData()
    this.searchScoreSummaryData()
    this.getScoreProfitListData()
  },
  loginOut() {
    wx.p.storage.rm('sessionId')
    wx.p.isLogin = false
    wx.p.storage.rm('userInfo')
    wx.p.router.reLaunch('/pages/Login/Login')
  },
  getPointsWalletData() {
    const {
      phone,
      nickName,
      channelSource
    } = this.data.userInfo;

    wx.p.api.common.getPointsWalletData({
      name: nickName,
      phone,
      scoreSource: channelSource //1.阳光激励 2.续保用户 3.管理层
    }).then(res => {
      if (res.code == 0) {
        this.setData({
          open: res.data ? true : false,
          isFlag: true
        })
      }

    }).catch((err) => {
      wx.p.wxApi.showToast(JSON.stringify(err))
    })
  },
  open() {
    const {
      userInfo: {
        phone,
        channelSource,
        nickName
      },
      scoreSummary: {
        currentScore
      }
    } = this.data;
    this.setData({
      showEnableWallet: true,
      walletObj: {
        "name": nickName,
        phone,
        "scoreSource": channelSource,
        currentScore
      }
    })
  },
  //更新开通状态
  update() {
    this.getPointsWalletData()
  },
  jump() {
    wx.p.router.go('/packageIndex/pages/integral/withdrawalNote/withdrawalNote')
  },
  searchScoreSummaryData() {
    const {
      userInfo: {
        phone,
        channelSource,
        merchantId
      }

    } = this.data;
    let params = {
      staffPhone: phone,
      channelSource, //1.阳光激励 2.续保用户 3.管理层
      merchantId
    }
    wx.p.api.withdrawalApi.searchScoreSummary(params).then(res => {
      if (res.code == 0) {
        this.setData({
          scoreSummary: res.data,
          staffBankFlag: !res.data.bankCardSize
        })
      } else {
        wx.p.sentry.reportError(`积分中心异常:${res.message}`, {
          ...params,
          res
        });
      }

    }).catch((err) => {
      wx.p.wxApi.showToast(JSON.stringify(err))
      wx.p.sentry.reportError(`积分中心异常:${err}`, {
        ...params,
        err
      });
    })
  },
  getScoreProfitListData(isFlag) {
    let {
      pageNum,
      total,
      pageSize,
      scoreList,
      userInfo: {
        phone,
        channelSource,
        merchantId
      }
    } = this.data;
    if(isFlag) pageNum=1
    wx.p.api.withdrawalApi.getScoreProfitList({
      staffPhone: phone,
      merchantId,
      channelSource,
      pageSize,
      pageNum
    }).then(res => {
      let data, tempList;
      if (res.code == 0) {
        data = res.data?.list ? res.data?.list : []
        tempList =[...scoreList, ...data];
        this.setData({
          pageNum,
          scoreList: pageNum == 1 ? data : tempList,
          total: res.data.total,
          triggered: false,
          nothing: res.data.total == tempList.length,
        })
      }

    }).catch((err) => {
      wx.p.wxApi.showToast(JSON.stringify(err))
    })
  },
  scrollonReachBottom() {
    console.log(222)
    let {
      total,
      scoreList,
      pageNum
    } = this.data;
    if (total > scoreList.length) {
      this.setData({
        pageNum: pageNum + 1,
      })
      this.getScoreProfitListData()
    } else {

    }

  },
  toBank() {
    const {
      currentScore,
    } = this.data.scoreSummary;
    wx.p.router.go('/packageIndex/pages/bankAccount/list/list', {
      score: currentScore
    })
  },
  hidePopup() {
    this.setData({
      showAccountModal: false
    })
  },
  navbarReady(e) {
    let {
      height
    } = e.detail
    this.setData({
      navHeight: height
    })
  },
  /**跳转至银行卡 */
  toAddBankAccount(e) {
    const {
      currentScore,
    } = this.data.scoreSummary;
    this.setData({
      showAccountModal: false
    }, () => {
      wx.p.router.go('/packageIndex/pages/bankAccount/add/add', {
        score: currentScore
      })
    })
  },
  toCash() {
    const {
      currentScore,
    } = this.data.scoreSummary, {
      staffBankFlag
    } = this.data;
    if (staffBankFlag) {
      this.setData({
        showAccountModal: true
      })
      return
    }

    wx.p.router.go('/packageIndex/pages/integral/withdrawal/withdrawal', {
      score: currentScore
    })
  },
  back() {
    wx.p.router.back()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.refresh) {
      this.searchScoreSummaryData()
      this.getScoreProfitListData(true)
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.refresh = true;
  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})