index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const app = getApp()
  2. const httpUtils = require('../../utils/http.js')
  3. const ui = require('../../utils/ui.js')
  4. Page({
  5. data: {
  6. tab: 1,
  7. money: 100,
  8. deviceid: '',
  9. roomName: '',
  10. deviceCode: '',
  11. balance: ''
  12. },
  13. deviceid: '',
  14. roomName: '',
  15. deviceCode: '',
  16. balance: '',
  17. onLoad(options) {
  18. this.setData({
  19. deviceid: options.deviceid,
  20. roomName: options.roomName,
  21. deviceCode: options.deviceCode,
  22. balance: options.balance
  23. })
  24. this.deviceid = options.deviceid
  25. this.roomName = options.roomName
  26. this.deviceCode = options.deviceCode
  27. this.balance = options.balance
  28. },
  29. getInputName(e){
  30. this.setData({
  31. money: e.detail.value
  32. })
  33. },
  34. changeTab(e){
  35. console.log(e)
  36. this.setData({
  37. tab: e.target.dataset.info
  38. })
  39. if(e.target.dataset.info == 1){
  40. this.setData({
  41. money: 100
  42. })
  43. }else if(e.target.dataset.info == 2){
  44. this.setData({
  45. money: 200
  46. })
  47. }else if(e.target.dataset.info == 3){
  48. this.setData({
  49. money: 500
  50. })
  51. }
  52. },
  53. toRecharge(){
  54. let that = this
  55. let obj = {
  56. url: '/wePhoneCharge',
  57. data: {
  58. deviceId: that.deviceid,
  59. deposit: that.data.money,
  60. token: wx.getStorageSync('token'),
  61. }
  62. }
  63. httpUtils.request(obj).then(res=>{
  64. console.log("pay",res)
  65. let payInfo = res.data.data
  66. // 调取后端接口后微信下单
  67. wx.requestPayment({
  68. timeStamp:payInfo.timeStamp,
  69. nonceStr:payInfo.nonceStr,
  70. package:payInfo.package,
  71. signType:payInfo.signType,
  72. paySign:payInfo.paySign,
  73. success (res1) {
  74. console.log("支付",res1)
  75. if(res1.errMsg == 'requestPayment:ok'){
  76. wx.showToast({
  77. title: '支付成功!',
  78. icon: 'success',
  79. duration: 2000
  80. })
  81. wx.navigateTo({
  82. url: '/pages/record/index?deviceid=' + that.deviceid + '&roomName=' + that.roomName + '&deviceCode=' + that.deviceCode
  83. })
  84. }
  85. },
  86. fail (res1) {
  87. wx.showToast({
  88. title: '支付失败!',
  89. icon: 'error',
  90. duration: 2000
  91. })
  92. }
  93. })
  94. }).catch(err=>{
  95. console.log(err)
  96. wx.showToast({
  97. title: "创建订单失败!",
  98. icon: 'error',
  99. duration: 2000
  100. })
  101. });
  102. }
  103. })