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

let navBarHeight = 38
Page({

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

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let userInfo = wx.p.storage.get('userInfo');
    this.setData({
      userInfo
    })
    //是否开通
    await this.getPointsWalletData()
    this.searchScoreSummaryData()
    this.getScoreProfitListData()
  },
  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;
    wx.p.api.withdrawalApi.searchScoreSummary({
      staffPhone: phone,
      channelSource, //1.阳光激励 2.续保用户 3.管理层
      merchantId
    }).then(res => {
      if (res.code == 0) {
        this.setData({
          scoreSummary: res.data,
          staffBankFlag: !res.data.bankCardSize
        })
      }

    }).catch((err) => {
      wx.p.wxApi.showToast(JSON.stringify(err))
    })
  },
  getScoreProfitListData() {
    let {
      pageNum,
      total,
      pageSize,
      scoreList,
      userInfo:{
        phone,
        channelSource,
        merchantId
      }
    } = this.data;
    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({
          scoreList: pageNum == 1 ? data : tempList,
          total: res.data.total,
          triggered: false,
          nothing: res.data.total == tempList.length,
        })
      }

    }).catcn((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() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})