payment.js 12 KB

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