ride_zige.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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: my.getStorageSync({'key':'setting'}).data.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. 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. if (app.globalData.req) {
  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. 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/depochenSuce/depoSuce',
  116. })
  117. }
  118. })
  119. that.setData({
  120. depoSuce: true
  121. })
  122. },
  123. fail(err) {
  124. // console.log(err)
  125. // my.showToast({
  126. // content: '支付失败',
  127. // icon: 'none'
  128. // })
  129. // that.setData({
  130. // depoSuce: true
  131. // })
  132. }
  133. })
  134. } else {
  135. console.log(res)
  136. that.setData({
  137. depoSuce: true
  138. })
  139. }
  140. })
  141. }
  142. } else {
  143. my.showToast({
  144. content: '您的操作过于频繁,请稍后再试~',
  145. icon: 'none'
  146. })
  147. }
  148. }, 1000),
  149. //退还押金
  150. backDeposit: function () {
  151. this.setData({
  152. frame: true
  153. })
  154. },
  155. closeFrame: function () {
  156. this.setData({
  157. frame: false
  158. })
  159. },
  160. //立即退还
  161. sureBack:util.throttle(function (e) {
  162. let setting=my.getStorageSync({'key':'setting'}).data
  163. var that = this;
  164. if (setting.deposit_delay_setting.status == true) {
  165. my.confirm({
  166. title: '退还押金',
  167. content: '您这笔退款预计一到三天内到账是否确认退款',
  168. showCancel: true, //是否显示取消按钮
  169. cancelButtonText: "取消", //默认是“取消”
  170. cancelColor: '#000000', //取消文字的颜色
  171. confirmButtonText: "确认", //默认是“确定”
  172. confirmColor: '#FF0000', //确定文字的颜色
  173. success: function (res) {
  174. if (res.confirm==false) {
  175. //点击取消,默认隐藏弹框
  176. } else {
  177. //点击确定
  178. app.request('/deposit/refund-job', '', 'POST').then(res => {
  179. console.log(res,'退还押金');
  180. if (res.status == 200) {
  181. my.reLaunch({
  182. url: '/pages/refund_success/refund_success?number=' + that.data.setting.deposit_delay_setting.day,
  183. })
  184. }
  185. }).catch(err=>{
  186. console.log('0000')
  187. })
  188. }
  189. }
  190. })
  191. } else {
  192. app.request('/deposit/refund', '', 'POST').then(res => {
  193. console.log(res);
  194. if (res.status == 200) {
  195. my.showToast({
  196. content: '申请成功,1个工作日内到账!',
  197. icon: 'none'
  198. })
  199. setTimeout(function(){
  200. my.reLaunch({
  201. url: '/pages/index/index',
  202. })
  203. },1500)
  204. // this.getState()
  205. }
  206. })
  207. }
  208. }, 1000),
  209. onReady: function () {
  210. },
  211. onShow: function () {
  212. },
  213. onHide: function () {
  214. },
  215. onUnload: function () {
  216. },
  217. onPullDownRefresh: function () {
  218. },
  219. onReachBottom: function () {
  220. },
  221. onShareAppMessage: function () {
  222. }
  223. })