// pages/messageNotification/message.js // 网络请求工具类 var networkUtil = require('../../../utils/network_util.js') var api = require('../../../utils/apiFile.js') Page({ /** * 页面的初始数据 */ data: { notificationList:[], // 消息通知列表 currentPage: 1, // 当前页码 limit: 10, // 每页显示的数据条数 hasMoreData: true, // 是否有更多数据可加载 babyId:null, formattedDate:null }, //获取消息通知 getNotificationList:function(){ }, formatDate(milliseconds) { // 创建 Date 对象 const date = new Date(milliseconds); // 格式化日期和时间 const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的 const day = String(date.getDate()).padStart(2, '0'); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0'); // 拼接成 YYYY-MM-DD HH:MM:SS 格式 return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } , // 下拉加载 loadMore:function(){ const self = this; if (!self.data.hasMoreData) { return; // 如果没有更多数据,不执行任何操作 } // 使用 setData 更新页面状态为正在加载 self.setData({ isLoading: true }); networkUtil._get(api.getfeedback, { page: self.data.currentPage, limit: self.data.limit, babyId:self.data.babyId, }, function(res) { if (res.data && res.data.data.length > 0) { let newData = self.data.notificationList.concat(res.data.data); newData.forEach((item,index)=>{ if(item.created){ newData[index].createdstr=self.formatDate(item.created) } }) self.setData({ notificationList: newData, currentPage: self.data.currentPage + 1, isLoading: false }); // 判断是否还有更多数据 const hasMoreData = res.data.pageInfo.page < res.data.pageInfo.lastPage // 更新页面数据(假设你在微信小程序或其他使用setData方法的框架中) self.setData({ hasMoreData: hasMoreData }); wx.hideToast(); } else { // 如果没有返回数据,表示没有更多数据了 self.setData({ hasMoreData: false, isLoading: false }); } }, function(res) { networkUtil.showErrorToast(res.errormsg); wx.hideToast(); }); }, // 跳转 messageBtn:function(e){ const id = e.currentTarget.dataset.index const str=e.currentTarget.dataset.item if(id){ wx.setStorageSync('feedxq', JSON.stringify(str)) setTimeout(() =>{ wx.navigateTo({ url: `/packageA/pages/feedbackxq/feedbackxq?id=${id}`, }) },100) } else { return } }, // 快速预约课程 goAddQuestion: function(e) { networkUtil.showLoading(); var self = this; wx.showModal({ title: '提示', confirmText: '线上', content:`您目前是要线上预约还是现场预约?`, cancelText: '现场', success(res) { if (res.confirm) { var param = { courseId: e.target.dataset.id, type: 1 }; networkUtil._get(api.orderCourse, param, function(res) { if (res.data.errorcode == 0) { networkUtil.showToast('预约成功'); self.loadMore(); } }, function(res) { networkUtil.showErrorToast(res.errormsg); wx.hideToast(); }); } else if (res.cancel) { var param = { courseId: e.target.dataset.id, type: 2 }; networkUtil._get(api.orderCourse, param, function(res) { // console.log(ress,'res'); if (res.data.errorcode == 0) { networkUtil.showToast('预约成功'); self.loadMore(); } } , function(res) { networkUtil.showErrorToast(res.errormsg); wx.hideToast(); } ); } } }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { networkUtil.showLoading() console.log('options',options); this.setData({ babyId:options.id }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.loadMore() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })