searchlist.js 2.1 KB
// pages/searchlist/searchlist.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    keyword: '搜索',
    homelist: [],
    page:1
   
  },

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

    this.setData({
      keyword:options.word,
      
    })

    this.searchlist()

  },


  searchlist() {
    let that = this;
    var url = '/home/Search/searchPost';
    var params = {
      keyword: that.data.keyword,
      p:that.data.page

    }
    var header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      that.setData({
        homelist: that.data.homelist.concat(res.search_result) 
      })


    }).catch((err) => {

    })

  },



  //开始搜索
  beginsearch(e) {
    let that = this;
    console.log(e)
    that.setData({
      keyword: e.detail.value,
      homelist:[],
      page:1

    })
    that.searchlist()

    


  },

  //教学方案列表详情
  detail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id;
    let free = e.currentTarget.dataset.free;
    wx.navigateTo({
      url: '../teachplan/teachplanlistdetail/teachplanlistdetail?id=' + id + '&free=' + free,
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

    that.searchlist()
  },

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

  }
})