homepage.js 2.6 KB
// pages/service/service.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sel: 0,
    kindlist: [],
    selid: '',
    page: 1,
    articlelist: []
  },

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

  },
  // 获取分类
  getkind() {
    let that = this;
    console.log(34834)
    var url = '/api/index/article_sort';
    var params = {
      type: 2
    }
    app.post(url, params, "post").then((res) => {
      console.log(res);
      that.setData({
        kindlist: res.article_sort,
        selid: res.article_sort[0].id
      })
      that.getarticlelist();

    }).catch((err) => {

    })
  },
  selnav(e) {
    this.setData({
      sel: e.currentTarget.dataset.index,
      selid: e.currentTarget.dataset.sortid,
      page: 1,
      articlelist: []
    })
    this.getarticlelist()

  },

  // 获取文章列表
  getarticlelist() {
    let that = this;
    var url = '/api/index/notice';
    var params = {
      sort_id: that.data.selid,
      page: that.data.page

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

      console.log(that.data.articlelist)



    }).catch((err) => {

    })
  },
  newdetail(e) {

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.setData({
      page: 1,
      articlelist: []
    })

    this.getarticlelist()
    //模拟加载

    setTimeout(function () {

      // complete

      wx.hideNavigationBarLoading() //完成停止加载

      wx.stopPullDownRefresh() //停止下拉刷新

    }, 1000);
  },

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

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

  }
})