// pages/message/index.js import { getProductHot } from '../../api/store.js'; import { getMessages } from "../../api/message" import { SplitArray } from "../../utils/util" const app = getApp(); Page({ /** * 页面的初始数据 */ data: { parameter: { title: "我的消息", 'navbar': '1', 'return': '1', 'color': false, }, host_product:[], iShidden: false, page: 0, messages: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.setTabBarBadge({ index: 2, text: '9' }); console.log("load"); if (app.globalData.token) this.setData({ iShidden:true}); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, onLoadFun: function() { this.get_host_product(); this.refreshNotifications(); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (app.globalData.isLog) { this.data.page = 1; this.get_host_product(); this.pullMessageList(); this.setData({ iShidden: true }); } }, refreshNotifications: function() { var that = this; getNotifications().then(res=>{ console.log(res); }, err=> { console.log(err); // that.setData({ // messages: [ 1 ] // }); }); }, /** * 获取我的推荐 */ get_host_product:function(){ var that=this; getProductHot().then(res=>{ that.setData({ host_product: res.data }); }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { console.log("unload"); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { setTimeout(function() { wx.stopPullDownRefresh({ success: (res) => { console.log("success stop") }, }); }, 300); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { console.log("load more"); this.data.page ++; this.pullMessageList(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, pullMessageList() { var that = this; getMessages(that.data.page).then(res=>{ that.setData({ messages: SplitArray(that.data.messages, res.messages) }); }, err=> { }); } })