fix 搜索search

develop
GJW200011 4 years ago
parent 8aff1d8fb6
commit 7b6459a082

@ -1,6 +1,6 @@
// pages/index/search/search.js // pages/index/search/search.js
import { import {
httpUtil,http, httpUtil, http,
location_city location_city
} from "../../../utils/util" } from "../../../utils/util"
Page({ Page({
@ -11,16 +11,16 @@ Page({
data: {}, data: {},
search_(keyword, city_id) { search_(keyword, city_id) {
const search_his = wx.getStorageSync('search_his') || [] const search_his = wx.getStorageSync('search_his') || []
if ((keyword && "undefined" !== keyword)||this.data.placeholder) { if ((keyword && "undefined" !== keyword) || this.data.placeholder) {
if (!keyword ){ if (!keyword) {
keyword =this.data.placeholder keyword = this.data.placeholder
} }
for(var i=0; i<search_his.length; i++) { for (var i = 0; i < search_his.length; i++) {
if(keyword == search_his[i]) { // 相同的全部删除 if (keyword == search_his[i]) { // 相同的全部删除
search_his.splice(i, 1); // 删除该元素 search_his.splice(i, 1); // 删除该元素
i--; i--;
} }
} }
search_his.unshift(keyword) search_his.unshift(keyword)
this.setData({ this.setData({
keyword, keyword,
@ -32,7 +32,7 @@ Page({
}).then(res => { }).then(res => {
this.setData({ this.setData({
ip_info: res.ip_info, ip_info: res.ip_info,
cancel_noContWarn:true, cancel_noContWarn: true,
search_list: res.search_list, search_list: res.search_list,
suggest_list: res.suggest_list suggest_list: res.suggest_list
}) })
@ -101,10 +101,10 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
// 获取search关键词 // 获取search关键词
httpUtil("/api/v1/hot-search","get").then(res=>{ httpUtil("/api/v1/hot-search", "get").then(res => {
this.setData({placeholder:res.keyword}) this.setData({ placeholder: res.keyword })
}) })
let city_id let city_id
if ('undefined' == options.city_id) { if ('undefined' == options.city_id) {
location_city().then(res => { location_city().then(res => {

Loading…
Cancel
Save