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