const app = getApp(); const util = require("../../../utils/util"); Page({ data: { list: [], loading: false, }, onLoad() { this.fetchList(); }, onPullDownRefresh() { this.fetchList().finally(() => { wx.stopPullDownRefresh(); }); }, async fetchList() { const currentStore = app.globalData.currentStore; const storeId = currentStore ? currentStore.storeId : null; this.setData({ loading: true }); try { const res = await app.request("/api/match/display-list", { store_id: storeId, days: 7, limit: 100, }); const raw = res.data || []; const list = raw.map((item) => { const time = item.startTime || item.createdAt || item.endTime || null; const stageName = item.stageName || ""; const statusName = item.statusName || ""; // 如果阶段名和状态名一样(例如都是“已结束”),只显示一次状态 const showStage = !!stageName && stageName !== statusName; // 根据状态生成样式类型 let statusType = "pending"; switch (item.status) { case 1: statusType = "ongoing"; break; case 2: statusType = "finished"; break; case 3: statusType = "cancelled"; break; default: statusType = "pending"; } return { ...item, timeText: time ? util.formatDate(time) : "", stageName, statusName, showStage, statusType, }; }); this.setData({ list }); } catch (e) { console.error("获取最近比赛列表失败:", e); } finally { this.setData({ loading: false }); } }, goDetail(e) { const match = e.currentTarget.dataset.match; if (!match) return; if (match.type === 1) { wx.navigateTo({ url: `/pages/match/challenge-detail/index?id=${match.id}`, }); } else { wx.navigateTo({ url: `/pages/match/ranking/index?code=${match.matchCode}`, }); } }, });