66 lines
1.3 KiB
JavaScript
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()
|
|
}
|
|
})
|