 var app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    focus:true,
    inputValue:"",
    g: false
  },
  bindKeyInput: function (e) {
    let inputValue= e.detail.value;
    //   console.log(e.detail.value);
      this.setData({
          inputValue
      })
      if (inputValue){
        this.setData({
          g: true
        })
      }else{
        this.setData({
          g: false
        })
      }
  },
  geiqian:function(){
         let geiqian = this.data.inputValue,
             that = this,
             openid = wx.getStorageSync("realOpenid"),
             user_id = wx.getStorageSync("openid");
         console.log(geiqian);
         if (Number(geiqian)<=0){
           wx.showToast({
             title: '付款金额错误',
             icon: 'none',
             duration: 2000
           })
           return;
         }
        
      //  生成订单
         wx.request({
           url: app.globalData.hostname +'orderDirect',
             data: {
                 user_id,
                 price: geiqian
             },
             success: function (res) {
                 if(res.data.code==200){
                   //发起支付
                   wx.request({
                     url: app.globalData.hostname + 'payDirect',
                     data: {
                       order_num: res.data.order_sn
                     },
                     success(res){
                      //  console.log(res.data)
                        // 得到支付需要的字段发起支付
                        wx.requestPayment({
                          timeStamp: res.data.timeStamp,
                          nonceStr: res.data.nonceStr,
                          package: res.data.package,
                          signType: res.data.signType,
                          paySign: res.data.paySign,
                          success(res){
                            console.log(res)
                          }
                        })
                     }
                 })
             }  }
         })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      more_info: wx.getStorageSync('more_info')
    })
    
  },

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

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

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

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

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

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

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