| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- // 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": "<p>here is html code</p><p style='color:red;'>some code</p>",
- "ts": "2021/3/12 12:43:12",
- "expiresAt": 1234354545,
- "type": 0,
- "read": 0
- },{
- "id": 1,
- "icon": "/images/two.png",
- "from": "美天旺客服",
- "subject": "退货通知",
- "body": "<p>here is html code</p><p style='color:red;'>some code</p>",
- "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)),
- });
- }
- })
|