search_2.js 3.2 KB
// pages/index/search_2/search_2.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    history_keyword: '',
    hot_station: '',
    hot_boss: '',
  },
  // 搜索框传值至search_4
  inputText(e) {
    console.log(e)
    let inputValue = e.detail.value
    wx.navigateTo({
      url: '/pages/index/search_4/search_4?inputValue=' + inputValue,
    })

  },

  // 点击搜索历史跳转
  toSearch(e) {
    console.log(e)
    let keyWord = e.currentTarget.dataset.keyword
    // let station_name = e.currentTarget.dataset.station_name 
    // let resume_name = e.currentTarget.dataset.resume_name
    wx.navigateTo({
      url: '/pages/index/search_4/search_4?inputValue=' + keyWord 
    })
    // console.log(resume_name)

  },


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

  // 获取搜索历史记录
  history() {
    let that = this;
    let url = 'index/category/history_keyword';
    let params = {
    
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      // 获取值
      that.setData({

        history_keyword: res.data
      })

    }).catch((err) => {

    })
  },
  // 清空历史记录
  clear_history() {
    let that = this;
    let url = 'index/category/history_del';
    let params = {

    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      // 提示功能
      wx.showToast({
        title: '删除成功',
        icon: 'none',
        duration: 1500
      })
      setTimeout(function(){
        // wx.navigateTo({
        //   url: '/pages/index/search_2/search_2',
        // })
        that.history()
      },1000)
    }).catch((err) => {

    })
  },

  // 获取热门搜索
  hot_search() {
    let that = this;
    let url = 'index/category/hot_search';
    let params = {
      
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      that.setData({
        hot_station: res.data.hot_station,
        hot_boss: res.data.hot_boss,
      })
      console.log(res.data.hot_boss)
           
    }).catch((err) => {
         
    })
    // console.log(that.hot_station)
  },
  

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  // 一进页面就执行此函数
  onShow: function () {
    this.history()
    this.hot_search()
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})