pay.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. const util = require('../../utils/utils')
  2. var app = getApp()
  3. var url = ''
  4. var intervar;
  5. Page({
  6. data: {
  7. statusbar: '',//导航栏高度
  8. order: '',//订单编号
  9. date: [],
  10. balance: '', //当前余额
  11. bolear: '', //判断当前余额够不够本次消费 够为true 不够为false
  12. check1: '',
  13. check2: '',
  14. index: '', //记录当前选择的是余额还是支付宝支付
  15. disable: false,
  16. timing: '',
  17. rent: '',
  18. screenHeight: '',
  19. code: '',
  20. chooseSize: false,
  21. animationData1: {},
  22. couponIndex: 0,
  23. coupon_user_bags_id: 0,
  24. coupon: [],
  25. payment_type: false,
  26. notice: false,
  27. setting: my.getStorageSync({ 'key': 'setting' }).data,
  28. img: app.globalData.imgUrl
  29. },
  30. catchtouchmove: function () {
  31. return;
  32. },
  33. tap_coupon: function (e) {
  34. this.setData({
  35. couponIndex: e.currentTarget.dataset.index
  36. })
  37. },
  38. payment_type: function () {
  39. this.setData({
  40. payment_type: true
  41. })
  42. },
  43. cancel: function () {
  44. console.log(this.data.index)
  45. this.setData({
  46. index: this.data.index,
  47. payment_type: false
  48. })
  49. if (this.data.index == 2) {
  50. this.setData({
  51. check1: true,
  52. check2: false
  53. })
  54. }
  55. if (this.data.index == 1) {
  56. this.setData({
  57. check2: true,
  58. check1: false
  59. })
  60. }
  61. },
  62. queding: function () {
  63. if (this.data.check1) {
  64. //判断当前是不是余额支付
  65. this.setData({
  66. check1: true,
  67. check2: false,
  68. index: 2,
  69. })
  70. } else {
  71. this.setData({
  72. check1: false,
  73. check2: true,
  74. index: 1,
  75. })
  76. }
  77. this.setData({
  78. payment_type: false
  79. })
  80. },
  81. to_recharge: function () {
  82. // console.log('去充值')
  83. my.navigateTo({
  84. url: '/pages/balance/balance',
  85. })
  86. },
  87. notice: function () {
  88. this.setData({
  89. notice: true
  90. })
  91. },
  92. notice_false: function () {
  93. this.setData({
  94. notice: false
  95. })
  96. },
  97. onLoad: function (options) {
  98. console.log(options)
  99. var that = this;
  100. this.setData({
  101. screenHeight: app.globalData.screenHeight
  102. })
  103. // if (options.rent == 'rent') {
  104. // } else {
  105. url = '/order'
  106. // url = '/rent'
  107. // this.setData({
  108. // rent: true
  109. // })
  110. // }
  111. if (options != null && options.order.length > 20) {
  112. this.setData({
  113. order: options.order
  114. })
  115. } else {
  116. my.alert({
  117. title: '提示',
  118. content: '订单号有误,请重试~',
  119. showCancel: false,
  120. success: function (res) {
  121. my.reLaunch({
  122. url: '/pages/index/index',
  123. })
  124. }
  125. })
  126. }
  127. },
  128. home: function () {
  129. //点击返回首页
  130. var that = this;
  131. if (that.data.index != '') {
  132. var data = {
  133. pay_type: that.data.index,
  134. order_no: that.data.order,
  135. coupon_user_bags_id: that.data.coupon_user_bags_id
  136. }
  137. if (that.data.disable == true) {
  138. my.showToast({
  139. content: '您的操作过于频繁,请稍后再试~',
  140. icon: 'none'
  141. })
  142. return;
  143. }
  144. that.setData({
  145. disable: true
  146. })
  147. if (that.data.date.orders.pay_status == 1) {
  148. my.reLaunch({
  149. url: '/pages/index/index',
  150. })
  151. my.hideLoading()
  152. return
  153. }
  154. app.request(url + '/pay', data, 'POST').then(res => {
  155. console.log(res)
  156. that.setData({
  157. order: res.data.order_no
  158. })
  159. //获取支付参数
  160. if (res.status == 200) {
  161. this.setData({
  162. order: res.data.order_no
  163. })
  164. if (res.data.pay_order_status == true) {
  165. my.reLaunch({
  166. url: '/pages/index/index',
  167. })
  168. } else {
  169. if (that.data.index == 1) {
  170. my.tradePay({
  171. tradeNO: res.data.tradeNo,
  172. success(resp) {
  173. console.log(resp, 'zhifubao')
  174. if (resp.resultCode == 9000) {
  175. my.reLaunch({
  176. url: '/pages/index/index',
  177. })
  178. } else {
  179. return
  180. }
  181. },
  182. fail(err) {
  183. my.showToast({
  184. content: '支付失败',
  185. icon: 'none'
  186. })
  187. }
  188. })
  189. that.setData({
  190. disable: false
  191. })
  192. } else {
  193. my.reLaunch({
  194. url: '/pages/index/index',
  195. })
  196. }
  197. }
  198. }
  199. })
  200. }
  201. },
  202. retryClose: util.throttle(function () {
  203. //点击关锁失败
  204. var that = this;
  205. my.showLoading({
  206. content: '关锁中...',
  207. mask: true
  208. })
  209. clearInterval(intervar)
  210. my.getLocation({
  211. type: 'gcj02',
  212. success: function (res) {
  213. console.log(res)
  214. app.request('/order/retry-close-lock?order_no=' + that.data.date.orders.no + '&bike_no=' + that.data.date.orders.bike_no, '', 'GET').then(res => {
  215. console.log(res)
  216. if (res.status == 200) {
  217. my.hideLoading()
  218. if (res.data.status == 1) {
  219. my.showToast({
  220. content: '关锁成功',
  221. icon: 'none'
  222. })
  223. }
  224. }
  225. })
  226. },
  227. })
  228. }, 1000),
  229. check1: function () {
  230. //选择余额支付
  231. this.setData({
  232. check1: true,
  233. check2: false
  234. })
  235. },
  236. check2: function () {
  237. //选择支付宝支付
  238. this.setData({
  239. check1: false,
  240. check2: true
  241. })
  242. },
  243. check4: function () {
  244. //点击去购买骑行卡
  245. my.navigateTo({
  246. url: '/pages/buy-card/buy-card',
  247. })
  248. },
  249. check3: function () {
  250. var that = this;
  251. // 创建一个动画实例
  252. console.log(that.data.coupon)
  253. app.request('/coupon/getCouponsByOrder?order_no=' + that.data.order, '', 'GET').then(res => {
  254. console.log(res)
  255. if (res.status == 200) {
  256. that.setData({
  257. coupon: res.data
  258. })
  259. var coupon = res.data.dataYes;
  260. for (var i = 0; i < coupon.length; i++) {
  261. if (coupon[i].id == that.data.date.user_coupon.coupon_user_bags_id) {
  262. coupon[i].selected = true;
  263. } else {
  264. coupon[i].selected = false;
  265. }
  266. }
  267. var couponYes = 'coupon.dataYes';
  268. that.setData({
  269. [couponYes]: coupon
  270. })
  271. }
  272. })
  273. var animation = my.createAnimation({
  274. // 动画持续时间
  275. duration: 400,
  276. // 定义动画效果,当前是匀速
  277. timingFunction: 'linear'
  278. })
  279. // 将该变量赋值给当前动画
  280. that.animation = animation
  281. // 先在y轴偏移,然后用step()完成一个动画
  282. animation.translateY(300).step()
  283. // 用setData改变当前动画
  284. that.setData({
  285. // 通过export()方法导出数据
  286. animationData1: animation.export(),
  287. // 改变view里面的Wx:if
  288. chooseSize: true
  289. })
  290. // 设置setTimeout来改变y轴偏移量,实现有感觉的滑动
  291. setTimeout(function () {
  292. animation.translateY(0).step()
  293. that.setData({
  294. animationData1: animation.export()
  295. })
  296. }, 100)
  297. },
  298. hideModal: function (e) {
  299. var that = this;
  300. var animation = my.createAnimation({
  301. duration: 400,
  302. timingFunction: 'linear'
  303. })
  304. that.animation = animation
  305. animation.translateY(360).step()
  306. that.setData({
  307. animationData1: animation.export()
  308. })
  309. // setTimeout(function () {
  310. // var query = my.createSelectorQuery();
  311. // query.select('.choose').boundingClientRect();
  312. // query.exec(function (res) {
  313. // console.log(res)
  314. // // that.setData({arrowDown:res[0].height+15})
  315. // animation.translateY(res[0].height).step()
  316. // })
  317. // that.setData({
  318. // animationData1: animation.export(),
  319. // chooseSize: false
  320. // })
  321. // }, 400)
  322. },
  323. coupons: function (e) {
  324. var id = e.currentTarget.dataset.id;
  325. var index = e.currentTarget.dataset.index;
  326. var coupons = this.data.coupon.dataYes;
  327. var select = e.currentTarget.dataset.selected;
  328. if (coupons[index].selected == true) {
  329. for (var i = 0; i < coupons.length; i++) {
  330. coupons[i].selected = false;
  331. }
  332. } else {
  333. for (var i = 0; i < coupons.length; i++) {
  334. coupons[i].selected = false;
  335. coupons[index].selected = true
  336. }
  337. }
  338. var couponList = 'coupon.dataYes';
  339. this.setData({
  340. coupon_user_bags_id: id,
  341. // chooseSize: false,
  342. [couponList]: coupons
  343. })
  344. },
  345. srue: function () {
  346. var that = this;
  347. var coupon_yes = that.data.coupon.dataYes;
  348. var id = ''
  349. for (var i = 0; i < coupon_yes.length; i++) {
  350. if (coupon_yes[i].selected == true) {
  351. id = coupon_yes[i].id
  352. }
  353. }
  354. my.showLoading({
  355. content: '加载中...',
  356. mask: true
  357. })
  358. app.request(url + '/pay-show?order_no=' + that.data.order + '&coupon_user_bags_id=' + id, '', 'GET').then(res => {
  359. console.log(res)
  360. if (res.status == 200) {
  361. my.hideLoading()
  362. that.setData({
  363. date: res.data,
  364. balance: res.data.wallet_money,
  365. bolear: res.data.wallet_pay_status,
  366. chooseSize: false
  367. })
  368. if (res.data.wallet_pay_status == false) {
  369. that.setData({
  370. check1: false,
  371. check2: true,
  372. index: 1
  373. })
  374. } else {
  375. that.setData({
  376. check1: true,
  377. check2: false,
  378. index: 2
  379. })
  380. }
  381. console.log(that.data.index)
  382. if (res.data.user_coupon.is_coupon) {
  383. that.setData({
  384. coupon_user_bags_id: res.data.user_coupon.coupon_user_bags_id
  385. })
  386. }
  387. }
  388. })
  389. },
  390. payment: util.throttle(function () {
  391. my.showLoading({
  392. content: '加载中',
  393. icon: 'none',
  394. mask: true
  395. })
  396. //点击立即支付
  397. var that = this;
  398. console.log(that.data.index)
  399. if (that.data.index != '') {
  400. var data = {
  401. pay_type: that.data.index,
  402. order_no: that.data.order,
  403. coupon_user_bags_id: that.data.coupon_user_bags_id
  404. }
  405. app.request(url + '/pay', data, 'POST').then(res => {
  406. console.log(res)
  407. my.hideLoading()
  408. //获取支付参数
  409. if (res.status == 200) {
  410. if (that.data.index == 1) {
  411. my.tradePay({
  412. tradeNO: res.data.tradeNo,
  413. success(resp) {
  414. console.log(resp, 'zhifubao')
  415. if (resp.resultCode == 9000) {
  416. my.reLaunch({
  417. url: '/pages/pay_success/pay_success',
  418. })
  419. } else {
  420. return
  421. }
  422. },
  423. fail(err) {
  424. my.hideLoading()
  425. my.showToast({
  426. content: '支付失败',
  427. icon: 'none'
  428. })
  429. }
  430. })
  431. that.setData({
  432. disable: false
  433. })
  434. } else {
  435. my.reLaunch({
  436. url: '/pages/pay_success/pay_success?order=' + that.data.date.orders.no,
  437. })
  438. }
  439. }
  440. }).catch(err => {
  441. my.hideLoading()
  442. my.showToast({
  443. content: '请求失败,请重试',
  444. icon: 'none'
  445. })
  446. })
  447. } else {
  448. my.hideLoading()
  449. my.showToast({
  450. content: '请选择支付方式',
  451. icon: 'none'
  452. })
  453. }
  454. }, 1500),
  455. repair: function () {
  456. my.navigateTo({
  457. url: '/pages/repair/repair?bike_id=' + this.data.code,
  458. })
  459. },
  460. phone: function (e) {
  461. my.makePhoneCall({
  462. number: my.getStorageSync({ 'key': 'home' }).data.customer_service_phone,
  463. })
  464. },
  465. onReady: function () {
  466. // console.log(this.data.coupon.dataYes)
  467. },
  468. onShow: function () {
  469. this.refresh()
  470. },
  471. refresh: function () {
  472. my.showNavigationBarLoading();
  473. var that = this;
  474. my.showLoading({
  475. content: '加载中...',
  476. mask: true
  477. })
  478. if (that.data.order.length > 20) {
  479. app.request(url + '/pay-show?order_no=' + that.data.order + '&is_first=true', '', 'GET').then(res => {
  480. console.log(res, '支付页面数据')
  481. console.log(this.data.disable, '支付页面数据')
  482. if (res.status == 200) {
  483. that.setData({
  484. date: res.data,
  485. balance: res.data.wallet_money,
  486. bolear: res.data.wallet_pay_status,
  487. code: res.data.orders.bike_no
  488. })
  489. my.hideLoading({
  490. complete: (res) => { },
  491. })
  492. if (res.data.wallet_pay_status == false) {
  493. that.setData({
  494. check1: false,
  495. check2: true,
  496. index: 1
  497. })
  498. } else {
  499. that.setData({
  500. check1: true,
  501. check2: false,
  502. index: 2
  503. })
  504. }
  505. if (res.data.user_coupon.is_coupon) {
  506. that.setData({
  507. coupon_user_bags_id: res.data.user_coupon.coupon_user_bags_id
  508. })
  509. }
  510. my.hideNavigationBarLoading()
  511. my.stopPullDownRefresh()
  512. }
  513. })
  514. }
  515. else {
  516. my.hideLoading()
  517. my.hideNavigationBarLoading()
  518. my.stopPullDownRefresh()
  519. }
  520. },
  521. onPullDownRefresh: function () {
  522. this.refresh()
  523. },
  524. backHome: function () {
  525. my.reLaunch({
  526. url: '/pages/index/index',
  527. })
  528. },
  529. onReachBottom: function () {
  530. },
  531. onShareAppMessage: function () {
  532. }
  533. })