const app = getApp(); const util = require("../../../utils/util"); Page({ data: { articles: [], loading: false, }, onLoad() { this.fetchArticles(); }, onPullDownRefresh() { this.fetchArticles().finally(() => { wx.stopPullDownRefresh(); }); }, async fetchArticles() { this.setData({ loading: true }); try { // 活动公告:按当前门店只拉取公告分类最近 10 条 const storeId = app.globalData.currentStore && app.globalData.currentStore.storeId; const data = { category: "notice", limit: 10 }; if (storeId) { data.store_id = storeId; } const res = await app.request("/api/article", data); const raw = res.data || []; const articles = raw.map((a) => ({ id: a.id, title: a.title, category: a.category, categoryName: a.category === "notice" ? "活动公告" : "", summary: a.summary, timeText: a.createdAt ? util.formatDate(a.createdAt) : "", isTop: !!a.isTop, })); this.setData({ articles }); } catch (e) { console.error("获取文章列表失败:", e); } finally { this.setData({ loading: false }); } }, goDetail(e) { const id = e.currentTarget.dataset.id; if (!id) return; wx.navigateTo({ url: `/pages/article/detail/index?id=${id}`, }); }, });