import moment from 'moment' const app = getApp(); import { getTopicMsgCmsItemFile } from '../../../assets/js/middleGround/tool.js' Page({ /** * 页面的初始数据 */ data: { list: [], //分页 page: 1, limit: 10, pageTotalCount: 0, bottomLoading: false, isMoreData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, skeletonLoding: true, worksInfo: [], info: {}, visible: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); this.getType() }, getType() { const data = { refCodes: ['jsek_publicationApplication'] } app.MG.resource.getCmsTypeByRefCode(data).then((res) => { this.setData({ worksInfo: res[0].cmsTypeLinks[0].children, }) this.getDataList(false) }) }, getDataList(isReachBottom) { app.MG.ugc.getTopicMessageList({ appRefCode: app.config.appRefCode, topicIdOrRefCode: 'bookApplication', start: this.data.page * this.data.limit - this.data.limit, size: this.data.limit, sort: { type: "Desc", field: "CreateDate" } }) .then(res => { try { if (res.datas.length > 0) { res.datas.forEach((item) => { item.createDate = moment(item.createDate).format("YYYY-MM-DD"); let info = getTopicMsgCmsItemFile(this.data.worksInfo, item.cmsItemDataList) if (info) { item.info = info } }); let dataList = res.datas; //触底加载新数据并保留老数据 if (isReachBottom) { dataList = [...this.data.list, ...dataList] //将新数据加入老数据中 } this.setData({ list: dataList, pageTotalCount: res.totalSize, bottomLoading: false, isMoreData: dataList.length > 0 ? false : true, skeletonLoding: false, }) } else { this.setData({ skeletonLoding: false, }) } } catch (error) { console.log(error) } }) }, toList(itemData) { let info = itemData.currentTarget.dataset.info; this.setData({ info: info.info, visible: true }) }, onVisibleChange(e) { this.setData({ visible: e.detail.visible, }); }, onClose() { this.setData({ visible: false, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this._freshing) return this.setData({ page: 1, limit: 10, 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); }, // 监听滚动距离 onPageScroll(e) { if (e && e.scrollTop >= 1000) { this.setData({ isBackTop: true }) } else { this.setData({ isBackTop: false }) } }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })