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