diff --git a/pages/goods/search/search.js b/pages/goods/search/search.js index ad9f3be..de66ca8 100644 --- a/pages/goods/search/search.js +++ b/pages/goods/search/search.js @@ -101,6 +101,7 @@ Page({ //扫一扫过来,显示搜索的内容 var s_key = t.s_key; if (s_key){ + s_key=s_key.trim(); this.search(s_key); this.openSearchModal(); return; } @@ -190,10 +191,16 @@ Page({ }); }, submitSearch: function(t) { - console.log(111); - this.search(t.detail.value.word); - - + console.log(111,t); + var val=t.detail.value.word; + if(!val) val=t.detail.value; + val=val.trim(); + if(!val){ + a.showWarning("请输入搜索关键词"); + } + + this.search(val); + }, //热搜关键字 @@ -282,13 +289,29 @@ Page({ historyRecord() { let self = this; - let keyword = this.data.key_str; + let keyword = this.data.key_str.trim(); let searchRecord = this.data.searchRecord; if(!searchRecord || searchRecord.length==0) searchRecord=wx.getStorageSync('searchRecord') || []; if(keyword) { - if(searchRecord.indexOf(keyword) > -1) { + + var index=searchRecord.indexOf(keyword); + if(index > -1) { // 已经存在该值 + searchRecord.splice(index,1); + searchRecord.unshift(keyword); + + // 将历史记录添加到缓存中 + wx.setStorage({ + key: 'searchRecord', + data: searchRecord, + success: function(res) { + self.setData({ + searchRecord, + }) + } + }) + return; } else { if(searchRecord.length >= 10) { diff --git a/pages/goods/search/search.wxml b/pages/goods/search/search.wxml index 8bdaf46..c80f0c4 100644 --- a/pages/goods/search/search.wxml +++ b/pages/goods/search/search.wxml @@ -162,7 +162,7 @@
- +