yingsa/miniprogram/pages/match/history/index.js
2026-01-20 08:50:50 +08:00

66 lines
1.3 KiB
JavaScript

const app = getApp()
const util = require('../../../utils/util')
Page({
data: {
matches: [],
loading: false,
page: 1,
pageSize: 20,
hasMore: true
},
onLoad() {
this.fetchMatches()
},
onPullDownRefresh() {
this.setData({ page: 1, hasMore: true })
this.fetchMatches().then(() => {
wx.stopPullDownRefresh()
})
},
onReachBottom() {
if (this.data.hasMore && !this.data.loading) {
this.loadMore()
}
},
async fetchMatches() {
const currentStore = app.globalData.currentStore
if (!currentStore?.storeId) {
return
}
this.setData({ loading: true })
try {
const res = await app.request('/api/match/my-matches', {
store_id: currentStore.storeId,
page: this.data.page,
pageSize: this.data.pageSize
})
const matches = (res.data.list || []).map(match => ({
...match,
confirmedAt: util.formatDate(match.confirmedAt)
}))
this.setData({
matches: this.data.page === 1 ? matches : [...this.data.matches, ...matches],
hasMore: matches.length >= this.data.pageSize
})
} catch (e) {
console.error('获取比赛记录失败:', e)
} finally {
this.setData({ loading: false })
}
},
loadMore() {
this.setData({ page: this.data.page + 1 })
this.fetchMatches()
}
})