recharge.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var app = getApp();
  2. const util = require('../../utils/utils.js');
  3. Page({
  4. data: {
  5. hot: false,
  6. index1: null,
  7. money: '',
  8. arr: [],
  9. info: false,
  10. id: '',
  11. no: '',
  12. infoDetail: [],
  13. hotInfo: []
  14. },
  15. onLoad: function (options) {
  16. var that = this;
  17. var area_id = ''
  18. wx.showLoading({
  19. title: '加载中...',
  20. })
  21. // if (wx.getStorageSync('home').id != undefined) {
  22. // area_id = wx.getStorageSync('home').id
  23. // }
  24. var data = {
  25. 'area_id': 1
  26. }
  27. app.request("/card_riding/index", data, "GET").then(res => {
  28. console.log(res)
  29. wx.hideLoading()
  30. if (res.data.data == '') {
  31. return;
  32. }
  33. var arr = res.data.data.shift()
  34. console.log(arr)
  35. that.setData({
  36. hotInfo: arr,
  37. arr: res.data.data,
  38. hot: true
  39. })
  40. }).catch(err => {
  41. console.log(err)
  42. })
  43. },
  44. background: function () {
  45. this.setData({
  46. info: false
  47. })
  48. },
  49. buy: function (e) {
  50. var id = e.currentTarget.dataset.id;
  51. var index = e.currentTarget.dataset.index;
  52. var arr = this.data.arr;
  53. this.setData({
  54. id,
  55. info: true,
  56. infoDetail: arr[index]
  57. })
  58. },
  59. buy1: function () {
  60. this.setData({
  61. id: this.data.hotInfo.id,
  62. info: true,
  63. infoDetail: this.data.hotInfo
  64. })
  65. },
  66. form: util.throttle(function () {
  67. var that = this;
  68. that.setData({
  69. info: false
  70. })
  71. var area_id = ''
  72. if (wx.getStorageSync('home').id != undefined) {
  73. area_id = wx.getStorageSync('home').id
  74. } else {
  75. wx.showToast({
  76. title: '当前地区暂无运营区域',
  77. icon: 'none'
  78. })
  79. return;
  80. }
  81. if (app.globalData.req) {
  82. var data = {
  83. 'card_riding_id': that.data.id,
  84. 'area_id': area_id
  85. }
  86. app.request("/card_riding/pay", data, "POST", app.globalData.req).then(res => {
  87. console.log(res)
  88. if (res.statusCode == 200) {
  89. that.setData({
  90. no: res.data.no
  91. })
  92. wx.requestPayment({
  93. timeStamp: res.data.timeStamp.toString(),
  94. nonceStr: res.data.nonceStr,
  95. package: res.data.package,
  96. signType: res.data.signType,
  97. paySign: res.data.paySign,
  98. success(resp) {
  99. console.log(resp)
  100. wx.showToast({
  101. title: '购买成功,请用车',
  102. icon: 'none',
  103. mask: true,
  104. success: function () {
  105. if(app.globalData.compatible){
  106. wx.reLaunch({
  107. url: '/pages/compatible/index/index',
  108. })
  109. }else{
  110. wx.reLaunch({
  111. url: '/pages/index/index',
  112. })
  113. }
  114. }
  115. })
  116. },
  117. fail(err) {
  118. console.log(err)
  119. wx.showToast({
  120. title: '支付失败',
  121. icon: 'none'
  122. })
  123. var data = {
  124. no: that.data.no
  125. }
  126. app.request("/card_riding/no_pay", data, "POST").then(res => {
  127. console.log(res)
  128. })
  129. }
  130. })
  131. }
  132. })
  133. } else {
  134. wx.showToast({
  135. title: '您的操作过于频繁,请稍后再试~',
  136. icon: 'none'
  137. })
  138. }
  139. }, 1000),
  140. onReady: function () {
  141. },
  142. onShow: function () {
  143. },
  144. onHide: function () {
  145. },
  146. onUnload: function () {
  147. },
  148. onPullDownRefresh: function () {
  149. },
  150. onReachBottom: function () {
  151. },
  152. onShareAppMessage: function () {
  153. }
  154. })