fix bugs
This commit is contained in:
@@ -100,6 +100,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import competitionAPI from '@/api/competition.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -112,58 +114,176 @@ export default {
|
||||
areaPickerValue: [0],
|
||||
dateOptions: ['2025-04-09', '2025-04-10', '2025-04-11'],
|
||||
areaOptions: ['乌鲁木齐', '天津市', '北京市'],
|
||||
eventList: [
|
||||
{
|
||||
id: 1,
|
||||
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
|
||||
location: '天津市-天津市体育中心',
|
||||
registerTime: '2025.02.01-2025.02.10',
|
||||
matchTime: '2025.02.01-2025.02.10',
|
||||
registerCount: '25212',
|
||||
status: 'open'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: '2025年全国武术套路锦标赛',
|
||||
location: '天津市-天津市体育中心',
|
||||
registerTime: '2025.02.01-2025.02.10',
|
||||
matchTime: '2025.02.01-2025.02.10',
|
||||
registerCount: '25212',
|
||||
status: 'finished'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
|
||||
location: '天津市-天津市体育中心',
|
||||
registerTime: '2025.02.01-2025.02.10',
|
||||
matchTime: '2025.02.01-2025.02.10',
|
||||
registerCount: '25212',
|
||||
status: 'open'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
|
||||
location: '天津市-天津市体育中心',
|
||||
registerTime: '2025.02.01-2025.02.10',
|
||||
matchTime: '2025.02.01-2025.02.10',
|
||||
registerCount: '25212',
|
||||
status: 'open'
|
||||
}
|
||||
]
|
||||
eventList: [],
|
||||
// 分页参数
|
||||
pageParams: {
|
||||
current: 1,
|
||||
size: 20
|
||||
},
|
||||
hasMore: true
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
this.loadEventList()
|
||||
},
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
this.pageParams.current = 1
|
||||
this.loadEventList(true)
|
||||
},
|
||||
// 上拉加载更多
|
||||
onReachBottom() {
|
||||
if (this.hasMore) {
|
||||
this.pageParams.current++
|
||||
this.loadEventList(false, true)
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
filteredEventList() {
|
||||
return this.eventList.filter(item => {
|
||||
if (this.searchText && !item.title.includes(this.searchText)) {
|
||||
return false;
|
||||
}
|
||||
// 可以添加更多筛选条件
|
||||
return true;
|
||||
});
|
||||
// 前端筛选(作为后备方案)
|
||||
let list = this.eventList
|
||||
|
||||
// 如果有搜索关键字,进行前端筛选
|
||||
if (this.searchText) {
|
||||
list = list.filter(item => item.title && item.title.includes(this.searchText))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
},
|
||||
// 监听搜索关键字变化
|
||||
watch: {
|
||||
searchText(newVal, oldVal) {
|
||||
// 防抖处理
|
||||
clearTimeout(this.searchTimer)
|
||||
this.searchTimer = setTimeout(() => {
|
||||
this.pageParams.current = 1
|
||||
this.loadEventList(true)
|
||||
}, 500)
|
||||
},
|
||||
selectedDate() {
|
||||
this.pageParams.current = 1
|
||||
this.loadEventList(true)
|
||||
},
|
||||
selectedArea() {
|
||||
this.pageParams.current = 1
|
||||
this.loadEventList(true)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 加载赛事列表
|
||||
* @param {Boolean} refresh 是否刷新(重置列表)
|
||||
* @param {Boolean} loadMore 是否加载更多(追加列表)
|
||||
*/
|
||||
async loadEventList(refresh = false, loadMore = false) {
|
||||
try {
|
||||
// 构建查询参数
|
||||
const params = {
|
||||
current: this.pageParams.current,
|
||||
size: this.pageParams.size
|
||||
}
|
||||
|
||||
// 添加搜索关键字
|
||||
// 注意:后端接口参数名待确认,可能是 name/keyword/search
|
||||
if (this.searchText) {
|
||||
params.name = this.searchText
|
||||
}
|
||||
|
||||
// 添加地区筛选
|
||||
if (this.selectedArea) {
|
||||
params.location = this.selectedArea
|
||||
}
|
||||
|
||||
// 调用API
|
||||
const res = await competitionAPI.getCompetitionList(params)
|
||||
|
||||
console.log('赛事列表API返回:', 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 mappedList = list.map(item => {
|
||||
// 尝试多个可能的时间字段
|
||||
const regStartTime = item.registrationStartTime || item.registerStartTime || item.signUpStartTime
|
||||
const regEndTime = item.registrationEndTime || item.registerEndTime || item.signUpEndTime
|
||||
const startTime = item.startTime || item.competitionStartTime || item.beginTime
|
||||
const endTime = item.endTime || item.competitionEndTime || item.finishTime
|
||||
|
||||
return {
|
||||
id: item.id,
|
||||
title: item.name || item.title || item.competitionName || '未命名赛事',
|
||||
location: item.location || item.address || item.venue || '待定',
|
||||
registerTime: this.formatTimeRange(regStartTime, regEndTime) ||
|
||||
item.registerTime || item.registrationPeriod || '待定',
|
||||
matchTime: this.formatTimeRange(startTime, endTime) ||
|
||||
item.matchTime || item.competitionTime || '待定',
|
||||
registerCount: item.registrationCount || item.registerCount || item.signUpCount || '0',
|
||||
status: this.getStatus(item.status)
|
||||
}
|
||||
})
|
||||
|
||||
console.log('格式化后的赛事列表:', mappedList)
|
||||
|
||||
// 刷新或加载更多
|
||||
if (refresh || !loadMore) {
|
||||
this.eventList = mappedList
|
||||
} else {
|
||||
this.eventList = [...this.eventList, ...mappedList]
|
||||
}
|
||||
|
||||
// 判断是否还有更多数据
|
||||
this.hasMore = this.eventList.length < total
|
||||
|
||||
// 停止下拉刷新
|
||||
if (refresh) {
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载赛事列表失败:', err)
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 格式化时间范围
|
||||
*/
|
||||
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: 已结束
|
||||
if (status === 3 || status === '3' || status === 'finished') {
|
||||
return 'finished'
|
||||
}
|
||||
return 'open'
|
||||
},
|
||||
|
||||
handleDateChange(e) {
|
||||
this.datePickerValue = e.detail.value;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user