实现用户登录→查询团课→预约团课→扫码签到→后台查看数据闭环
This commit is contained in:
@@ -125,6 +125,8 @@
|
||||
|
||||
<script>
|
||||
const courseApi = require('../../api/course')
|
||||
const bookingApi = require('../../api/booking')
|
||||
const store = require('../../store/index')
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -170,6 +172,10 @@
|
||||
this.loadCourses()
|
||||
this.loadTypes()
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
Promise.all([this.loadCourses(), this.loadTypes()])
|
||||
.finally(() => { uni.stopPullDownRefresh() })
|
||||
},
|
||||
computed: {
|
||||
// 将类型列表按每行 COLS_PER_ROW 个拆分为二维数组
|
||||
typeRows() {
|
||||
@@ -325,7 +331,31 @@
|
||||
},
|
||||
switchSort(value) { this.currentSort = value },
|
||||
goToDetail(course) { uni.navigateTo({ url: '/pages/course-detail/course-detail?id=' + course.id }) },
|
||||
bookCourse(course) { if (course.canBook) uni.navigateTo({ url: '/pages/course-detail/course-detail?id=' + course.id }) }
|
||||
async bookCourse(course) {
|
||||
if (!course.canBook) return
|
||||
const memberInfo = store.getMemberInfo()
|
||||
const memberId = memberInfo ? (memberInfo.memberId || memberInfo.id) : null
|
||||
if (!memberId) {
|
||||
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.showLoading({ title: '预约中...' })
|
||||
try {
|
||||
await bookingApi.bookCourse({
|
||||
courseId: course.id,
|
||||
memberId: memberId
|
||||
})
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '预约成功', icon: 'success' })
|
||||
// 跳转到「我的课程」页面
|
||||
setTimeout(() => { uni.switchTab({ url: '/pages/my-courses/my-courses' }) }, 1000)
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
console.error('预约失败:', e)
|
||||
const msg = (e.data && e.data.message) || '预约失败,请重试'
|
||||
uni.showToast({ title: msg, icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user