var app= getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    moneys:[

    ],
    moneynum:'',
  },

    //充值
    pay_list:function(e){
        var that = this;
       
        //获取money
        that.setData({
            moneynum:e.currentTarget.dataset.id,
            
        })

        wx.request({
            url: app.globalData.hostname +'orderRecharge',
            data:{
                user_id: wx.getStorageSync('openid'),
                pay_id: that.data.moneynum
            },
            success:(res)=>{
                console.log(res.data.code);
                if(res.data.code ==200){
                    wx.request({
                        url: app.globalData.hostname + 'payRecharge',
                        data: { order_num: res.data.order_sn },
                        header: {},
                        method: 'GET',
                        dataType: '',
                        success: function (res) {
                            console.log(res, '支付');
                            wx.requestPayment({
                                'timeStamp': res.data.timeStamp,
                                'nonceStr': res.data.nonceStr,
                                'package': res.data.package,
                                'signType': 'MD5',
                                'paySign': res.data.paySign,
                                'success': function (res) {
                                    console.log(res);
                                    var openid = wx.getStorageSync("openid");
                                    // var page = 1, typekind = that.data.tabIndex;
                                    wx.showToast({
                                        title: '支付成功',
                                        icon: 'success',
                                        image: '',
                                        duration: 1000,
                                        mask: true,
                                        success: function (res) {
                                            setTimeout(function () {
                                                that.setData({
                                                    page: 1,
                                                    hasMore: true,
                                                    orderList: [],
                                                })
                                                that.getOrderList(that)
                                                // that.getOrderList(that, openid, page, that.data.size, typekind)
                                            }, 1000)
                                        },
                                    })
                                },
                            })
                        },
                    })
                }
            }
        })
        
    },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;

      //rechange
    wx.request({
        url: app.globalData.hostname +'recharge_list',
        data:{},
        success:(res)=>{
            console.log(res);
            that.setData({
                moneys:res.data.data
            })
        }
        
    })


      //被分享者 点击拿到分享着的share_id
        var share_id = options.userid;
        //更新数据
        that.setData({
            userInfo: wx.getStorageSync('userInfo'),
        })
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

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

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

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

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

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

  /**
           * 用户点击右上角分享
           */
  onShareAppMessage: function (res) {
      var userid = app.globalData.userId;
      console.log(userid);
      if (res.from === 'button') {
          // 来自页面内转发按钮
          console.log(res.target)
      }
      return {
          title: '汽车美容案例',
          path: '/pages/home_page/home_page?userid=' + userid,
          success: function (res) {
              var pages = getCurrentPages()    //获取加载的页面

              var currentPage = pages[pages.length - 1]    //获取当前页面的对象

              //点击分享传进userid 截取userid 从onload拿到
              var url = currentPage.route + '?userid=' + userid;  //当前页面url

              console.log(url);

          },
          fail: function (res) {
              // 转发失败
          }
      }
  }
})