const util = require('../../utils/utils') var app = getApp() var url = '' var intervar; Page({ data: { statusbar: '',//导航栏高度 order: '',//订单编号 date: [], balance: '', //当前余额 bolear: '', //判断当前余额够不够本次消费 够为true 不够为false check1: '', check2: '', index: '', //记录当前选择的是余额还是支付宝支付 disable: false, timing: '', rent: '', screenHeight: '', code: '', chooseSize: false, animationData1: {}, couponIndex: 0, coupon_user_bags_id: 0, coupon: [], payment_type: false, notice: false, setting: my.getStorageSync({ 'key': 'setting' }).data, img: app.globalData.imgUrl }, catchtouchmove: function () { return; }, tap_coupon: function (e) { this.setData({ couponIndex: e.currentTarget.dataset.index }) }, payment_type: function () { this.setData({ payment_type: true }) }, cancel: function () { console.log(this.data.index) this.setData({ index: this.data.index, payment_type: false }) if (this.data.index == 2) { this.setData({ check1: true, check2: false }) } if (this.data.index == 1) { this.setData({ check2: true, check1: false }) } }, queding: function () { if (this.data.check1) { //判断当前是不是余额支付 this.setData({ check1: true, check2: false, index: 2, }) } else { this.setData({ check1: false, check2: true, index: 1, }) } this.setData({ payment_type: false }) }, to_recharge: function () { // console.log('去充值') my.navigateTo({ url: '/pages/balance/balance', }) }, notice: function () { this.setData({ notice: true }) }, notice_false: function () { this.setData({ notice: false }) }, onLoad: function (options) { console.log(options) var that = this; this.setData({ screenHeight: app.globalData.screenHeight }) // if (options.rent == 'rent') { // } else { url = '/order' // url = '/rent' // this.setData({ // rent: true // }) // } if (options != null && options.order.length > 20) { this.setData({ order: options.order }) } else { my.alert({ title: '提示', content: '订单号有误,请重试~', showCancel: false, success: function (res) { my.reLaunch({ url: '/pages/index/index', }) } }) } }, home: function () { //点击返回首页 var that = this; if (that.data.index != '') { var data = { pay_type: that.data.index, order_no: that.data.order, coupon_user_bags_id: that.data.coupon_user_bags_id } if (that.data.disable == true) { my.showToast({ content: '您的操作过于频繁,请稍后再试~', icon: 'none' }) return; } that.setData({ disable: true }) if (that.data.date.orders.pay_status == 1) { my.reLaunch({ url: '/pages/index/index', }) my.hideLoading() return } app.request(url + '/pay', data, 'POST').then(res => { console.log(res) that.setData({ order: res.data.order_no }) //获取支付参数 if (res.status == 200) { this.setData({ order: res.data.order_no }) if (res.data.pay_order_status == true) { my.reLaunch({ url: '/pages/index/index', }) } else { if (that.data.index == 1) { my.tradePay({ tradeNO: res.data.tradeNo, success(resp) { console.log(resp, 'zhifubao') if (resp.resultCode == 9000) { my.reLaunch({ url: '/pages/index/index', }) } else { return } }, fail(err) { my.showToast({ content: '支付失败', icon: 'none' }) } }) that.setData({ disable: false }) } else { my.reLaunch({ url: '/pages/index/index', }) } } } }) } }, retryClose: util.throttle(function () { //点击关锁失败 var that = this; my.showLoading({ content: '关锁中...', mask: true }) clearInterval(intervar) my.getLocation({ type: 'gcj02', success: function (res) { console.log(res) app.request('/order/retry-close-lock?order_no=' + that.data.date.orders.no + '&bike_no=' + that.data.date.orders.bike_no, '', 'GET').then(res => { console.log(res) if (res.status == 200) { my.hideLoading() if (res.data.status == 1) { my.showToast({ content: '关锁成功', icon: 'none' }) } } }) }, }) }, 1000), check1: function () { //选择余额支付 this.setData({ check1: true, check2: false }) }, check2: function () { //选择支付宝支付 this.setData({ check1: false, check2: true }) }, check4: function () { //点击去购买骑行卡 my.navigateTo({ url: '/pages/buy-card/buy-card', }) }, check3: function () { var that = this; // 创建一个动画实例 console.log(that.data.coupon) app.request('/coupon/getCouponsByOrder?order_no=' + that.data.order, '', 'GET').then(res => { console.log(res) if (res.status == 200) { that.setData({ coupon: res.data }) var coupon = res.data.dataYes; for (var i = 0; i < coupon.length; i++) { if (coupon[i].id == that.data.date.user_coupon.coupon_user_bags_id) { coupon[i].selected = true; } else { coupon[i].selected = false; } } var couponYes = 'coupon.dataYes'; that.setData({ [couponYes]: coupon }) } }) var animation = my.createAnimation({ // 动画持续时间 duration: 400, // 定义动画效果,当前是匀速 timingFunction: 'linear' }) // 将该变量赋值给当前动画 that.animation = animation // 先在y轴偏移,然后用step()完成一个动画 animation.translateY(300).step() // 用setData改变当前动画 that.setData({ // 通过export()方法导出数据 animationData1: animation.export(), // 改变view里面的Wx:if chooseSize: true }) // 设置setTimeout来改变y轴偏移量,实现有感觉的滑动 setTimeout(function () { animation.translateY(0).step() that.setData({ animationData1: animation.export() }) }, 100) }, hideModal: function (e) { var that = this; var animation = my.createAnimation({ duration: 400, timingFunction: 'linear' }) that.animation = animation animation.translateY(360).step() that.setData({ animationData1: animation.export() }) // setTimeout(function () { // var query = my.createSelectorQuery(); // query.select('.choose').boundingClientRect(); // query.exec(function (res) { // console.log(res) // // that.setData({arrowDown:res[0].height+15}) // animation.translateY(res[0].height).step() // }) // that.setData({ // animationData1: animation.export(), // chooseSize: false // }) // }, 400) }, coupons: function (e) { var id = e.currentTarget.dataset.id; var index = e.currentTarget.dataset.index; var coupons = this.data.coupon.dataYes; var select = e.currentTarget.dataset.selected; if (coupons[index].selected == true) { for (var i = 0; i < coupons.length; i++) { coupons[i].selected = false; } } else { for (var i = 0; i < coupons.length; i++) { coupons[i].selected = false; coupons[index].selected = true } } var couponList = 'coupon.dataYes'; this.setData({ coupon_user_bags_id: id, // chooseSize: false, [couponList]: coupons }) }, srue: function () { var that = this; var coupon_yes = that.data.coupon.dataYes; var id = '' for (var i = 0; i < coupon_yes.length; i++) { if (coupon_yes[i].selected == true) { id = coupon_yes[i].id } } my.showLoading({ content: '加载中...', mask: true }) app.request(url + '/pay-show?order_no=' + that.data.order + '&coupon_user_bags_id=' + id, '', 'GET').then(res => { console.log(res) if (res.status == 200) { my.hideLoading() that.setData({ date: res.data, balance: res.data.wallet_money, bolear: res.data.wallet_pay_status, chooseSize: false }) if (res.data.wallet_pay_status == false) { that.setData({ check1: false, check2: true, index: 1 }) } else { that.setData({ check1: true, check2: false, index: 2 }) } console.log(that.data.index) if (res.data.user_coupon.is_coupon) { that.setData({ coupon_user_bags_id: res.data.user_coupon.coupon_user_bags_id }) } } }) }, payment: util.throttle(function () { my.showLoading({ content: '加载中', icon: 'none', mask: true }) //点击立即支付 var that = this; console.log(that.data.index) if (that.data.index != '') { var data = { pay_type: that.data.index, order_no: that.data.order, coupon_user_bags_id: that.data.coupon_user_bags_id } app.request(url + '/pay', data, 'POST').then(res => { console.log(res) my.hideLoading() //获取支付参数 if (res.status == 200) { if (that.data.index == 1) { my.tradePay({ tradeNO: res.data.tradeNo, success(resp) { console.log(resp, 'zhifubao') if (resp.resultCode == 9000) { my.reLaunch({ url: '/pages/pay_success/pay_success', }) } else { return } }, fail(err) { my.hideLoading() my.showToast({ content: '支付失败', icon: 'none' }) } }) that.setData({ disable: false }) } else { my.reLaunch({ url: '/pages/pay_success/pay_success?order=' + that.data.date.orders.no, }) } } }).catch(err => { my.hideLoading() my.showToast({ content: '请求失败,请重试', icon: 'none' }) }) } else { my.hideLoading() my.showToast({ content: '请选择支付方式', icon: 'none' }) } }, 1500), repair: function () { my.navigateTo({ url: '/pages/repair/repair?bike_id=' + this.data.code, }) }, phone: function (e) { my.makePhoneCall({ number: my.getStorageSync({ 'key': 'home' }).data.customer_service_phone, }) }, onReady: function () { // console.log(this.data.coupon.dataYes) }, onShow: function () { this.refresh() }, refresh: function () { my.showNavigationBarLoading(); var that = this; my.showLoading({ content: '加载中...', mask: true }) if (that.data.order.length > 20) { app.request(url + '/pay-show?order_no=' + that.data.order + '&is_first=true', '', 'GET').then(res => { console.log(res, '支付页面数据') console.log(this.data.disable, '支付页面数据') if (res.status == 200) { that.setData({ date: res.data, balance: res.data.wallet_money, bolear: res.data.wallet_pay_status, code: res.data.orders.bike_no }) my.hideLoading({ complete: (res) => { }, }) if (res.data.wallet_pay_status == false) { that.setData({ check1: false, check2: true, index: 1 }) } else { that.setData({ check1: true, check2: false, index: 2 }) } if (res.data.user_coupon.is_coupon) { that.setData({ coupon_user_bags_id: res.data.user_coupon.coupon_user_bags_id }) } my.hideNavigationBarLoading() my.stopPullDownRefresh() } }) } else { my.hideLoading() my.hideNavigationBarLoading() my.stopPullDownRefresh() } }, onPullDownRefresh: function () { this.refresh() }, backHome: function () { my.reLaunch({ url: '/pages/index/index', }) }, onReachBottom: function () { }, onShareAppMessage: function () { } })