沙盘演示系统应用的微信小程序
zuoxiao
2024-11-04 232b383c629ac75dbf1bb780a63239b6f57d5071
pages/rechargeMoney/rechargMoney.js
@@ -23,6 +23,7 @@
    pageSize: 20, //充值记录每页记录数
    loading: false, //是否正在加载
    hasMore: true,
    moneyList:[]//充值金额
  },
  /**
@@ -38,7 +39,8 @@
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getRechargList()
    this.getRechargList();
    this. getMorneyList();
  },
  /**
@@ -67,9 +69,9 @@
   */
  onPullDownRefresh() {
    this.setData({
      pageCurr: 1
      pageCurr: 1,
    })
    this.getRechargList()
    this.getRechargList(true)
  },
  /**
@@ -103,7 +105,7 @@
    const data = {
      sessionId: getApp().globalData.sessionId,
      vcId: this.data.vcId, //虚拟卡ID
      rechargeAmount: 1 //(单位是分)
      rechargeAmount: this.data.moneyList[this.data.activeIndex]//(单位是分)
    };
    console.log("postCloseValaue" + data);
    post({
@@ -136,7 +138,13 @@
        signType: data.content.signType,
        paySign: data.content.paySign,
        success(res) {
          wx.showToast({
            title: "充值成功",
            icon: 'success',
            duration: 3000
          })
          console.log('支付成功', res);
          this. getRechargList(true);
        },
        fail(err) {
          console.log('支付失败', err);
@@ -151,7 +159,7 @@
    });
  },
  //获取充值记录
  getRechargList() {
  getRechargList(isRefresh) {
    const params = {
      url: 'wx/virtual_card/getVcRechargeRecords',
      data: {
@@ -162,10 +170,10 @@
    };
    get(params).then(data => {
      this.setData({
        allRechargeList:this.data.allRechargeList.concat( data.content.obj),
        allRechargeList: isRefresh ? data.content.obj : this.data.allRechargeList.concat(data.content.obj),
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        loading: false,
        hasMore: !data.content.obj.pageTotal === this.data.pageCurr
        hasMore: this.data.pageCurr < data.content.pageTotal
      })
      this.updateDisplayText();
    }).catch(err => {
@@ -181,12 +189,7 @@
      })
    });
  },
  // 生成支付签名的函数
  generatePaySign(params) {
    const sortedKeys = Object.keys(params).sort();
    const stringToSign = sortedKeys.map(key => `${key}=${params[key]}`).join('&') + `&key=your-mch-key`;
    return md5(stringToSign).toUpperCase();
  },
  //加载更多
  loadMore() {
    if (this.data.hasMore && !this.data.loading) {
@@ -209,5 +212,24 @@
    this.setData({
      allRechargeList: updatedList
    });
  },
  //获取金额
  getMorneyList(){
    const params = {
      url: 'wx/virtual_card/gerRechargeProfiles'
    };
    get(params).then(data => {
      this.setData({
        moneyList:  data.content ,
      })
      this.updateDisplayText();
    }).catch(err => {
      // 错误回调
      wx.showToast({
        title: err.msg,
        icon: 'error',
        duration: 3000
      })
    });
  }
})