const app = getApp(); let iPageIndex = 1 // 当前第几页,0代表第一页 let iPageSize = 10 //每页显示多少数据 Page({ data: { imageUrl: getApp().globalData.imageUrl, id: "", source: "", user_author: "", sourcetime: "", title: "", content: "", affections: "", crisis: "", ssim: "", dataList: [], //放置返回数据的数组 loadMore: false, //"上拉加载"的变量,默认false,隐藏 loadAll: false, //“没有数据”的变量,默认false,隐藏 totalNum: 0 }, onLoad() { wx.setNavigationBarTitle({ title: '详情' }) let pages = getCurrentPages(); let currentPage = pages[pages.length - 1] let options = currentPage.options this.setData({ id: options.id }) }, onShow() { this.getData().then(() => { this.getLikeData() }) }, //页面上拉触底事件的处理函数 onReachBottom: function () { console.log("上拉触底事件") let that = this if (!that.data.loadMore) { that.setData({ loadMore: true, //加载中 loadAll: false //是否加载完所有数据 }); //加载更多,这里做下延时加载 that.getLikeData(); } }, searchScrollLower() { this.getLikeData(); }, getData() { return new Promise((resolve, reject) => { app.globalData.request({ action: 'getDataById', sId: this.data.id, sType: 'ZhuTiFenXiBl', token: wx.getStorageSync('token') || 't%2BrswgjvzGM=' }).then(res => { let arr = res || []; if (arr.length > 0) { let data = arr[0]; this.setData({ source: data._source.source, user_author: data._source.user_author, sourcetime: data._source.sourcetime, title: data._source.title, content: data._source.content, affections: data._source.affections, crisis: data._source.crisis, ssim: data._source.ssim }) } resolve(true) }).catch(() => { reject(false) }) }) }, getLikeData() { let sTimeType = wx.getStorageSync('sTimeType') || 34; let sStartTime = ""; let sEndTime = ""; if (sTimeType == 4) { sStartTime = wx.getStorageSync('sStartTime') || ''; sEndTime = wx.getStorageSync('sEndTime') || ''; } let obj = { action: "getSimilarityData", sId: this.data.id, sSsim: this.data.sSsim, sType: "ZhuTiFenXiBl", iPageIndex: iPageIndex, iPageSize: iPageSize, token: wx.getStorageSync('token') || 't%2BrswgjvzGM=', sTimeType: sTimeType, sStartTime: sStartTime, sEndTime: sEndTime } //第一次加载数据 if (iPageIndex == 1) { this.setData({ loadMore: true, //把"上拉加载"的变量设为true,显示 loadAll: false //把“没有数据”设为false,隐藏 }) } app.globalData.request(obj, (database) => { this.setData({ totalNum: database.totalNum }) }).then(res => { if (res && res.length > 0) { iPageIndex++; //把新请求到的数据添加到dataList里 let list = this.data.dataList.concat(res); this.setData({ dataList: list, //获取数据数组 loadMore: false //把"上拉加载"的变量设为false,显示 }); if (res.length < pageSize) { this.setData({ loadMore: false, //隐藏加载中。。 loadAll: true //所有数据都加载完了 }); } } else { this.setData({ loadAll: true, //把“没有数据”设为true,显示 loadMore: false //把"上拉加载"的变量设为false,隐藏 }); } }) } })