430 lines
10 KiB
JavaScript
430 lines
10 KiB
JavaScript
// pages/basketballGym/index.js
|
|
import { getTimeoutStorage, getDistance } from "../../utils/util";
|
|
const app = getApp();
|
|
import {
|
|
getCurrentPageUrl
|
|
} from './../../utils/util.js'
|
|
let id = ''
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
venues: {},
|
|
showUnclickMask: false,
|
|
orderSn: '000',
|
|
payMoney: 0,
|
|
flg: 100,
|
|
msg: '',
|
|
isWxLogin: false,
|
|
isGoHome: false,
|
|
welcomeMsg: '',
|
|
isRequesting: false,
|
|
isPaying: 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.openDoor(orderSn, that.data.venues.enterFlag != '1')
|
|
} else {
|
|
that.setData({
|
|
flg: 777,
|
|
msg: '正在确认支付结果,请勿退出...'
|
|
})
|
|
//第二次
|
|
setTimeout(function () {
|
|
app.$api.memberIsPayed({
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
if (res.isPayed) {
|
|
that.setData({
|
|
flg: 0,
|
|
msg: ''
|
|
})
|
|
that.openDoor(orderSn, that.data.venues.enterFlag != '1')
|
|
} else {
|
|
that.setData({
|
|
flg: 777,
|
|
msg: '正在确认订单状态...'
|
|
})
|
|
// 第三次
|
|
setTimeout(function () {
|
|
app.$api.memberIsPayed({
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
if (res.isPayed) {
|
|
that.setData({
|
|
flg: 0,
|
|
msg: ''
|
|
})
|
|
that.openDoor(orderSn, that.data.venues.enterFlag != '1')
|
|
} 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,
|
|
})
|
|
},
|
|
|
|
// 打电话
|
|
callPhone() {
|
|
wx.makePhoneCall({
|
|
phoneNumber: this.data.venues.phone,
|
|
})
|
|
},
|
|
|
|
// 我要进场
|
|
enter() {
|
|
if (this.data.isRequesting) return;
|
|
let info = wx.getStorageSync('information') || {};
|
|
if (!info.mobile) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '根据场馆实名制要求,需绑定手机号后才能进场或支付。',
|
|
confirmText: '去绑定',
|
|
success(modRes) {
|
|
if (modRes.confirm) {
|
|
wx.navigateTo({ url: '/pages/userInfo/index' })
|
|
}
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
let isRead = getTimeoutStorage('isReaded');
|
|
console.log('isRead======' + isRead)
|
|
if (isRead == 'ojbk') {
|
|
this.setData({ isRequesting: true });
|
|
wx.getFuzzyLocation({
|
|
type: 'wgs84',
|
|
success: (locRes) => {
|
|
let distance = getDistance(locRes.latitude, locRes.longitude, Number(this.data.venues.latitude), Number(this.data.venues.longitude));
|
|
if (distance > 40000) {
|
|
this.setData({ isRequesting: false });
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: `距离场馆过远,请靠近后再试!`,
|
|
showCancel: false
|
|
});
|
|
return;
|
|
}
|
|
app.$api.venueJoin({
|
|
venueId: id
|
|
}).then(res => {
|
|
this.setData({
|
|
flg: res.join.flg,
|
|
msg: res.join.msg,
|
|
payMoney: res.join.money,
|
|
isRequesting: false
|
|
})
|
|
if (res.join.flg == 0) {
|
|
if (res.join.order_sn) {
|
|
this.openDoor(res.join.order_sn, true)
|
|
} else {
|
|
console.log('已在场内,无操作')
|
|
this.setData({
|
|
flg: 100
|
|
})
|
|
wx.showToast({ title: '您已在场内', icon: 'none' });
|
|
}
|
|
}
|
|
}, err => {
|
|
this.setData({ isRequesting: false });
|
|
})
|
|
},
|
|
fail: (err) => {
|
|
this.setData({ isRequesting: false });
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '无法获取您的位置信息,可能会影响进场识别,请确保开启微信和定位权限。',
|
|
showCancel: false
|
|
});
|
|
}
|
|
});
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '/pages/disclaimers/index'
|
|
})
|
|
}
|
|
},
|
|
|
|
// 我要出场
|
|
out() {
|
|
if (this.data.isRequesting) return;
|
|
this.setData({ isRequesting: true });
|
|
app.$api.venueOut({
|
|
venueId: id
|
|
}).then(res => {
|
|
this.setData({
|
|
flg: res.out.flg,
|
|
msg: res.out.msg,
|
|
payMoney: res.out.money,
|
|
isRequesting: false
|
|
})
|
|
if (res.out.flg == 0) {
|
|
this.openDoor(res.out.order_sn || '000', false)
|
|
}
|
|
}, err => {
|
|
console.log(err);
|
|
this.setData({ isRequesting: false });
|
|
})
|
|
|
|
},
|
|
|
|
// 弹框背景禁止滑动
|
|
unMove() {
|
|
return;
|
|
},
|
|
|
|
// 关闭进场步骤弹框
|
|
closeInStep() {
|
|
this.setData({
|
|
flg: 100,
|
|
welcomeMsg: ''
|
|
})
|
|
this.initPage()
|
|
},
|
|
|
|
// 关闭提示框
|
|
cancelDeleteDialog() {
|
|
if (this.data.isPaying) {
|
|
wx.showToast({ title: '订单处理中,请稍后', icon: 'none' });
|
|
return;
|
|
}
|
|
this.setData({
|
|
flg: 100
|
|
})
|
|
},
|
|
|
|
// 点击提示框确认
|
|
confirmDeleteDialog() {
|
|
if (this.data.isPaying) return; // 防重复点击
|
|
this.setData({ isPaying: true });
|
|
wx.showLoading({ title: '正在处理订单...', mask: true }); // 物理锁死屏幕
|
|
|
|
// 去支付
|
|
app.$api.basketOrder({
|
|
venueId: this.data.venues.id,
|
|
enterFlag: this.data.venues.enterFlag,
|
|
payMoney: this.data.payMoney
|
|
}).then(res => {
|
|
// 如果后端判定这笔订单已经支付,直接开门
|
|
if (res.paid_flag) {
|
|
wx.hideLoading();
|
|
this.setData({ isPaying: false, flg: 0, msg: '' });
|
|
this.openDoor(res.order_sn, this.data.venues.enterFlag != '1');
|
|
return;
|
|
}
|
|
|
|
// 未支付,拿到单号拉起微信支付
|
|
let orderSn = res.order_sn || (res.pay && res.pay.orderSn);
|
|
this.setData({
|
|
orderSn: orderSn
|
|
})
|
|
wx.hideLoading(); // 隐藏下单的 Loading
|
|
|
|
app.$pay.wxPay(res.pay).then(wxRes => {
|
|
console.log('支付成功了');
|
|
this.setData({ isPaying: false, isRequesting: false });
|
|
this.checkIsPayed(orderSn);
|
|
}, err => {
|
|
console.log('支付失败', err);
|
|
this.setData({ isPaying: false, isRequesting: false });
|
|
if (err && err.errMsg && err.errMsg.indexOf('cancel') !== -1) {
|
|
wx.showToast({ title: '支付已取消', icon: 'none' });
|
|
this.setData({ flg: 100 });
|
|
} else {
|
|
this.checkIsPayed(orderSn);
|
|
}
|
|
})
|
|
}, err => {
|
|
this.setData({ isPaying: false });
|
|
wx.hideLoading();
|
|
if (err.data && err.data.err_code == 30022) {
|
|
this.setData({
|
|
isWxLogin: true,
|
|
})
|
|
} else {
|
|
wx.showToast({ title: err.data.errMsg, icon: 'none' });
|
|
}
|
|
})
|
|
},
|
|
|
|
// 点击提示框确认
|
|
confirmOutDialog() {
|
|
// 出场
|
|
this.openDoor('000', false)
|
|
},
|
|
|
|
openDoor(orderSn, isEnter) {
|
|
wx.showLoading({
|
|
title: '正在开门...',
|
|
mask: true,
|
|
})
|
|
app.$api.generateBarcode({
|
|
venueId: this.data.venues.id,
|
|
enterFlag: this.data.venues.enterFlag,
|
|
orderSn: orderSn
|
|
}).then(res => {
|
|
wx.hideLoading();
|
|
this.setData({
|
|
flg: 0,
|
|
welcomeMsg: isEnter ? '欢迎光临,请入场' : '再见,请出场'
|
|
})
|
|
}, err => {
|
|
console.log(err)
|
|
wx.hideLoading();
|
|
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
|
|
})
|
|
})
|
|
}
|
|
});
|
|
}
|
|
|
|
})
|