Files
venue_wx/pages/myBookings/index.js
2021-05-23 20:59:20 +08:00

231 lines
4.9 KiB
JavaScript

// pages/myBookings/index.js
const app = getApp();
let orderSn = ""
let orderLimit = 48;
Page({
/**
* 页面的初始数据
*/
data: {
isSignIn: false,
memberLessonTicket: {},
showDeleteDialog: false,
isGoHome: false,
endDate: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
if (options.scene) {
app.$api.memberLessonTicketsSing({
coachId: options.scene
}).then(res => {
orderSn = res.orderSn;
wx.showToast({
title: '签到成功',
duration: 2000
})
let that = this;
setTimeout(function() {
that.getData();
}, 2000)
}, err => {
setTimeout(function() {
if (!options.orderSn) {
wx.redirectTo({
url: '/pages/home/index',
})
} else {
wx.redirectTo({
url: '/pages/myBookings/index?orderSn=' + options.orderSn,
})
}
}, 2000)
})
} else {
orderSn = options.orderSn;
this.getData();
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
let pages = getCurrentPages();
this.setData({
isGoHome: pages.length == 1
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
return {
title: '智慧云馆'
}
},
// 取消预约
cancelBooking() {
if (!this.data.isSignIn) {
this.setData({
showDeleteDialog: true
})
return;
} else {
wx.showToast({
title: '距离开课' + orderLimit + '小时内不得取消',
icon: 'none',
})
}
},
// 我要签到
signIn() {
let that = this;
// if (!this.data.isSignIn) {
// this.setData({
// showDeleteDialog: true
// })
// return;
// }
// let currentDate = new Date().getTime();
// let startDate = new Date(this.data.memberLessonTicket.venueLesson.date.replace(/-/g, "/") + ' ' + this.data.memberLessonTicket.venueLesson.startTime).getTime();
// if (currentDate < startDate) {
// wx.showToast({
// title: '课程还未开始',
// icon: 'none',
// })
// return;
// }
wx.scanCode({
onlyFromCamera: true,
success: function(res) {
if (!res.path) {
wx.showToast({
title: '二维码错误',
icon: 'none',
})
return;
}
wx.redirectTo({
url: '/' + res.path + '&orderSn=' + orderSn,
})
// that.setData({
// isSignIn: true
// })
},
})
},
// 获取数据
getData() {
app.$api.memberLessonTicketsDetail({
orderSn: orderSn
}).then(res => {
let currentDate = new Date().getTime();
let startDate = currentDate;
if (res.memberLessonTicket.venueLesson.orderLimit){
orderLimit = res.memberLessonTicket.venueLesson.orderLimit;
}
if (res.memberLessonTicket) {
startDate = new Date(res.memberLessonTicket.venueLesson.date.replace(/-/g, "/") + ' ' + res.memberLessonTicket.venueLesson.startTime).getTime();
}
if (!res.memberLessonTicket) {
wx.navigateBack({
delta: 1,
})
}
this.setData({
memberLessonTicket: res.memberLessonTicket,
isSignIn: (startDate - currentDate) / 1000 / 60 / 60 < orderLimit,
})
}, err => {
})
},
// 取消弹框
cancelDeleteDialog() {
this.setData({
showDeleteDialog: false
})
},
// 确认删除
confirmDeleteDialog() {
app.$api.memberLessonTicketsCancel({
orderSn: this.data.memberLessonTicket.orderSn
}).then(res => {
wx.showToast({
title: '取消成功',
})
this.setData({
showDeleteDialog: false
})
this.getData();
}, err => {
this.setData({
showDeleteDialog: false
})
});
},
// 打开导航,
opnGPS() {
wx.openLocation({
latitude: Number(this.data.memberLessonTicket.venueLesson.latitude),
longitude: Number(this.data.memberLessonTicket.venueLesson.longitude),
name: this.data.memberLessonTicket.venueLesson.name,
address: this.data.memberLessonTicket.venueLesson.address,
})
},
// 点击图片
clickImage() {
wx.previewImage({
urls: [this.data.memberLessonTicket.venueLesson.coach.wechatCode],
})
}
})