|
|
@@ -3,8 +3,6 @@ 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({
|
|
|
@@ -22,7 +20,6 @@ Page({
|
|
|
host_product:[],
|
|
|
iShidden: false,
|
|
|
page: 0,
|
|
|
- unread: 0,
|
|
|
messages: []
|
|
|
},
|
|
|
|
|
|
@@ -30,7 +27,9 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
- if (app.globalData.token) this.setData({ iShidden:true});
|
|
|
+ if (app.globalData.token) {
|
|
|
+ this.setData({ iShidden:true});
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -41,7 +40,6 @@ Page({
|
|
|
|
|
|
onLoadFun: function() {
|
|
|
this.pullMessageList();
|
|
|
- this.get_host_product();
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -50,12 +48,12 @@ Page({
|
|
|
onShow: function () {
|
|
|
if (app.globalData.isLog) {
|
|
|
this.data.page = 1;
|
|
|
- this.get_host_product();
|
|
|
this.pullMessageList();
|
|
|
this.setData({
|
|
|
iShidden: true
|
|
|
});
|
|
|
}
|
|
|
+ app.setUnread(app.globalData.unread); // 从详情页面返回,更新已读
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -83,23 +81,19 @@ Page({
|
|
|
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=> {
|
|
|
|
|
|
+ if (!this.message || this.messages.length <= 0) {
|
|
|
+ this.get_host_product();
|
|
|
+ }
|
|
|
+ }, err=> {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
@@ -107,13 +101,8 @@ Page({
|
|
|
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)
|
|
|
+ app.globalData.unread -= 1;
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/message_details/index?data=' + encodeURIComponent(JSON.stringify(e.currentTarget.dataset.items)),
|