This commit is contained in:
2025-12-12 01:44:41 +08:00
parent 21abcaff53
commit 2f1d732a36
46 changed files with 7756 additions and 484 deletions

View File

@@ -63,6 +63,8 @@
<script>
import CustomTabs from '../../components/custom-tabs/custom-tabs.vue';
import registrationAPI from '@/api/registration.js'
import competitionAPI from '@/api/competition.js'
export default {
components: {
@@ -72,40 +74,30 @@ export default {
return {
tabs: ['全部', '待开始', '进行中', '已结束'],
currentTab: 0,
eventList: [
{
id: 1,
status: 'ongoing',
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
location: '天津市-天津市体育中心',
matchTime: '2025.02.01-2025.02.10',
projects: '男子组剑术、男子组太极拳',
contact: '18666666666',
participants: '张三、李四四、王二、张三、李四四、张三、李四四、王二、张三、李四四'
},
{
id: 2,
status: 'pending',
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
location: '天津市-天津市体育中心',
matchTime: '2025.02.01-2025.02.10',
projects: '男子组剑术、男子组太极拳',
contact: '18666666666',
participants: '张三、李四四、王二、张三、李四四、张三、李四四、王二、张三、李四四'
},
{
id: 3,
status: 'finished',
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
location: '天津市-天津市体育中心',
matchTime: '2025.02.01-2025.02.10',
projects: '男子组剑术、男子组太极拳',
contact: '18666666666',
participants: '张三、李四四、王二、张三、李四四、张三、李四四、王二、张三、李四四'
}
]
eventList: [],
// 分页参数
pageParams: {
current: 1,
size: 20
},
hasMore: true
};
},
onLoad() {
this.loadRegistrationList()
},
// 下拉刷新
onPullDownRefresh() {
this.pageParams.current = 1
this.loadRegistrationList(true)
},
// 上拉加载更多
onReachBottom() {
if (this.hasMore) {
this.pageParams.current++
this.loadRegistrationList(false, true)
}
},
computed: {
filteredList() {
if (this.currentTab === 0) {
@@ -120,8 +112,182 @@ export default {
}
},
methods: {
/**
* 加载我的报名列表
* @param {Boolean} refresh 是否刷新(重置列表)
* @param {Boolean} loadMore 是否加载更多(追加列表)
*/
async loadRegistrationList(refresh = false, loadMore = false) {
try {
const params = {
current: this.pageParams.current,
size: this.pageParams.size
}
// 添加状态筛选
if (this.currentTab > 0) {
params.status = this.currentTab
}
const res = await registrationAPI.getRegistrationList(params)
console.log('=== 我的报名列表 - 后端返回的原始数据 ===')
console.log('完整响应:', res)
let list = []
let total = 0
// 处理分页数据
if (res.records) {
list = res.records
total = res.total || 0
} else if (Array.isArray(res)) {
list = res
total = res.length
}
// 为每条报名记录获取详情(包含关联数据)
const detailPromises = list.map(item => this.getRegistrationDetailData(item))
const mappedList = await Promise.all(detailPromises)
// 过滤掉获取失败的记录
const validList = mappedList.filter(item => item !== null)
// 刷新或加载更多
if (refresh || !loadMore) {
this.eventList = validList
} else {
this.eventList = [...this.eventList, ...validList]
}
// 判断是否还有更多数据
this.hasMore = this.eventList.length < total
// 停止下拉刷新
if (refresh) {
uni.stopPullDownRefresh()
}
} catch (err) {
console.error('加载报名列表失败:', err)
uni.stopPullDownRefresh()
}
},
/**
* 获取单条报名记录的详细信息
* @param {Object} orderItem 订单基本信息
* @returns {Promise<Object>} 包含完整信息的记录
*/
async getRegistrationDetailData(orderItem) {
try {
console.log('=== 获取报名详情 ===', orderItem.id)
// 获取报名详情
const detail = await registrationAPI.getRegistrationDetail(orderItem.id)
console.log('报名详情:', detail)
// 获取赛事详情
let competitionInfo = null
if (orderItem.competitionId || detail.competitionId) {
const competitionId = orderItem.competitionId || detail.competitionId
competitionInfo = await competitionAPI.getCompetitionDetail(competitionId)
console.log('赛事详情:', competitionInfo)
}
// 构建映射数据
const mapped = {
id: orderItem.id,
status: this.getStatus(orderItem.status),
title: competitionInfo?.name || detail.competitionName || '未知赛事',
location: competitionInfo?.location || competitionInfo?.address || detail.location || '',
matchTime: this.formatTimeRange(
competitionInfo?.startTime || detail.startTime,
competitionInfo?.endTime || detail.endTime
) || '',
projects: detail.projectNames || this.formatProjects(detail.projects || detail.projectList) || '',
contact: orderItem.contactPhone || detail.contactPhone || '',
participants: detail.athleteNames || this.formatParticipants(detail.athletes || detail.athleteList) || ''
}
console.log('映射后的数据:', mapped)
return mapped
} catch (err) {
console.error('获取报名详情失败:', err, orderItem.id)
// 返回基本信息,避免整个记录丢失
return {
id: orderItem.id,
status: this.getStatus(orderItem.status),
title: '获取详情失败',
location: '',
matchTime: '',
projects: '',
contact: orderItem.contactPhone || '',
participants: `${orderItem.totalParticipants || 0}`
}
}
},
/**
* 格式化时间范围
*/
formatTimeRange(startTime, endTime) {
if (!startTime || !endTime) return ''
const formatDate = (dateStr) => {
if (!dateStr) return ''
const date = new Date(dateStr)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}.${month}.${day}`
}
return `${formatDate(startTime)}-${formatDate(endTime)}`
},
/**
* 获取报名状态
*/
getStatus(status) {
// 1: 待开始, 2: 进行中, 3: 已结束
const statusMap = {
1: 'pending',
2: 'ongoing',
3: 'finished',
'pending': 'pending',
'ongoing': 'ongoing',
'finished': 'finished'
}
return statusMap[status] || 'pending'
},
/**
* 格式化报名项目
*/
formatProjects(projects) {
if (!projects) return ''
if (Array.isArray(projects)) {
return projects.map(p => p.name || p.projectName).join('、')
}
return projects
},
/**
* 格式化参赛选手
*/
formatParticipants(athletes) {
if (!athletes) return ''
if (Array.isArray(athletes)) {
return athletes.map(a => a.name || a.athleteName).join('、')
}
return athletes
},
handleTabChange(index) {
this.currentTab = index;
// 切换tab时重新加载
this.pageParams.current = 1
this.loadRegistrationList(true)
},
getStatusClass(status) {
return {