yingsa/miniprogram/pages/match/history/index.js
ethanfly 98f9e64d91 refactor: Enhance store and user management features
- Updated user information retrieval to support store-specific points and ladder user data.
- Refactored store initialization logic to prioritize last selected store.
- Improved API endpoints for fetching matches and user data, ensuring compatibility with store context.
- Adjusted UI components to display store-related information consistently across various pages.
- Enhanced error handling and data fetching logic for better user experience.
2026-02-07 11:09:37 +08:00

91 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const app = getApp();
const util = require("../../../utils/util");
Page({
data: {
matches: [],
loading: false,
page: 1,
pageSize: 20,
hasMore: true,
},
onLoad() {
this.fetchMatches();
},
onShow() {
// 门店切换后刷新数据
if (app.globalData.storeChanged) {
app.globalData.storeChanged = false;
this.setData({ page: 1, hasMore: true, matches: [] });
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() {
this.setData({ loading: true });
try {
// 不传 store_id获取全部门店的比赛记录
const res = await app.request("/api/match/my-matches", {
page: this.data.page,
pageSize: this.data.pageSize,
});
const matches = (res.data.list || []).map((match) => {
// 确保 powerChange 是数字类型,移除可能存在的加号和其他非数字字符
let powerChange = match.powerChange;
if (powerChange != null && powerChange !== undefined) {
// 如果是字符串,移除所有加号、空格等非数字字符(保留负号)
if (typeof powerChange === "string") {
// 保留负号,移除所有加号和其他字符
const cleaned = powerChange.replace(/\+/g, "").trim();
powerChange = parseFloat(cleaned) || 0;
}
// 确保是数字类型
powerChange = Number(powerChange);
// 如果是 NaN设为 0
if (isNaN(powerChange)) {
powerChange = 0;
}
} else {
powerChange = 0;
}
return Object.assign({}, match, {
powerChange: powerChange,
confirmedAt: util.formatDate(match.confirmedAt),
});
});
this.setData({
matches:
this.data.page === 1 ? matches : this.data.matches.concat(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();
},
});