enterprise.js 5.3 KB
     let A = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbar: [{
      name: '企业咨询'
    },
    {
      name: '企话吧'
    }
    ],
    zixunList: [],
    postList:[],
    currentTab: 0,
    page: 1,
    ifData: !1,
    noMore: !1,
    show: !0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = this; wx.getSystemInfo({
      success: function (res) {
        c.setData({
          winHeight: res.windowHeight
        })
      },
    }), this.postList();
  },
  subArticle() {
    wx.navigateTo({
      url: '/pages/interact/interactPost/interactPost',
    })
  },
  zan(e){
    let url = '/api/interact/setLike',params = {
      object_id: e.currentTarget.id,
      type:'1'
    }, index = e.currentTarget.dataset.idx,t=this,type=e.currentTarget.dataset.type;
    A.post(url,params).then((r)=>{
      t.data.postList[index].is_like = r.is_like
      t.data.postList[index].likes = r.likes
      t.setData({
        postList: t.data.postList
      })
    })
  },
  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.postList.splice(index, 1);
            t.setData({
              postList: t.data.postList
            })

          })
        }
      }
    })
  },
  navdetail(e) {
    wx.navigateTo({
      url: '/pages/colleagues_2/colleagues_2?id='+e.currentTarget.id,
    })
  },
  getzixun() {
    wx.showLoading({
      title: '加载中',
    })
    let url = '/api/interact/getQuestionList', d = this, params = {
      page: d.data.page
    };
    A.post(url, params, false).then((r) => {
      for(let b of r.data){
        b.create_time = A.timeFormate(b.create_time, 'YYMMDDHHMM')
        b.reply_time = A.timeFormate(b.reply_time,'YYMMDDHHMM')
      }
      let list = d.data.zixunList.concat(r.data);
      d.setData({
        zixunList: list
      })
      list.length == 0 ? d.setData({
        ifData: !0,
      }) : (r.data.length < r.per_page ? d.setData({
        noMore: !0
      }) : "")
      setTimeout(() => {
        d.setData({
          show: !1
        }, 1200)
      })
      wx.hideLoading()
      wx.stopPullDownRefresh()
    })
  },
  postList() {
    wx.showLoading({
      title: '加载中',
    })
    let url = '/api/interact/getPostsList', d = this, params = {
      page: d.data.page
    };
    A.post(url, params, false).then((r) => {
      for(let b of r.data){
        b.images = b.images.split(',')
      }
      let list = d.data.postList.concat(r.data);
      d.setData({
        postList: list,
        comment: r.new_comment
      })
      list.length == 0 ? d.setData({
        ifData: !0,
      }) : (r.data.length < r.per_page ? d.setData({
        noMore: !0
      }) : "")
      wx.hideLoading()
      wx.stopPullDownRefresh()
    })
  },

  askQuestion() {
    wx.navigateTo({
      url: '/pages/question/question',
    })
  },
  checkstatus() {
    let b = this, url = '/api/user/getAuthStatus', params = {
      header: true
    };
    A.post(url, params).then((r) => {
      b.setData({
        auth: r
      });
      r == 2 ? b.getzixun() : '';
    })
  },
  renzheng(e) {
    let type = e.currentTarget.dataset.type;
    type == 1 ? wx.showToast({
      title: '认证审批中请耐心等待',
      icon: 'none',
      duration: 1200
    }) : wx.navigateTo({
      url: '/pages/my/approve/approve',
    })
  },
  navbarTap: function (e) {
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0,
    })
    let t = this, idx = e.currentTarget.dataset.idx;
    this.setData({
      show:!0,
      currentTab: idx,
      zixunList:[],
      postList:[],
      page:1
    }), idx ? t.postList() : t.getzixun();

  },
  jump() {
    wx.navigateTo({
      url: '',
    })

    wx.switchTab({
      url: '',
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.checkstatus()
    this.setData({
      zixunList: [],
      postList:[],
      page: 1,
      show:!0
    })
    this.data.currentTab=='0'?this.getzixun():this.postList()
  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.checkstatus()
    this.setData({
      zixunList: [],
      postList: [],
      page: 1
    })
    this.data.currentTab == '0' ? this.getzixun() : this.postList()
  },

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

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

  }
})