diff --git a/components/index-nav/index-nav.vue b/components/index-nav/index-nav.vue index e235ecf..a913f3e 100644 --- a/components/index-nav/index-nav.vue +++ b/components/index-nav/index-nav.vue @@ -42,7 +42,7 @@ export default { image: 'https://cdn.guojiang.club/storage/uploads/images/2020_06_05/rNCqCVUgi5GFYntpqmevHEaO1NYt5PZ2tgjEXRMU.png', name: '数码家电' },{ - link: '/pages/index/onlineMall/onlineMall', + link: '/pages/index/onlineMall/onlineMall?id=6', image: 'https://cdn.guojiang.club/storage/uploads/images/2020_06_05/rNCqCVUgi5GFYntpqmevHEaO1NYt5PZ2tgjEXRMU.png', name: '黄金珠宝' },{ diff --git a/pages/index/category/category.vue b/pages/index/category/category.vue index ccc6329..cbc1d37 100644 --- a/pages/index/category/category.vue +++ b/pages/index/category/category.vue @@ -235,7 +235,8 @@ }, // 右边点击 rightTap: function(item) { - this.$url(item.path); + console.log(item); + this.$url('/pages/index/onlineMall/onlineMall?id='+ item.id); }, rightScroll: function(e) { let scrollH = e.detail.scrollTop + 30; diff --git a/pages/index/onlineMall/onlineMall.vue b/pages/index/onlineMall/onlineMall.vue index f4a3706..6d6218b 100644 --- a/pages/index/onlineMall/onlineMall.vue +++ b/pages/index/onlineMall/onlineMall.vue @@ -1,27 +1,25 @@ @@ -38,17 +45,94 @@ export default { data() { return { - value: '', - is_focus: true // 是否自动获得焦点 + value: '', // 搜索的值 + is_focus: true, // 是否自动获得焦点 + hot_list: [], // 热门搜索 + history_list: [], // 历史搜索 + max_history_count: 12 // 最多存多少个历史搜索值 } }, onLoad(){ - + this.getHistorySearch(); + this.getHotSearch(); + }, + onHide(){ + this.setHistorySearch(); }, methods: { - customClick(event){ - console.log("点击了", event); - this.$url('/pages/shop/searchList'); + // 获取搜索历史 + getHistorySearch(){ + let history_search = this.$cookieStorage.get('history_search') || []; + this.history_list = JSON.parse(JSON.stringify(history_search)); + }, + // 设置搜索历史 + setHistorySearch(){ + if(this.history_list.length){ + this.$cookieStorage.set('history_search', this.history_list); + }else{ + this.$cookieStorage.clear('history_search'); + } + }, + // TODO 获取热门搜索 待对接请求接口 + getHotSearch(){ + // this.$http.get({ + // api: '' + // }).then(res => { + // console.log("hot", res); + // }) + let list = ['秋上新','纪梵希','雅诗兰黛','中秋','苹果爱普','基督教烧烤']; + this.hot_list = list; + }, + // 激活关键词搜索 + activeKeyWord(value){ + this.value = value; + this.customClick(value); + }, + // 用户按下搜索按钮,或回车键 + search(value){ + this.customClick(value); + }, + // 点击了搜索按钮 + customClick(value){ + this.updateHistory(value).then(() => { + this.$url('/pages/shop/searchList?value='+ value); + }) + }, + // 更新搜索历史列表 + updateHistory(value){ + return new Promise((resolve, reject) => { + let history_list = [...this.history_list]; + if(history_list.includes(value)){ + history_list.map((item, index) => { + if(item == value){ + this.history_list.splice(index, 1); // 删除掉已经存在的key值 + } + }) + this.history_list.unshift(value); // 向头部追加新的key值 + if(this.history_list.length > this.max_history_count){ + this.history_list.pop(); // 如果历史记录超出预设最大范围,将最尾key值移除 + } + }else{ + this.history_list.unshift(value); + if(this.history_list.length > this.max_history_count){ + this.history_list.pop(); + } + } + resolve(value); // 操作完成,回调成功 + }) + }, + // 清空搜索记录 + remove(){ + uni.showModal({ + title: '温馨提示', + content: '确定清空搜索历史吗?', + confirmColor: '#15716E', + success: result => { + if(result.confirm){ + this.history_list = []; + } + } + }) } } } diff --git a/pages/shop/searchList.vue b/pages/shop/searchList.vue index 1035e05..736e455 100644 --- a/pages/shop/searchList.vue +++ b/pages/shop/searchList.vue @@ -36,7 +36,7 @@ }, data() { return { - value: '爱慕先生', + value: '', tab_current: 0, tab_list: [{ name: '商品(8)' @@ -97,6 +97,7 @@ onLoad(options){ let info = uni.getSystemInfoSync(); this.scrollH = info.screenHeight; + this.value = options.value || ''; }, methods: { customClick(){