index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. openId: wx.getStorageSync('openId'),
  62. }
  63. }
  64. httpUtils.request(obj).then(res=>{
  65. console.log("pay",res)
  66. let payInfo = res.data.data
  67. // 调取后端接口后微信下单
  68. wx.requestPayment({
  69. timeStamp:payInfo.timeStamp,
  70. nonceStr:payInfo.nonceStr,
  71. package:payInfo.package,
  72. signType:payInfo.signType,
  73. paySign:payInfo.paySign,
  74. success (res1) {
  75. console.log("支付",res1)
  76. if(res1.errMsg == 'requestPayment:ok'){
  77. wx.showToast({
  78. title: '支付成功!',
  79. icon: 'success',
  80. duration: 2000
  81. })
  82. wx.navigateTo({
  83. url: '/pages/record/index?deviceid=' + that.deviceid + '&roomName=' + that.roomName + '&deviceCode=' + that.deviceCode
  84. })
  85. }
  86. },
  87. fail (res1) {
  88. wx.showToast({
  89. title: '支付失败!',
  90. icon: 'error',
  91. duration: 2000
  92. })
  93. }
  94. })
  95. }).catch(err=>{
  96. console.log(err)
  97. wx.showToast({
  98. title: "创建订单失败!",
  99. icon: 'error',
  100. duration: 2000
  101. })
  102. });
  103. }
  104. })