myPost.js 2.5 KB
const a = getApp();
Page({

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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = this;
    wx.getSystemInfo({
      success: function(res) {
        c.setData({
          windowHeight: res.windowHeight
        })
      },
    }), c.articleList();
  },
  articleList(){
    let b = this, url ='/api/User/getMyPostsList',params={
      header:true,
      page: b.data.page
    };
    a.post(url,params).then((r)=>{
      for(let b of r.data){
        b.images = b.images.split(',');
      }
      let dataList = b.data.page>1?b.data.articleList.concat(r.data):r.data;
      b.setData({
        articleList: dataList,
        ifData:!0,
        preLength: r.data.length
      })
      !dataList.length?b.setData({
        ifData:!1
      }):""

    })
  },
  navdetail(e) {
    wx.navigateTo({
      url: '/pages/colleagues_2/colleagues_2?id=' + e.currentTarget.id,
    })
  },
  delArticle(e){
    console.log(e)
    let t = this, id = e.currentTarget.id, url ='/api/interact/deletePosts',params={
      id:id
    },index = e.currentTarget.dataset.indx;
    wx.showModal({
      title: '提示',
      content: '确认删除这个帖子吗?',
      success: (r)=>{
        if(r.confirm){
          a.post(url,params).then((rt)=>{
            wx.showToast({
              title: '删除成功',
              icon:'none',
              duration: 1300
            })
            t.data.articleList.splice(index,1);
            t.setData({
              articleList: t.data.articleList
            })
            
          })
        }
      }
    })
  },
  subArticle(){
    wx.navigateTo({
      url: '/pages/interact/interactPost/interactPost',
    })
  },
  loadMore(){
    
  },

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

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

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

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

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