searchpage.js 3.2 KB
// pages/searchpage/searchpage.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchlist:'',
    keyword:'',
    homelist:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getsearch()
  },
  //获取搜索
  getsearch(){
    let that = this;
    var url = '/home/Search/index';
    var params = {


    }

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



    }).catch((err) => {

    })

  },

  //清空历史纪录
  clearhistory(){
    let that = this;
    var url = '/home/Search/clearSearchHistory';
    var params = {


    }

    var header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      if(res==""){
        wx.showToast({
          title: '清除成功',
          icon:'none'
        })


        setTimeout(function(){
          that.getsearch()
        },1500)
      }




    }).catch((err) => {

    })

  },

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

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


  //   }).catch((err) => {

  //   })

  // },

  //开始搜索
  beginsearch(e){
    let that=this;
    console.log(e)
    that.setData({
      keyword:e.detail.value,
      
    })
    if(e.detail.value!=''){
      wx.navigateTo({
        url: '../searchlist/searchlist?word=' + e.detail.value,
      })
    }
   

    

  },
  //跳到搜索页

  searchcontent(){
    let that=this;
    let word=that.data.keyword;
    wx.navigateTo({
      url: '../searchlist/searchlist?word='+word,
    })
  },

  //热门搜索
  searchhot(e){
    let hotword=e.currentTarget.dataset.hot;
    console.log(hotword)
    this.setData({
      keyword:hotword,
      // homelist:[]
    })

    wx.navigateTo({
      url: '../searchlist/searchlist?word=' + hotword,
    })
    // this.searchlist()
  },
  //教学方案列表详情
  detail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../teachplan/teachplanlistdetail/teachplanlistdetail?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

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

  }
})