putongwenzhang.js 3.3 KB
// pages/findblock/putongwenzhang/putongwenzhang.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    id:'',
    page:1,
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      url: app.globalData.url,
      id:options.id
    })

    
  },

  //获取文章列表
  getarticlelist(){
    let that = this;
    let url = 'index/Find/article_list', params = {
      category_id:that.data.id,
      page:that.data.page

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        list:that.data.list.concat(res.list)
      })



    }).catch((err) => {

    })
  },

//点赞和取消点赞
  dianzan(e){
    let that = this;
    let id=e.currentTarget.dataset.id;
   
    let url = 'index/Common/good', params = {
      sort:4,
      id:id
    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: res,
        icon:'none'
      })

      let newlist=that.data.list;
      for(var obj of newlist){
        if(obj.id==id){
          if (obj.is_good == 0) {
            obj.is_good = 1;
            obj.good_count = obj.good_count + 1
          } else {
            obj.is_good = 0;
            if (obj.good_count == 0) {
              obj.obj.good_count = 0
            } else {
              obj.good_count = obj.good_count - 1
            }
          }
        }
       
      }

      that.setData({
        list:newlist
      })
      



    }).catch((err) => {

    })
  },

  //进入评论页面
  ping(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/myblock/pingjia/pingjia?id='+id+'&type='+4,
    })
  },

  //详情页面
  detail(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/findblock/wenzhangdetail/wenzhangdetail?id='+id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
    this.setData({
      page:1,
      list:[]
    })
    this.getarticlelist()
  },

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

  },

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

  },

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

  },

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    let that = this;
    
    let id = e.target.dataset.id;
   
   
    let url = '/pages/findblock/wenzhangdetail/wenzhangdetail?id=' + id
    

    return {
      title: '发现', // 转发后 所显示的title
      // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径

      path: url,//建档攻略分享1
      // path:'',
      success: (res) => {    // 成功后要做的事情
        console.log(res)

      },
      fail: function (res) {
        // 分享失败
        console.log(res)
      }
    }

  }
})