buy-card.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.id != undefined) {
  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. my.showToast({
  99. content: '购买成功,请用车',
  100. icon: 'none',
  101. mask: true,
  102. success: function () {
  103. my.reLaunch({
  104. url: '/pages/index/index',
  105. })
  106. }
  107. })
  108. },
  109. fail(err) {
  110. console.log(err)
  111. // my.showToast({
  112. // content: '支付失败',
  113. // icon: 'none'
  114. // })
  115. // var data = {
  116. // no: that.data.no
  117. // }
  118. // app.request("/card_riding/no_pay", data, "POST").then(res => {
  119. // console.log(res)
  120. // })
  121. }
  122. })
  123. }
  124. })
  125. } else {
  126. my.showToast({
  127. content: '您的操作过于频繁,请稍后再试~',
  128. icon: 'none'
  129. })
  130. }
  131. }, 1000),
  132. //选择卡
  133. changeCard: function (e) {
  134. console.log(e.currentTarget.dataset.id.id)
  135. this.setData({
  136. id: e.currentTarget.dataset.id.id,
  137. // info: true,
  138. infoDetail: e.currentTarget.dataset.id,
  139. currentCard: e.currentTarget.dataset.id.id
  140. }
  141. )
  142. },
  143. buyButtom: function () {
  144. this.setData({
  145. info: true,
  146. })
  147. },
  148. onReady: function () {
  149. },
  150. onShow: function () {
  151. },
  152. onHide: function () {
  153. },
  154. onUnload: function () {
  155. },
  156. onPullDownRefresh: function () {
  157. },
  158. onReachBottom: function () {
  159. },
  160. onShareAppMessage: function () {
  161. }
  162. })