// 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(){
},
// 下拉加载
loadMore:function(){
const self = this;
if (!self.data.hasMoreData) {
return; // 如果没有更多数据,不执行任何操作
}
// 使用 setData 更新页面状态为正在加载
self.setData({
isLoading: true
});
networkUtil._get(api.getMsgList, {
page: self.data.currentPage,
limit: self.data.limit,
babyId:self.data.babyId,
}, function(res) {
if (res.data && res.data.data.length > 0) {
const newData = self.data.notificationList.concat(res.data.data);
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
if(id){
setTimeout(() =>{
wx.navigateTo({
url: `/packageA/pages/messageContent/messageContent?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()
this.setData({
babyId:wx.getStorageSync('erid')
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.loadMore()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})