buy-card.js 3.9 KB

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