You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
// pages/search/index.js
|
|
|
|
|
import commonApi from "../../utils/https/common"
|
|
|
|
|
import util from '../../utils/util'
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
keyword:"",
|
|
|
|
|
keywords:[],
|
|
|
|
|
hot:[]
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
commonApi._post("search/hot").then(res=>{
|
|
|
|
|
console.log(res)
|
|
|
|
|
this.setData({
|
|
|
|
|
hot:res.data
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
pagePoint: function(e,type){
|
|
|
|
|
util.pagePoint(e,type)
|
|
|
|
|
},
|
|
|
|
|
inputKeyword:function(e){
|
|
|
|
|
this.setData({
|
|
|
|
|
keyword:e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
delHis:function(){
|
|
|
|
|
this.setData({
|
|
|
|
|
keywords:[]
|
|
|
|
|
})
|
|
|
|
|
wx.removeStorageSync('sz_trip_keywords')
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '删除成功',
|
|
|
|
|
icon:'success'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
search:function(){
|
|
|
|
|
if(!this.data.keyword) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入关键字',
|
|
|
|
|
icon:'none'
|
|
|
|
|
})
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setHis(this.data.keyword);
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: 'list/index?keyword='+this.data.keyword,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
searchHot:function(e){
|
|
|
|
|
let item = e.currentTarget.dataset.item;
|
|
|
|
|
this.setHis(item)
|
|
|
|
|
this.pagePoint({
|
|
|
|
|
event:e.currentTarget.dataset.event,
|
|
|
|
|
param: {
|
|
|
|
|
keyword:item
|
|
|
|
|
}
|
|
|
|
|
},1)
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: 'list/index?keyword='+item,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
// 设置历史记录
|
|
|
|
|
setHis:function(keyword){
|
|
|
|
|
let keywords = this.data.keywords;
|
|
|
|
|
for(let i=0;i<keywords.length;i++){
|
|
|
|
|
if(keywords[i]==keyword){
|
|
|
|
|
keywords.splice(i,1);
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
keywords.unshift(keyword)
|
|
|
|
|
this.setData({
|
|
|
|
|
keywords:keywords
|
|
|
|
|
})
|
|
|
|
|
wx.setStorageSync('sz_trip_keywords', JSON.stringify(keywords));
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
// 获取历史搜索
|
|
|
|
|
let keywords = wx.getStorageSync('sz_trip_keywords');
|
|
|
|
|
keywords = keywords?JSON.parse(keywords):[];
|
|
|
|
|
this.setData({
|
|
|
|
|
keywords:keywords
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|