ride_zige.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.statusCode == 200) {
  98. console.log(res)
  99. my.requestPayment({
  100. timeStamp: res.data.timeStamp.toString(),
  101. nonceStr: res.data.nonceStr,
  102. package: res.data.package,
  103. signType: res.data.signType,
  104. paySign: res.data.paySign,
  105. success(res) {
  106. console.log(res)
  107. let init = '';
  108. if (that.data.depShow) {
  109. init = "购买成功"
  110. } else {
  111. init = "支付成功"
  112. }
  113. my.showToast({
  114. content: init,
  115. icon: 'none',
  116. duration: 1000,
  117. success: function () {
  118. my.reLaunch({
  119. url: '/pages/depochenSuce/depoSuce',
  120. })
  121. }
  122. })
  123. that.setData({
  124. depoSuce: true
  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. } else {
  147. my.showToast({
  148. content: '您的操作过于频繁,请稍后再试~',
  149. icon: 'none'
  150. })
  151. }
  152. }, 1000),
  153. //退还押金
  154. backDeposit: function () {
  155. this.setData({
  156. frame: true
  157. })
  158. },
  159. closeFrame: function () {
  160. this.setData({
  161. frame: false
  162. })
  163. },
  164. //立即退还
  165. sureBack:util.throttle(function (e) {
  166. let setting=my.getStorageSync({'key':'setting'}).data
  167. var that = this;
  168. if (setting.deposit_delay_setting.status == true) {
  169. my.confirm({
  170. title: '退还押金',
  171. content: '您这笔退款预计一到三天内到账是否确认退款',
  172. showCancel: true, //是否显示取消按钮
  173. cancelButtonText: "取消", //默认是“取消”
  174. cancelColor: '#000000', //取消文字的颜色
  175. confirmButtonText: "确认", //默认是“确定”
  176. confirmColor: '#FF0000', //确定文字的颜色
  177. success: function (res) {
  178. if (res.confirm==false) {
  179. //点击取消,默认隐藏弹框
  180. } else {
  181. //点击确定
  182. app.request('/deposit/refund-job', '', 'POST').then(res => {
  183. console.log(res,'退还押金');
  184. if (res.statusCode == 200) {
  185. my.reLaunch({
  186. url: '/pages/refund_success/refund_success?number=' + that.data.setting.deposit_delay_setting.day,
  187. })
  188. }
  189. }).catch(err=>{
  190. console.log('0000')
  191. })
  192. }
  193. }
  194. })
  195. } else {
  196. app.request('/deposit/refund', '', 'POST').then(res => {
  197. console.log(res);
  198. if (res.statusCode == 200) {
  199. my.showToast({
  200. content: '申请成功,1个工作日内到账!',
  201. icon: 'none'
  202. })
  203. setTimeout(function(){
  204. my.reLaunch({
  205. url: '/pages/index/index',
  206. })
  207. },1500)
  208. // this.getState()
  209. }
  210. })
  211. }
  212. }, 1000),
  213. onReady: function () {
  214. },
  215. onShow: function () {
  216. },
  217. onHide: function () {
  218. },
  219. onUnload: function () {
  220. },
  221. onPullDownRefresh: function () {
  222. },
  223. onReachBottom: function () {
  224. },
  225. onShareAppMessage: function () {
  226. }
  227. })