pay.js 13 KB

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