message.js 3.9 KB
// pages/message/message.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        messagelist: [],
        token: '',
        login_new: '',
        selected: 1,
        list: [{
            pagePath: "/packageA/pages/index/index",
            text: "商品",
            iconPath: "/images/tabbar/icon_75.png",
            selectedIconPath: "/images/tabbar/icon_68.png"
        },
        {
            pagePath: "/packageA/pages/message/message",
            text: "消息",
            iconPath: "/images/tabbar/message.png",
            selectedIconPath: "/images/tabbar/messageactive.png"
        },
        {
            pagePath: "/packageA/pages/shop_cart/shop_cart",
            text: "购物车",
            iconPath: "/images/tabbar/icon_70.png",
            selectedIconPath: "/images/tabbar/icon_73.png"
        },
        {
            pagePath: "/packageA/pages/my/my",
            text: "我的",
            iconPath: "/images/tabbar/icon_71.png",
            selectedIconPath: "/images/tabbar/icon_72.png"
        }]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    getmessagelist() {
        let that = this
        let url = '/information/get_all';
        let data = {
            page: that.data.page,
            pageNum: 10,

        }
        app.post(url, data, "POST").then((r) => {
            console.log(r)
            that.setData({
                messagelist: that.data.messagelist.concat(r.msg)
            })

            let newlist = [];
            that.data.messagelist.forEach(function (value, index, array) {
                console.log(newlist)
                if (value.status == 1) {
                    newlist.push(value)
                }
            })

            console.log(newlist)
            if (newlist.length != 0) {
                wx.showTabBarRedDot({
                    index: 1,
                    success: function (red) {
                        wx.setTabBarBadge({
                            index: 1,
                            text: newlist.length.toString(),
                        })
                    }
                })
            } else {
                wx.hideTabBarRedDot({
                    index: 1,
                    success: function (red) {

                        // wx.setTabBarBadge({
                        //   index: 1,
                        //   text: newlist.length.toString(),
                        // })
                    }
                })
            }


        }).catch((err) => { })
    },

    // 订单详情
    ordertail(e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/packageA/pages/messagedetail/messagedetail?id=' + id,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            token: wx.getStorageSync('token'),
            login_new: app.globalData.login_new
        })

        this.setData({
            messagelist: [],
            page: 1
        })
        this.getmessagelist()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        let newpage = this.data.page;
        newpage++;
        this.setData({
            page: newpage
        })
        this.getmessagelist()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})