var app = getApp();//获取应用实例
/**
* 页面的初始数据
*/
data: {
uId:"",
uname:"",
token:"",
pageNum:1,
pageSize:20,
statusbar:0,// 小程序状态栏的高度
height:0,
post:[],
total :true// 判断是否加载更多
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var that = this;
//创建节点选择器
var query = wx.createSelectorQuery();
query.select('.nav').boundingClientRect(function (rect) {
that.setData({
height: rect.height,
statusbar:app.attached()
})
}).exec();
wx.getStorage({
key:"getWxAmpProfile",
success:function(res){
if(res.data){
that.setData({
uId:res.data.UID,
uname:res.data.UNAME,
})
}
that.kefu(1)
},
complete:function(){
}
});
},
kefu(pageNum){
var that = this;
wx.request({
url: '第一个请求地址',
method:'post',
data:{
isSeller:false,
userId:that.data.uId
},
header:{
// "Contend-Type":"application/json"
"Content-Type":"application/x-www-form-urlencoded"
},
success:function(res){
console.log(res)
var date = res.data;
that.setData({
getUserFriend:date
});
if(date.code == 900){
// 获取消息列表
wx.request({
url: '请求地址',
method:'post',
data:{
isSeller:false,
limit:20,
page:pageNum,
receiveUserId:date.data[1].friendUserId,
userId:that.data.uId
},
header:{
// "Contend-Type":"application/json"
"Content-Type":"application/x-www-form-urlencoded"
},
success:function(data){
var date = data.data;
if(date.code == 900){
if(date.data.length>=20){
console.log(date)
var message = that.data.post.concat(date.data)
that.setData({
post:message.reverse(),
total :true,
pageNum:pageNum
})
}else{
that.setData({
total:false
});
if(date.data.length){
var message = that.data.post.concat(date.data)
that.setData({
post:message.reverse(),
})
}
}
}
}
})
}
}
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
var that = this;
if(that.data.total == true){
this.kefu(that.data.pageNum+1)
}
},
小程序获取客服数据并按照信息发布时间排序
最新推荐文章于 2024-07-12 16:33:35 发布