ride_zige.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // pages/ride_zige/ride_zige.js
  2. const util = require('../../utils/utils');
  3. var app = getApp()
  4. var url = ''
  5. Page({
  6. data: {
  7. currentItem: 0,
  8. cardList: [],//骑行卡列表
  9. deposit: '',//骑行卡
  10. depositMoney: '',//押金金额
  11. frame: false,//确认退还退押金弹框
  12. },
  13. onLoad: function (options) {
  14. this.setData({
  15. deposit: my.getStorageSync({ 'key': 'userState' }).data,
  16. depositMoney: my.getStorageSync({ 'key': 'setting' }).data.deposit
  17. })
  18. this.getCard()
  19. // this.getState()
  20. },
  21. //获取免押金卡列表
  22. getCard() {
  23. my.showLoading({})
  24. let data = {
  25. area_id: my.getStorageSync({ 'key': 'home' }).data.id
  26. }
  27. if (my.getStorageSync({ 'key': 'home' }).data.id == undefined) {
  28. my.hideLoading()
  29. my.showToast({
  30. content: '您附近没有运营区域',
  31. icon: 'none'
  32. })
  33. } else {
  34. //免押金卡
  35. app.request('/deposit_card/index', data, 'GET').then(res => {
  36. console.log(res.data);
  37. this.setData({
  38. cardList: res.data.data
  39. })
  40. my.hideLoading({
  41. complete: (res) => { },
  42. })
  43. console.log(this.data.cardList)
  44. })
  45. }
  46. },
  47. //选择骑行卡类型
  48. changeCard: function (e) {
  49. let that = this
  50. let id = e.currentTarget.dataset.id
  51. console.log(e, 'pppppp')
  52. that.setData({
  53. currentItem: id
  54. })
  55. // if(id==0){
  56. // }else if (that.data.deposit.is_deposit == 1 && that.data.deposit.deposit_type == 1) {
  57. // my.showToast({
  58. // content: '您已缴纳押金无需购买免押金卡',
  59. // icon: 'none'
  60. // })
  61. // return;
  62. // }
  63. },
  64. //立即支付
  65. pay: util.throttle(function (e) {
  66. console.log('支付')
  67. var that = this;
  68. let url = '';
  69. var data = '';
  70. console.log(that.data.depShow)
  71. if (that.data.currentItem == 0) { //缴纳押金
  72. console.log(11111)
  73. url = "/deposit/pay";
  74. data = {
  75. area_id: my.getStorageSync({ 'key': 'home' }).data.id
  76. }
  77. } else { //购买免押金卡
  78. console.log(2222)
  79. url = "/deposit_card/pay";
  80. data = {
  81. area_id: my.getStorageSync({ 'key': 'home' }).data.id,
  82. id: that.data.currentItem
  83. }
  84. }
  85. if (my.getStorageSync({ 'key': 'setting' }).data == '') {
  86. my.alert({
  87. title: '提示',
  88. content: '您附近暂无运营区域~',
  89. success: function (res) {
  90. my.navigateBack()
  91. }
  92. })
  93. } else {
  94. app.request(url, data, 'POST', app.globalData.req).then(res => {
  95. console.log(res)
  96. if (res.status == 200) {
  97. console.log(res)
  98. my.tradePay({
  99. tradeNO: res.data.tradeNo,
  100. success(res) {
  101. console.log(res)
  102. if (res.resultCode == 9000) {
  103. let init = '';
  104. if (that.data.depShow) {
  105. init = "购买成功"
  106. } else {
  107. init = "支付成功"
  108. }
  109. my.showToast({
  110. content: init,
  111. icon: 'none',
  112. duration: 1000,
  113. success: function () {
  114. my.reLaunch({
  115. url: '/pages/pay_success/pay_success',
  116. })
  117. }
  118. })
  119. that.setData({
  120. depoSuce: true
  121. })
  122. } else {
  123. return
  124. }
  125. },
  126. fail(err) {
  127. // console.log(err)
  128. // my.showToast({
  129. // content: '支付失败',
  130. // icon: 'none'
  131. // })
  132. // that.setData({
  133. // depoSuce: true
  134. // })
  135. }
  136. })
  137. } else {
  138. console.log(res)
  139. that.setData({
  140. depoSuce: true
  141. })
  142. }
  143. })
  144. }
  145. }, 1000),
  146. //退还押金
  147. backDeposit: function () {
  148. this.setData({
  149. frame: true
  150. })
  151. },
  152. closeFrame: function () {
  153. this.setData({
  154. frame: false
  155. })
  156. },
  157. //立即退还
  158. sureBack: util.throttle(function (e) {
  159. app.request('/deposit/refund', '', 'POST').then(res => {
  160. console.log(res);
  161. if (res.status == 200) {
  162. my.showToast({
  163. content: '押金退回申请成功,请注意查收!',
  164. icon: 'none'
  165. })
  166. setTimeout(function () {
  167. my.reLaunch({
  168. url: '/pages/index/index',
  169. })
  170. }, 1500)
  171. // this.getState()
  172. }
  173. })
  174. }, 1000),
  175. onReady: function () {
  176. },
  177. onShow: function () {
  178. },
  179. onHide: function () {
  180. },
  181. onUnload: function () {
  182. },
  183. onPullDownRefresh: function () {
  184. },
  185. onReachBottom: function () {
  186. },
  187. onShareAppMessage: function () {
  188. }
  189. })