新增e2e测试脚本,修复部分问题
This commit was merged in pull request #51.
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">人数</text>
|
||||
<text class="info-value">{{ course.currentMembers || 0 }} / {{ course.maxMembers || 0 }}</text>
|
||||
<text class="info-value">{{ getMemberCount(course) }} / {{ course.maxMembers || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -71,6 +71,7 @@
|
||||
totalHeaderHeight: 0,
|
||||
loading: true,
|
||||
courses: [],
|
||||
memberCounts: {},
|
||||
currentTab: 'all',
|
||||
tabs: [
|
||||
{ label: '全部', value: 'all' },
|
||||
@@ -146,6 +147,8 @@
|
||||
if (!a._isToday && b._isToday) return 1
|
||||
return 0
|
||||
})
|
||||
// 实时获取每门课的预约人数
|
||||
this.fetchRealMemberCounts(list)
|
||||
} catch (e) {
|
||||
console.error('加载课程失败:', e)
|
||||
uni.showToast({ title: '加载课程失败', icon: 'none' })
|
||||
@@ -154,6 +157,32 @@
|
||||
}
|
||||
},
|
||||
|
||||
async fetchRealMemberCounts(list) {
|
||||
const results = await Promise.allSettled(
|
||||
list.map(course =>
|
||||
coachApi.getCourseBookings(course.id).then(bookings => {
|
||||
const arr = Array.isArray(bookings) ? bookings : []
|
||||
return {
|
||||
courseId: course.id,
|
||||
count: arr.filter(b => b.status === '0' || b.status === '2').length
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
const counts = {}
|
||||
results.forEach(r => {
|
||||
if (r.status === 'fulfilled') {
|
||||
counts[r.value.courseId] = r.value.count
|
||||
}
|
||||
})
|
||||
this.memberCounts = counts
|
||||
},
|
||||
|
||||
getMemberCount(course) {
|
||||
const real = this.memberCounts[course.id]
|
||||
return real != null ? real : (course.currentMembers || 0)
|
||||
},
|
||||
|
||||
formatDate(timeStr) {
|
||||
if (!timeStr) return '--'
|
||||
return timeStr.substring(0, 10)
|
||||
|
||||
Reference in New Issue
Block a user