// pages/message/index.js import { getProductHot } from '../../api/store.js'; import { getMessages } from "../../api/message" import { SplitArray } from "../../utils/util" var base64 = require("../../utils/base64") const app = getApp(); Page({ /** * 页面的初始数据 */ data: { parameter: { 'title': "消息", 'navbar': '1', 'return': '1', 'color': false, }, host_product:[], iShidden: false, page: 0, messages: [{ "id": 1, "icon": "/images/one.png", "from": "系统消息", "subject": "优惠活动", "body": "

here is html code

some code

", "ts": "2021/3/12 12:43:12", "expiresAt": 1234354545, "type": 0, "read": 0 },{ "id": 1, "icon": "/images/two.png", "from": "美天旺客服", "subject": "退货通知", "body": "

here is html code

some code

", "ts": "2021/3/12 12:43:12", "expiresAt": 1234354545, "type": 0, "read": 0 }] }, /** * 生命周期函数--监听页面加载 */ 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.pullMessageList(); 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 () { var that = this; wx.stopPullDownRefresh({ success: (res) => { setTimeout(function() { console.log("success stop") that.data.page = 1; that.pullMessageList(); }, 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=> { }); }, tabClick(e) { wx.navigateTo({ url: '/pages/message_details/index?data=' + base64.encode(JSON.stringify(e.currentTarget.dataset.items)), }); } })