const app = getApp(); const svc = require('../../services/exercise'); Page({ data: { statusBarHeight: 20, slug: '', collection: null, exercises: [], loading: true, page: 1, pageSize: 30, total: 0 }, onLoad(query) { const slug = query.slug || ''; this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20, slug }); this.load(); }, load() { this.setData({ loading: true }); svc.getCollectionExercises(this.data.slug, { page: this.data.page, pageSize: this.data.pageSize }).then((res) => { this.setData({ collection: res.collection, exercises: (res && res.items) || [], total: (res && res.total) || 0, loading: false }); }).catch(() => { this.setData({ loading: false }); }); }, onExercise(e) { wx.navigateTo({ url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id) }); } });