import R from '../../utils/request'; import C from '../../utils/constant'; Page({ data: { cdnHost: C.cdnHost, list: [], page: 1, listEndText: '', }, onShow() { this.getTabBar().init(); }, onLoad() { this.init(); }, init() { this.fetchList(1); }, fetchList(page) { R.get('/index.php/api/v1/news_list', { page }).then(({ model }) => { const list = []; model.forEach(item => { list.push({ ...item, }); }); if (list.length == 0) { this.setData({ listEndText: '没有更多了' }); } else { this.setData({ listEndText: '点击加载更多。。。' }); } if (page == 1) { this.setData({ list ,page}); } else { const list2 = this.data.list.concat(list); this.setData({ list: list2,page }); } }); }, loadMore() { const { page, listEndText } = this.data; if (listEndText == '点击加载更多。。。') { this.fetchList(page + 1); } }, goDetail(e) { const { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/detail/detail?id=${id}` }); }, refresh() { this.fetchList(1); wx.showToast({ icon: 'none', title: '刷新成功' }); }, // 下拉刷新 onPullDownRefresh() { this.init(); wx.stopPullDownRefresh(); }, });