const store = require('../../utils/store.js'); const recordTypes = require('../../utils/recordTypes.js'); // 这一页只干一件事:把后端配置的记录事项按分组列出来,点一个进添加页。 // 原来它还带着健康洞察、体重趋势、健康时间轴——那三块搬到 pages/history 了, // 从报告页进。一个「我要记一笔」的页面上摆着三块只读图表, // 用户每次都得先滚过去才能找到要点的东西。 Page({ data: { pet: {}, typeGroups: [], sheetShow: false, sheetType: '' }, onLoad() { this._unsub = store.subscribe((pet) => this.setData({ pet })); }, onUnload() { if (this._unsub) this._unsub(); }, onShow() { this.loadTypes(); store .ready() .then(() => this.setData({ pet: store.getPet() })) .catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' })); }, loadTypes() { if (this.data.typeGroups.length) return; recordTypes .load() .then((groups) => this.setData({ typeGroups: groups })) .catch(() => {}); }, goAdd(e) { wx.navigateTo({ url: '/pages/addrecord/addrecord?type=' + e.currentTarget.dataset.type }); }, // 没建档时要能建档,所以这页留一个只用于 addPet 的弹层 onAddPet() { this.setData({ sheetType: 'addPet', sheetShow: true }); }, closeSheet() { this.setData({ sheetShow: false }); }, onShareAppMessage() { return { title: '用肉垫计划记录毛孩子的成长', path: '/pages/record/record' }; }, onShareTimeline() { return { title: '用肉垫计划记录毛孩子的成长' }; }, });