453 lines
9.0 KiB
JavaScript
453 lines
9.0 KiB
JavaScript
// pages/basketballGym/index.js
|
|
// import QRCode from './qrcode';
|
|
import drawQrcode from './weapp.qrcode.js';
|
|
const app = getApp();
|
|
import {
|
|
getCurrentPageUrl
|
|
} from './../../utils/util.js'
|
|
let id = ''
|
|
// let qrcode = new QRCode('canvas', {
|
|
// text: "123456",
|
|
// width: 120,
|
|
// height: 120,
|
|
// colorDark: '#000000',
|
|
// colorLight: '#ffffff',
|
|
// correctLevel: QRCode.correctLevel.H
|
|
// });
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
venues: {},
|
|
// isShowBuyVip: false,
|
|
// buyVipObj: {},
|
|
showUnclickMask: false,
|
|
// showCardMask: false,
|
|
orderSn: '000',
|
|
payMoney: 0,
|
|
flg: 100,
|
|
isPayed: false,
|
|
msg: '',
|
|
isWxLogin: false,
|
|
isGoHome: false,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function(options) {
|
|
if (options.id) {
|
|
id = options.id;
|
|
}
|
|
|
|
if (options.scene) {
|
|
id = options.scene;
|
|
}
|
|
this.initPage()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function() {
|
|
let pages = getCurrentPages();
|
|
this.setData({
|
|
isGoHome: pages.length == 1
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function() {
|
|
this.setData({
|
|
showUnclickMask: false
|
|
// flg: 100
|
|
})
|
|
|
|
this.initPage()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function() {
|
|
this.initPage()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function() {
|
|
return {
|
|
title: this.data.venues.name,
|
|
imageUrl: this.data.venues.images[0].url
|
|
}
|
|
},
|
|
|
|
initPage() {
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
mask: true,
|
|
})
|
|
app.$api.venueDetail({
|
|
venueId: id
|
|
}).then(res => {
|
|
console.log(res);
|
|
this.setData({
|
|
venues: res.venues
|
|
})
|
|
}, err => {
|
|
|
|
});
|
|
},
|
|
|
|
checkIsPayed(orderSn) {
|
|
this.setData({
|
|
flg: 777,
|
|
msg: '正在查询支付结果...'
|
|
})
|
|
let that = this;
|
|
setTimeout(function(){
|
|
app.$api.memberIsPayed({
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
if (res.isPayed) {
|
|
that.setData({
|
|
flg: 0,
|
|
msg: ''
|
|
})
|
|
that.showBarcode(orderSn)
|
|
} else {
|
|
that.setData({
|
|
flg: 777,
|
|
msg: '正在确认支付结果,请勿退出...'
|
|
})
|
|
//第二次
|
|
setTimeout(function(){
|
|
app.$api.memberIsPayed({
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
if (res.isPayed) {
|
|
that.setData({
|
|
flg: 0,
|
|
msg: ''
|
|
})
|
|
that.showBarcode(orderSn)
|
|
} else {
|
|
that.setData({
|
|
flg: 777,
|
|
msg: '最后一次确认订单状态...'
|
|
})
|
|
// 第三次
|
|
setTimeout(function(){
|
|
app.$api.memberIsPayed({
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
if (res.isPayed) {
|
|
that.setData({
|
|
flg: 0,
|
|
msg: ''
|
|
})
|
|
that.showBarcode(orderSn)
|
|
}else {
|
|
that.setData({
|
|
flg: 999,
|
|
msg: '订单未成功支付'
|
|
})
|
|
}
|
|
});
|
|
},5000)
|
|
}
|
|
});
|
|
},5000)
|
|
}
|
|
});
|
|
},5000)
|
|
},
|
|
|
|
// 打开导航,
|
|
opnGPS() {
|
|
wx.openLocation({
|
|
latitude: Number(this.data.venues.latitude),
|
|
longitude: Number(this.data.venues.longitude),
|
|
name: this.data.venues.name,
|
|
address: this.data.venues.address,
|
|
})
|
|
},
|
|
|
|
// 充值
|
|
// recharge() {
|
|
// if (!wx.getStorageSync('accessToken')) {
|
|
// wx.setStorageSync('history', getCurrentPageUrl());
|
|
// wx.redirectTo({
|
|
// url: '/pages/login/index',
|
|
// })
|
|
// return
|
|
// }
|
|
// wx.navigateTo({
|
|
// url: '/pages/myAccount/index',
|
|
// })
|
|
// },
|
|
|
|
// 打电话
|
|
callPhone() {
|
|
wx.makePhoneCall({
|
|
phoneNumber: this.data.venues.phone,
|
|
})
|
|
},
|
|
|
|
// 购买套餐
|
|
// nowBuy(e) {
|
|
// let index = e.currentTarget.dataset.index;
|
|
// if (!wx.getStorageSync('accessToken')) {
|
|
// wx.setStorageSync('history', getCurrentPageUrl());
|
|
// wx.redirectTo({
|
|
// url: '/pages/login/index',
|
|
// })
|
|
// return
|
|
// }
|
|
// this.setData({
|
|
// isShowBuyVip: true,
|
|
// buyVipObj: this.data.venues.cards[index]
|
|
// })
|
|
// },
|
|
|
|
// 我要进场
|
|
enter() {
|
|
app.$api.venueJoin({
|
|
venueId: id
|
|
}).then(res => {
|
|
this.setData({
|
|
flg: res.join.flg,
|
|
msg: res.join.msg,
|
|
payMoney: res.join.money
|
|
})
|
|
if (res.join.flg == 0) {
|
|
this.showBarcode('000')
|
|
}
|
|
}, err => {
|
|
console.log(err);
|
|
})
|
|
|
|
},
|
|
|
|
// 我要出场
|
|
out() {
|
|
app.$api.venueOut({
|
|
venueId: id
|
|
}).then(res => {
|
|
this.setData({
|
|
flg: res.out.flg,
|
|
msg: res.out.msg,
|
|
payMoney: res.out.money
|
|
})
|
|
if (res.out.flg == 0) {
|
|
this.showBarcode('000')
|
|
}
|
|
}, err => {
|
|
console.log(err);
|
|
})
|
|
|
|
},
|
|
|
|
// 弹框背景禁止滑动
|
|
unMove() {
|
|
return;
|
|
},
|
|
|
|
// 关闭进场步骤弹框
|
|
closeInStep() {
|
|
this.setData({
|
|
flg: 100
|
|
})
|
|
this.initPage()
|
|
},
|
|
|
|
// 关闭购买vip弹框
|
|
// closeBuyVipPopup() {
|
|
// this.setData({
|
|
// isShowBuyVip: false
|
|
// })
|
|
// },
|
|
|
|
// 购买Vip
|
|
// buyVip() {
|
|
// let that = this;
|
|
// this.setData({
|
|
// showUnclickMask: true
|
|
// })
|
|
// app.$api.memberCardOrderCreate({
|
|
// cardType: this.data.buyVipObj.cardType,
|
|
// num: 1,
|
|
// type: this.data.venues.type,
|
|
// venueId: this.data.venues.id
|
|
// }).then(res => {
|
|
// app.$pay.wxPay(res.pay).then(res => {
|
|
// that.setData({
|
|
// isShowBuyVip: false,
|
|
// showUnclickMask: false
|
|
// })
|
|
// }, err => {
|
|
// that.setData({
|
|
// isShowBuyVip: false,
|
|
// showUnclickMask: false
|
|
// })
|
|
//
|
|
// })
|
|
// }, err => {
|
|
// // console.log(err);
|
|
// this.setData({
|
|
// isShowBuyVip: false,
|
|
// showUnclickMask: false
|
|
// })
|
|
// if (err.data.err_code == 30022) {
|
|
// this.setData({
|
|
// isWxLogin: true,
|
|
// isShowBuyVip: false
|
|
// })
|
|
// }
|
|
// })
|
|
// },
|
|
|
|
// 关闭
|
|
// cancelCardMask() {
|
|
// this.setData({
|
|
// showCardMask: false
|
|
// })
|
|
// },
|
|
|
|
// 开启会员卡提示
|
|
// showCardContent() {
|
|
// this.setData({
|
|
// showCardMask: true
|
|
// })
|
|
// },
|
|
|
|
// 关闭提示框
|
|
cancelDeleteDialog() {
|
|
this.setData({
|
|
flg: 100
|
|
})
|
|
},
|
|
|
|
// 点击提示框确认
|
|
confirmOutDialog() {
|
|
// 出场
|
|
this.showBarcode('000')
|
|
},
|
|
|
|
// 点击提示框确认
|
|
confirmDeleteDialog() {
|
|
// 去支付
|
|
app.$api.basketOrder({
|
|
venueId: this.data.venues.id,
|
|
enterFlag: this.data.venues.enterFlag,
|
|
payMoney: this.data.payMoney
|
|
}).then(res => {
|
|
this.setData({
|
|
orderSn: res.pay.orderSn,
|
|
flg: 777,
|
|
msg: '正在支付...'
|
|
})
|
|
app.$pay.wxPay(res.pay).then(res => {
|
|
console.log('支付成功了')
|
|
this.checkIsPayed(this.data.orderSn)
|
|
}, err => {
|
|
console.log('支付失败')
|
|
this.setData({
|
|
flg: 999,
|
|
msg: '支付失败,用户取消支付'
|
|
})
|
|
})
|
|
}, err => {
|
|
if (err.data.err_code == 30022) {
|
|
this.setData({
|
|
isWxLogin: true,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
showBarcode(orderSn) {
|
|
app.$api.generateBarcode({
|
|
venueId: this.data.venues.id,
|
|
enterFlag: this.data.venues.enterFlag,
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
this.setData({
|
|
flg: 0
|
|
})
|
|
drawQrcode({
|
|
width: 180,
|
|
height: 180,
|
|
x: 10,
|
|
y: 10,
|
|
canvasId: 'myQrcode',
|
|
// ctx: wx.createCanvasContext('myQrcode'),
|
|
typeNumber: 10,
|
|
text: res.barcode
|
|
})
|
|
}, err => {
|
|
console.log(err)
|
|
this.setData({
|
|
flg: 999,
|
|
msg: '生成二维码失败'
|
|
})
|
|
});
|
|
},
|
|
|
|
// 取消授权登录
|
|
cancelWXDialog() {
|
|
this.setData({
|
|
isWxLogin: false
|
|
})
|
|
},
|
|
|
|
// 授权微信
|
|
getUserInfo(e) {
|
|
wx.getUserProfile({
|
|
desc: '用于完善会员资料',
|
|
success: (res) => {
|
|
app.$pay.payWxLoing(res).then(res => {
|
|
wx.showToast({
|
|
title: '绑定成功',
|
|
duration: 2000,
|
|
})
|
|
this.setData({
|
|
isWxLogin: false
|
|
})
|
|
}, err => {
|
|
this.setData({
|
|
isWxLogin: false
|
|
})
|
|
})
|
|
}
|
|
});
|
|
}
|
|
|
|
})
|