123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- 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 () {
- }
- })
|