learnShare.js 2.5 KB
// pages/learnShare/learnShare.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classify: [],
    MenuId: 0, //分类id
    KeyWord: '',
    Page: 0,
    news: [],
    hasMoreData: false,
    classifyid:''
  },
  goIndex() {
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  //设置查询的关键词
  setKeyWord(e) {
    let that = this;
    that.setData({
      KeyWord: e.detail.value
    })
  },

  // 选择分类
  chooseClassify(e) {
    var id = e.currentTarget.dataset.id;
    let classifyid = e.currentTarget.dataset.classifyid;
    let idx=e.currentTarget.dataset.idx;
    console.log(idx)
    if(idx==undefined){
      this.setData({
        classifyid:'',
      })
    }else{
      this.setData({
        classifyid: classifyid,
      
      })
    }
    this.setData({
     
      MenuId:id,
    })
    this.getdata();
  },

  //获取文章类别
  getdata() {
    let that = this;
    let url = 'pubilc/news';
    let params = {
      MenuId: this.data.classifyid,
      KeyWord: this.data.KeyWord,
      Page: that.data.Page
    }
    app.post(url, params).then((res) => {
      if (res.data.code == 200) {
        this.setData({
          classify: res.data.data.menu,
          news: res.data.data.news,
        })
      }
    }).catch((errMsg) => {
    })

  },

  //文章详情
  listDetail(e) {
    var NewsId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../ArticleDetails/ArticleDetails?NewsId=' + NewsId,
    })
  },

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

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

  },

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

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

  },

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

  },

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.page = 1
    this.getdata('正在刷新数据')
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    if (this.data.hasMoreData) {
      this.getdata('加载更多数据')
    } else {
      wx.showToast({
        title: '没有更多数据',
      })
    }
  }
})