var app = getApp();
const util = require('../../utils/utils.js')
Page({
  data: {
    detail:[],
    order_no:''
  },
  onLoad: function (options) {
    console.log(options)
    wx.showLoading({
      title: '加载中...',
      mask:true
    })
    app.request('/punishment_order?no='+options.no, '', 'GET').then(res => {
      if (res.statusCode == 200) {
        console.log(res)
        // this.data.detail = res.data
        this.setData({detail:res.data,order_no:options.no})
      }
      wx.hideLoading({
        complete: (res) => {},
      })
    })
  },
  pay:util.throttle(function() {
    var data = {
      no:this.data.order_no
    }
      app.request('/punishment_order/pay', data, 'POST').then(res => {
        if (res.statusCode == 200) {
          console.log(res)
          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.showToast({
                title: '支付成功',
                success:function(){
                  wx.navigateBack()
                }
              })
            },
            fail(err) {
              console.log(err)
              wx.showToast({
                title: '支付失败',
                icon: 'none'
              })
            }
          })
        }
      })
  },2000),
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  }
})