balance _center2.js 4.0 KB
// pages/my/balance _center2/balance _center2.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */ 
  data: {
          imgUrl: app.globalData.imgUrl,
          state:1,
          flag:1,
          flags:-1,
          store:[],
          balance:[],
          bill:{}
  },
  //充值
  pay_pay_recharge(){
          let id=this.data.flag
          let url ='/wxapp/pay/recharge'
          let params={
                  id:id
          }
          app.post(url,params).then(r=>{
                  console.log(r)
                  wx.requestPayment({
                          timeStamp: r.data.jsApiParameters.timeStamp,
                          nonceStr: r.data.jsApiParameters.nonceStr,
                          package: r.data.jsApiParameters.package,
                          signType: r.data.jsApiParameters.signType,
                          paySign: r.data.jsApiParameters.paySign,
                          success(res) {
                                  console.log(res);
                                  this.fetchData();
                          },
                          fail(res) {
                                  console.log(res);
                          }
                  })
          })
  },
  //fetchData
  fetchData(){
          let url ='/wxapp/user/recharge';
          let flags=this.data.flags
          app.post(url).then(r=>{
                  console.log(r);
                  r.data.balanceList.forEach(function(ele,index){
                          ele.create_time = app.timeFormate(ele.create_time, 'YYMMDDHHMM');
                  });
                  if(flags==-1){
                          console.log('78')
                          this.setData({
                                  store: r.data.stored,
                                  bill: r.data.user,
                                  balance: r.data.balanceList,
                                    flag:r.data.stored[0].id
                          });
                  }else{
                          this.setData({
                                  store: r.data.stored,
                                  bill: r.data.user,
                                  balance: r.data.balanceList,
                                  flag: flags
                          });
                  }
          });
  },
  //修改changeFlag
        changeFlag1(e){
                let id=e.currentTarget.dataset.id;
                this.setData({
                        flag:id
                });
        },
        //点击充值协议
        jump_agreement(){
                wx.navigateTo({
                        url: '../agreement/agreement/agreement',
                })
        },
    
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
          console.log(options)
          if (options.id !='undefined') {
                  this.setData({
                          flags: options.id * 1
                  })
          }
          this.fetchData();
  },
  // 返回个人中心
  get_my(){
    wx.navigateBack({})
  },
  // 兑换码充值
  get_exchange() {
    wx.navigateTo({
      url: '../charger_code/charger_code',
    })
  },
  // 账单明细
  get_billing(){
    wx.navigateTo({
      url: '../balance _center/balance _center',
    })
  },
changeState1(){
        this.setData({
                state:1
        });
},
changeState2() {
        this.setData({
                state: 2
        });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

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

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

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

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

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

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