// pages/testHistory/testHistory.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { user_id:0, pagenum:0, lists:[], userInfo:{} }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getUserId(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getdata(); this.getUserId() }, getUserId(){ var getuser = wx.getStorageSync("userInfo"); if(getuser){ this.data.user_id = getuser.id; this.data.userInfo= getuser; }else if(app.globalData.userInfo){ this.data.user_id = app.globalData.userInfo.id; this.data.userInfo= app.globalData.userInfo; }else{ wx.navigateTo({ url: '/page/login/login', }); } this.setData({ userInfo:this.data.userInfo }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { this.data.pagenum = 1;//隐藏设置分页1 }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, getUserId(){ var getuser = wx.getStorageSync("userInfo"); if(getuser){ this.data.user_id = getuser.id; this.data.userInfo= getuser; }else if(app.globalData.userInfo){ this.data.user_id = app.globalData.userInfo.id; this.data.userInfo= app.globalData.userInfo; }else{ wx.navigateTo({ url: '/page/login/login', }); } this.setData({ userInfo:this.data.userInfo }) console.log(this.data.userInfo.avatar,"yy") }, //data getdata:function(){ var that=this; this.setData({ loading: true }); app.request('/api/mini/testhostory', { user_id:this.data.user_id, page:this.data.pagenum }, function (data, ret) { if(ret.code == 1){ if(ret.data.lists){ var newA = that.data.lists.concat(ret.data.lists); }else{ var newA = that.data.lists; } that.setData({ loading: false, lists:newA, }); } typeof cb == 'function' && cb(data); }, function (data, ret) { that.setData({ loading: false }); app.error(ret.msg); },2); }, onReachBottom: function () { //触底开始下一页 console.log("到底了") var pagenum = this.data.pagenum + 1; //获取当前页数并+1 this.setData({ pagenum: pagenum, //更新当前页数 }) this.getdata(); }, goDetail:function(e){ var test_id = e.currentTarget.dataset.test_id; wx.navigateTo({ url: '/page/constitutionGrade/constitutionGrade?res_test_id='+test_id, }); }, gorecord:function(e){ var test_id = e.currentTarget.dataset.test_id; wx.navigateTo({ url: '/page/record/record?res_test_id='+test_id, }); } })