buy-card.js 4.0 KB

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