123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- var app = getApp()
- var url = ''
- import {
- BluetoothManager,
- BtErrorCode,
- CMD
- } from '../../service/BluWkm'
- var intervar;
- const bluM = new BluetoothManager
- Page({
- data: {
- 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: wx.getStorageSync('setting'),
- 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 () {
- console.log(this.data.check2)
- console.log(this.data.check1)
- console.log(this.data.index)
- 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('去充值')
- wx.navigateTo({
- url: '/pages/personal/recharge/recharge',
- })
- },
- 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') {
- //说明是日租订单
- url = '/rent'
- this.setData({
- rent: false
- })
- } else {
- url = '/order'
- this.setData({
- rent: true
- })
- }
- this.setData({
- order: options.order
- })
- console.log(options.order)
- },
- home: function () {
- //点击返回首页
- var that = this;
- if (app.globalData.compatible) {
- wx.reLaunch({
- url: '/pages/compatible/index/index',
- })
- } else {
- 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) {
- return;
- }
- that.setData({
- disable: true
- })
- app.request(url + '/pay', data, 'POST').then(res => {
- console.log(res)
- //获取支付参数
- if (res.statusCode == 200) {
- if (res.data.pay_order_status == true) {
- wx.reLaunch({
- url: '/pages/index/index',
- })
- } else {
- if (that.data.index == 1) {
- wx.requestPayment({ //调用微信支付
- timeStamp: res.data.timeStamp.toString(),
- nonceStr: res.data.nonceStr,
- package: res.data.package,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success(resp) {
- console.log(resp)
- wx.reLaunch({
- url: '/pages/index/index',
- })
- },
- fail(err) {
- console.log(err)
- wx.showToast({
- title: '支付失败',
- icon: 'none'
- })
- if (res.data.order_no != that.data.order) {
- that.setData({
- order: res.data.order_no
- })
- }
- }
- })
- that.setData({
- disable: false
- })
- } else {
- wx.reLaunch({
- url: '/pages/index/index',
- })
- }
- }
- }
- })
- }
- }
- },
- retryClose: function () {
- //点击关锁失败
- var that = this;
- wx.showLoading({
- title: '关锁中...',
- mask: true
- })
- clearInterval(intervar)
- wx.getLocation({
- type: 'gcj02',
- success: function (res) {
- console.log(res)
- bluM.connectDeivece(that.data.box_no, CMD.lock)
- 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.statusCode == 200) {
- wx.hideLoading()
- if (res.data.status == 1) {
- wx.showToast({
- title: '关锁成功',
- icon: 'none'
- })
- }
- }
- })
- },
- })
- },
- check1: function () {
- //选择余额支付
- this.setData({
- check1: true,
- check2: false
- })
- },
- check2: function () {
- //选择微信支付
- this.setData({
- check1: false,
- check2: true
- })
- },
- check4: function () {
- //点击去购买骑行卡
- wx.navigateTo({
- url: '/pages/recharge/recharge',
- })
- },
- 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.statusCode == 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 = wx.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 = wx.createAnimation({
- duration: 400,
- timingFunction: 'linear'
- })
- that.animation = animation
- animation.translateY(360).step()
- that.setData({
- animationData1: animation.export()
- })
- setTimeout(function () {
- var query = wx.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
- }
- }
- wx.showLoading({
- title: '加载中...',
- 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.statusCode == 200) {
- wx.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: function () {
- //点击立即支付
- 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
- }
- if (that.data.disable == true) {
- return;
- }
- that.setData({
- disable: true
- })
- app.request(url + '/pay', data, 'POST').then(res => {
- console.log(res)
- //获取支付参数
- if (res.statusCode == 200) {
- if (that.data.index == 1) {
- wx.requestPayment({ //调用微信支付
- timeStamp: res.data.timeStamp.toString(),
- nonceStr: res.data.nonceStr,
- package: res.data.package,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success(resp) {
- console.log(resp)
- wx.reLaunch({
- url: '/pages/personal/rechSuce/rechSuce?order=' + that.data.date.orders.no + '&rent=' + that.data.rent,
- })
- },
- fail(err) {
- console.log(err)
- wx.showToast({
- title: '支付失败',
- icon: 'none'
- })
- if (res.data.order_no != that.data.order) {
- that.setData({
- order: res.data.order_no
- })
- }
- }
- })
- that.setData({
- disable: false
- })
- } else {
- wx.reLaunch({
- url: '/pages/personal/rechSuce/rechSuce?order=' + that.data.order + '&rent=' + that.data.rent,
- })
- }
- } else {
- that.setData({
- disable: false
- })
- }
- }).catch(err => {
- console.log(err)
- })
- } else {
- wx.showToast({
- title: '请选择支付方式',
- icon: 'none'
- })
- }
- },
- repair: function () {
- wx.navigateTo({
- url: '/pages/repair/repair?bike_id=' + this.data.code,
- })
- },
- phone: function (e) {
- wx.makePhoneCall({
- phoneNumber: wx.getStorageSync('home').customer_service_phone,
- })
- },
- onReady: function () {
- // console.log(this.data.coupon.dataYes)
- },
- onShow: function () {
- this.refresh()
- this.setData({
- setting: wx.getStorageSync('setting')
- })
- },
- refresh: function () {
- wx.showNavigationBarLoading();
- var that = this;
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- app.request(url + '/pay-show?order_no=' + that.data.order + '&is_first=true', '', 'GET').then(res => {
- console.log(res)
- if (res.statusCode == 200) {
- wx.hideLoading({
- complete: (res) => {},
- })
- that.setData({
- date: res.data,
- balance: res.data.wallet_money,
- bolear: res.data.wallet_pay_status,
- code: res.data.orders.bike_no
- })
- 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
- })
- }
- wx.hideNavigationBarLoading()
- wx.stopPullDownRefresh()
- }
- })
- },
- onHide: function () {
- },
- onUnload: function () {
- },
- onPullDownRefresh: function () {
- this.refresh()
- },
- onReachBottom: function () {
- },
- onShareAppMessage: function () {
- }
- })
|