const app = getApp() const util = require('../../../utils/util') Page({ data: { records: [], loading: false, page: 1, pageSize: 20, hasMore: true }, onLoad() { this.fetchRecords() }, onShow() { // 门店切换后刷新数据 if (app.globalData.storeChanged) { app.globalData.storeChanged = false this.setData({ page: 1, hasMore: true, records: [] }) 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 => Object.assign({}, record, { createdAt: util.formatDate(record.createdAt) }) ) this.setData({ records: this.data.page === 1 ? records : this.data.records.concat(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() } })