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.
177 lines
3.5 KiB
177 lines
3.5 KiB
// pages/index/search/search.js
|
|
import {
|
|
httpUtil,http,
|
|
location_city
|
|
} from "../../../utils/util"
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {},
|
|
search_(keyword, city_id) {
|
|
const search_his = wx.getStorageSync('search_his') || []
|
|
if ((keyword && "undefined" !== keyword)||this.data.placeholder) {
|
|
if (!keyword ){
|
|
keyword =this.data.placeholder
|
|
}
|
|
for(var i=0; i<search_his.length; i++) {
|
|
if(keyword == search_his[i]) { // 相同的全部删除
|
|
search_his.splice(i, 1); // 删除该元素
|
|
i--;
|
|
}
|
|
}
|
|
search_his.unshift(keyword)
|
|
this.setData({
|
|
keyword,
|
|
searching: true
|
|
})
|
|
httpUtil("/api/v1/search", "get", {
|
|
keyword,
|
|
city_id
|
|
}).then(res => {
|
|
this.setData({
|
|
ip_info: res.ip_info,
|
|
cancel_noContWarn:true,
|
|
search_list: res.search_list,
|
|
suggest_list: res.suggest_list
|
|
})
|
|
})
|
|
}
|
|
this.setData({
|
|
search_his
|
|
})
|
|
wx.setStorageSync('search_his', search_his)
|
|
},
|
|
|
|
|
|
write_in(e) {
|
|
this.setData({
|
|
keyword: e.detail.value
|
|
})
|
|
if (this.data.keyword == '') {
|
|
this.setData({
|
|
searching: false
|
|
})
|
|
}
|
|
},
|
|
search(e) {
|
|
this.setData({
|
|
keyword: e.detail.value
|
|
})
|
|
this.search_(e.detail.value, this.data.city_id)
|
|
},
|
|
search1() {
|
|
this.search_(this.data.keyword, this.data.city_id)
|
|
},
|
|
delete() {
|
|
var that = this
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '是否删除搜索缓存',
|
|
success(res) {
|
|
if (res.confirm) {
|
|
console.log('用户点击确定')
|
|
wx.removeStorageSync("search_his");
|
|
that.setData({
|
|
search_his: null
|
|
})
|
|
} else if (res.cancel) {
|
|
console.log('用户点击取消')
|
|
}
|
|
}
|
|
})
|
|
|
|
},
|
|
research(e) {
|
|
this.search_(e.currentTarget.dataset.keyword, this.data.city_id)
|
|
},
|
|
|
|
nav(e) {
|
|
wx.navigateTo({
|
|
url: '/pages/opera/IP_detail/IP_detail?abb_id=' + e.currentTarget.dataset.abb_id
|
|
})
|
|
},
|
|
nav1(e) {
|
|
wx.navigateTo({
|
|
url: '/pages/opera/show/show_detail?cycle_id=' + e.currentTarget.dataset.cycle_id
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
// 获取search关键词
|
|
httpUtil("/api/v1/hot-search","get").then(res=>{
|
|
this.setData({placeholder:res.keyword})
|
|
})
|
|
let city_id
|
|
if ('undefined' == options.city_id) {
|
|
location_city().then(res => {
|
|
city_id = res.city_info.city_id
|
|
})
|
|
} else if (options.city_id) {
|
|
city_id = options.city_id
|
|
} else {
|
|
wx.switchTab({
|
|
url: '/pages/index/index/index',
|
|
})
|
|
}
|
|
this.setData({
|
|
city_id,
|
|
search_his: wx.getStorageSync('search_his') || []
|
|
})
|
|
if (options.keyword) {
|
|
this.search_(options.keyword, options.city_id)
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |