myComments.js 2.6 KB
const a = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    commentsList: [],
    page: 1,
    ifData: !1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getCommentsList();
  },

  // 获取评论列表
  getCommentsList() {
    let b = this,
      url = '/api/User/getMyCommentList',
      params = {
        header: true,
        page: b.data.page
      };
    a.post(url, params).then((res) => {
      for (let b of res.data) {
        b.images = b.images.split(',')
      }
      b.setData({
        commentsList: b.data.commentsList.concat(res.data)
      })
      b.data.commentsList.length > 0 ? b.setData({
        ifData: !0
      }) : b.setData({
        ifData: !1
      }), res.data.length < res.per_page ? b.setData({
        noMore: !0,
      }) : ''
      wx.stopPullDownRefresh()
    })
  },
  navdetail(e) {
    wx.navigateTo({
      url: '/pages/colleagues_2/colleagues_2?id=' + e.currentTarget.id,
    })
  },
  delCom(e) {
    let t = this,
      id = e.currentTarget.id,
      url = '/api/interact/deleteComment',
      indx = e.currentTarget.dataset.indx,
      params = {
        id: id
      };
      wx.showModal({
        title: '提示',
        content: '是否删除该评论?',
        success:(res)=>{
          if(res.confirm){
            a.post(url, params).then(r => {
              wx.showToast({
                title: '删除成功',
                icon: 'none'
              });
              t.data.commentsList.splice(indx, 1)
              t.setData({
                commentsList: t.data.commentsList
              })
            })
          }
        }
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.setData({
      page:1,
      commentsList:[]
    }),
    this.getCommentsList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    let that = this;
    if (that.data.noMore) {
      wx.showToast({
        title: '没有更多了',
        icon: 'none'
      })
    } else {
      that.setData({
        page: that.data.page + 1,
      });
      that.getCommentsList();
    }

  },

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

  }
})