const app = getApp(); Page({ data: { background: 'transparent', focus: false, Search: '', pagination: { page: 1, pages: 1, count: 1, }, list: [], }, onLoad() { app.waitLogin().then(() => { this.setData({ focus: true, }); }); }, handleInput() { this.setData({ 'pagination.count': 1, }); }, handleSearch() { if (!this.data.Search) { wx.showToast({ title: '请输入搜索内容', icon: 'none', }); return; } this.getList(); }, getList(newPage = 1) { wx.ajax({ method: 'GET', url: `?r=shizhong/book/search-list`, data: { page: newPage, Search: this.data.Search, }, }).then((res) => { const list = res.page === 1 ? res.list : [...this.data.list, ...res.list]; this.setData({ list, pagination: { page: res.page, pages: res.pages, count: res.count, }, }); }); }, onReachBottom() { const { page, pages } = this.data.pagination; if (pages > page && this.data.list.length) { this.getList(page + 1); } }, handleBack() { wx.navigateBack(); }, handleDetail(e) { const { id, cid } = e.currentTarget.dataset; const backPath = `/pages/article/index?id=${id}&cid=${cid}`; app.waitLogin(false, true, backPath).then(() => { wx.navigateTo({ url: backPath, }); }); }, }); export {};