| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- // pages/message/index.js
- import { getProductHot } from '../../api/store.js';
- import { getMessages, readMessages } from "../../api/message"
- import { tsToString } 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,
- unread: 0,
- messages: []
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (app.globalData.token) this.setData({ iShidden:true});
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- onLoadFun: function() {
- this.pullMessageList();
- this.get_host_product();
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (app.globalData.isLog) {
- this.data.page = 1;
- this.get_host_product();
- this.pullMessageList();
- this.setData({
- iShidden: true
- });
- }
- },
- /**
- * 获取我的推荐
- */
- get_host_product:function(){
- var that=this;
- getProductHot().then(res=>{
- that.setData({ host_product: res.data });
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- pullMessageList() {
- var that = this;
- getMessages(that.data.page).then(res=>{
- var unread = 0;
- res.data.forEach(function(row){
- row.ts = tsToString(row.ts)
- row.read = row.read == null ? false : true
- if (!row.read){
- unread += 1
- }
- })
- app.setUnread(unread)
-
- that.setData({
- messages: res.data,
- unread: unread
- });
- }, err=> {
- });
- },
- onTapMessageItem(e) {
- if (!e.currentTarget.dataset.items.read) {
- var that = this
- readMessages([e.currentTarget.dataset.items.id]).then(res=>{
- that.setData({
- unread: that.data.unread-1,
- })
- // app.globalData.unread = res.data.unread
- app.setUnread(res.data.unread)
- })
-
- }
- wx.navigateTo({
- url: '/pages/message_details/index?data=' + encodeURIComponent(JSON.stringify(e.currentTarget.dataset.items)),
- });
- }
- })
|