myLike.js 2.6 KB

const a = getApp();
Page({

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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getLikeList();
  },
  navdetail(e) {
    wx.navigateTo({
      url: '/pages/colleagues_2/colleagues_2?id=' + e.currentTarget.id,
    })
  },

  zan(e) {
    console.log(e)
    let t = this, id = e.currentTarget.id, url = '/api/interact/deletePosts', params = {
      id: id
    }, index = e.currentTarget.dataset.indx;
    a.post(url, params).then((rt) => {
      wx.showToast({
        title: '删除成功',
        icon: 'none',
        duration: 1300
      })


    })
  },

  zan(e) {
    let url = '/api/interact/setLike', params = {
      object_id: e.currentTarget.id,
      type: '1'
    }, index = e.currentTarget.dataset.indx, t = this, type = e.currentTarget.dataset.type;
    a.post(url, params).then((r) => {
      wx.showToast({
        title: '已取消点赞',
        icon:'none'
      })
      t.data.likeList.splice(index, 1);
      setTimeout(()=>{
        t.setData({
          likeList: t.data.likeList
        })
      },1200)
    })
  },
  // 获取点赞列表
  getLikeList() {
    let b = this, url = '/api/User/getMyLikeList', 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({
        likeList: b.data.likeList.concat(res.data),
        ifData: res.data.length > 0 ? true : false,
        noMore: res.data.length < res.per_page ? !0 : !1
      })
    })
  },

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

  },

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

  },

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

  },

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

  },

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

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

  },

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

  }
})