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

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    messagelist: [],
    token:'',
    login_new:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  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: '/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() {

  }
})