// pages/release/release.js // 获取应用实例 const app = getApp() const $request = require('../../utils/request.js'); const $util = require('../../utils/util.js'); Page({ data: { currentIndex: 2, pageLoading: true, customerId: "", // 前往关注公众号 topShow: true, msgData: [], page: 1, size: 10, total: 0, // 是否加载数据,true加载,false不加载 onRefresh: true, }, /** * 生命周期函数--监听页面加载 */ onLoad() { this.getMsgData(); }, closeTopShow() { this.setData({ topShow: false }) }, getMsgData() { let { page, size } = this.data; $request.get('/businessCommunicationDemand/getChatRecordTable.action', { page, size }).then(res => { console.log(res); let tempListData = this.data.msgData; if (res.status == 0) { let datas = res.data; console.log(datas, 'datas') // 先push数据 tempListData.push(...datas.chatRecordTable); tempListData.forEach(el => { el.createdOn = $util.formatTime(new Date(el.createdOn), true); if (typeof el.type == 'string') { el.type = el.type.split(','); } }) // 设置总数 this.setData({ msgData: tempListData, total: datas.total, }) // 如果数据大于了返回的总数 if (tempListData.length >= this.data.total) { // 停止累加数据 this.setData({ onRefresh: false, itemLoading: false, }) } else { this.setData({ onRefresh: true, itemLoading: false, page: page + 1 }) } console.log('-------------消息 beg-------------------') console.log(this.data.msgData); console.log('-------------消息 end-------------------') } this.setData({ pageLoading: false, }) }).catch(error => { console.log(error, 'error appletLogin') }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.onRefresh) { this.setData({ itemLoading: true }) this.getListData(); } }, })