payment.js 13 KB

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