pay.js 14 KB

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