const app = getApp(); Page({ /** * 页面的初始数据 */ data: { active: 0, activeName: "FavoriteBookCity", tabList: [ { label: '图书', key: 0, linkType: 'FavoriteBookCity', }, { label: '课程', key: 1, linkType: 'Favoriteclass', } ], list: [], //分页 page: 1, limit: 18, pageTotalCount: 0, bottomLoading: false, isMoreData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, skeletonLoding: true, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); this.getDataList(false); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, tabBookClick(item) { let that = this; let info = this.data.tabList[item.detail.value] that.setData({ skeletonLoding: true, active: item.detail.value, activeName: info.linkType, list: [], page: 1, bottomLoading: false, isMoreData: false, }) that.getDataList(false); }, getDataList(isReachBottom) { app.MG.store.getProductList({ handelEBooK: true, queryType: "AppUserProductLink", linkType: this.data.activeName, paging: { start: this.data.page * this.data.limit - this.data.limit, size: this.data.limit }, fields: { author: [] } }).then((res) => { try { if (res.datas.length > 0) { let dataList = res.datas; //触底加载新数据并保留老数据 if (isReachBottom) { dataList = [...this.data.list, ...dataList] //将新数据加入老数据中 } this.setData({ list: dataList, pageTotalCount: res.total, bottomLoading: false, isMoreData: dataList.length > 0 ? false : true, skeletonLoding: false, loading: false }) } else { this.setData({ skeletonLoding: false, loading: false }) } } catch (error) { console.log(error) } }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this._freshing) return this.setData({ // list: [], page: 1, limit: 18, pageTotalCount: 0, bottomLoading: false, isMoreData: false }) this._freshing = true; this.setData({ triggered: false, }) this.getDataList(false); this._freshing = false }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { this.setData({ bottomLoading: true, isMoreData: false }) let bool = false; if (this.data.pageTotalCount > this.data.list.length) { bool = true; this.setData({ page: this.data.page + 1, }) } else { setTimeout(() => { this.setData({ bottomLoading: false, isMoreData: true }) }, 100) return false; } this.getDataList(bool); }, setCoolect(itemData) { let that = this; let info = itemData.currentTarget.dataset.info; wx.showModal({ title: '提示', //提示的标题 content: '确定要取消收藏?', //提示的内容 success: function (res) { if (res.confirm) { app.MG.store .delProductLink({ productIds: [info.id], linkType: that.data.activeName, }) .then(() => { wx.showToast({ title: "收藏已取消", icon: 'success', duration: 1000, }) that.getDataList(false) }); } else if (res.cancel) { console.log('用户点击了取消') } } }) }, goBookDetails(e) { const { book } = e.currentTarget.dataset; wx.navigateTo({ url: `/packageBookService/pages/bookServices/detail/index?id=${book.id}&name=${book.name}`, }); }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })