recharge.js 3.7 KB

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