var app = getApp();
const util = require('../../utils/utils.js')
Page({
  data: {
    show:false,
    date:[],
    code:'',
    img:app.globalData.imgUrl
  },
  onLoad: function (options) {
    this.setData({date:wx.getStorageSync('setting'),code:options.code})
    wx.setNavigationBarTitle({
      title: app.globalData.title 
    })
  },
  btn: util.throttle(function(){
    this.setData({show:true})
  },1000),
  over:util.throttle(function(){
    this.setData({ show: false })
  },1000),
  pay: util.throttle(function () {
    var that = this;
    wx.getLocation({
      success: function (res) {
        console.log(res)
        if (app.globalData.req) {
          var data = {
            'type': 'D',
            'bike_no': that.data.code,
            'area_id': wx.getStorageSync('home').id,
            'lat': res.latitude,
            'lng': res.longitude
          }
          app.request('/rent/store-order', data, 'POST', app.globalData.req).then(res => {
            console.log(res)
            if (res.statusCode == 200) {
              if (res.data.nonceStr == undefined) {
                wx.reLaunch({
                  url: '/pages/daily_riding/daily_riding?order=' + res.data.no,
                })
              } else {
                wx.requestPayment({
                  timeStamp: res.data.timeStamp.toString(),
                  nonceStr: res.data.nonceStr,
                  package: res.data.package,
                  signType: res.data.signType,
                  paySign: res.data.paySign,
                  success(resp) {
                    console.log(resp)
                    wx.reLaunch({
                      url: '/pages/daily_riding/daily_riding?order=' + res.data.no,
                    })
                  },
                  fail(err) {
                    console.log(err)
                    wx.showToast({
                      title: '支付失败',
                      icon: 'none'
                    })
                  }
                })
              }
            }
          })
        } else {
          wx.showToast({
            title: '您的操作过于频繁，请稍后再试~',
            icon: 'none'
          })
        }

      },
    })
  }, 1000),
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {
    
  }
})