buy-card.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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('骑行卡数据',res.data.data.shift())
  37. console.log(arr1)
  38. console.log(res.data.data)
  39. that.setData({
  40. hotInfo: arr1,
  41. arr: res.data.data,
  42. hot: true,
  43. infoDetail: arr1,
  44. id:arr1.id
  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 (my.getStorageSync({ 'key': 'home' }).data) {
  79. area_id = my.getStorageSync({ 'key': 'home' }).data.id
  80. } else {
  81. my.showToast({
  82. content: '当前地区暂无运营区域',
  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.status == 200) {
  95. that.setData({
  96. no: res.data.no
  97. })
  98. my.tradePay({
  99. tradeNO: res.data.tradeNo,
  100. success: function (res) {
  101. if (res.resultCode == 9000) {
  102. my.showToast({
  103. content: '购买成功,请用车',
  104. icon: 'none',
  105. mask: true,
  106. success: function () {
  107. my.reLaunch({
  108. url: '/pages/index/index',
  109. })
  110. }
  111. })
  112. } else {
  113. return
  114. }
  115. },
  116. fail(err) {
  117. console.log(err)
  118. // my.showToast({
  119. // content: '支付失败',
  120. // icon: 'none'
  121. // })
  122. // var data = {
  123. // no: that.data.no
  124. // }
  125. // app.request("/card_riding/no_pay", data, "POST").then(res => {
  126. // console.log(res)
  127. // })
  128. }
  129. })
  130. }
  131. })
  132. } else {
  133. my.showToast({
  134. content: '您的操作过于频繁,请稍后再试~',
  135. icon: 'none'
  136. })
  137. }
  138. }, 1000),
  139. //选择卡
  140. changeCard: function (e) {
  141. console.log(e.currentTarget.dataset.id.id)
  142. this.setData({
  143. id: e.currentTarget.dataset.id.id,
  144. // info: true,
  145. infoDetail: e.currentTarget.dataset.id,
  146. currentCard: e.currentTarget.dataset.id.id
  147. }
  148. )
  149. },
  150. buyButtom: function () {
  151. this.setData({
  152. info: true,
  153. })
  154. },
  155. onReady: function () {
  156. },
  157. onShow: function () {
  158. },
  159. onHide: function () {
  160. },
  161. onUnload: function () {
  162. },
  163. onPullDownRefresh: function () {
  164. },
  165. onReachBottom: function () {
  166. },
  167. onShareAppMessage: function () {
  168. }
  169. })