60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
const app = getApp()
|
|
const util = require('../../../utils/util')
|
|
|
|
Page({
|
|
data: {
|
|
records: [],
|
|
loading: false,
|
|
page: 1,
|
|
pageSize: 20,
|
|
hasMore: true
|
|
},
|
|
|
|
onLoad() {
|
|
this.fetchRecords()
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.setData({ page: 1, hasMore: true })
|
|
this.fetchRecords().then(() => {
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
|
|
onReachBottom() {
|
|
if (this.data.hasMore && !this.data.loading) {
|
|
this.loadMore()
|
|
}
|
|
},
|
|
|
|
async fetchRecords() {
|
|
this.setData({ loading: true })
|
|
|
|
try {
|
|
const res = await app.request('/api/points/records', {
|
|
page: this.data.page,
|
|
pageSize: this.data.pageSize
|
|
})
|
|
|
|
const records = (res.data.list || []).map(record => ({
|
|
...record,
|
|
createdAt: util.formatDate(record.createdAt)
|
|
}))
|
|
|
|
this.setData({
|
|
records: this.data.page === 1 ? records : [...this.data.records, ...records],
|
|
hasMore: records.length >= this.data.pageSize
|
|
})
|
|
} catch (e) {
|
|
console.error('获取积分记录失败:', e)
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
loadMore() {
|
|
this.setData({ page: this.data.page + 1 })
|
|
this.fetchRecords()
|
|
}
|
|
})
|