diff --git a/README.md b/README.md index 815815049b4ee162d57dad5ff5fdbcfff8708204..7cadbd45362393b27d98dda7cd6cf1e573500fbe 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ vue2 + vue-rotuer2 + vuex2 + webpack + ES6/7 + fetch + sass + flex + svg + http- - [x] 选择城市 -- 完成 - [x] 搜索地址 -- 完成 - [x] 展示所选地址附近商家列表 -- 完成 -- [ ] 搜索美食,餐馆 +- [x] 搜索美食,餐馆 -- 完成 - [ ] 根据距离、销量、评分、特色菜等进行排序和筛选 - [ ] 单个餐馆的详细信息展示,商品列表,优惠活动 - [ ] 餐馆及单个商品的评价列表展示、筛选 diff --git a/src/components/common/shoplist.vue b/src/components/common/shoplist.vue index 8b7bad4a6a2d32822116fcfc2f2bf13e9180709a..4f7052c1054febaf7f4466c4813ff344b5116e89 100644 --- a/src/components/common/shoplist.vue +++ b/src/components/common/shoplist.vue @@ -1,6 +1,6 @@ @@ -54,12 +62,13 @@ import {getStore, setStore} from '../../config/mUtils' export default { data(){ return { - geohash: '', // - searchValue: '', // - restaurantList: [], // - imgBaseUrl, // - searchHistory: [], // - showHistory: true, // + geohash: '', // msite页面传递过来的地址信息 + searchValue: '', // 搜索内容 + restaurantList: [], // 搜索返回的结果 + imgBaseUrl, // 图片域名地址 + searchHistory: [], // 搜索历史记录 + showHistory: true, // 是否显示历史记录,只有在返回搜索结果后隐藏 + emptyResult: false, // 搜索结果为空时显示 } }, created(){ @@ -76,12 +85,16 @@ export default { headTop }, methods:{ + //点击提交按钮,搜索结果并显示,同时将搜索内容存入历史记录 async searchTarget(){ if (!this.searchValue) { return } + //隐藏历史记录 this.showHistory = false; + //获取搜索结果 this.restaurantList = await searchRestaurant(this.geohash, this.searchValue); + this.emptyResult = !this.restaurantList.length; /** * 点击搜索结果进入下一页面时进行判断是否已经有一样的历史记录 * 如果没有则新增,如果有则不做重复储存,判断完成后进入下一页 @@ -103,16 +116,25 @@ export default { } setStore('searchHistory',this.searchHistory) }, + //搜索结束后,删除搜索内容直到为空时清空搜索结果,并显示历史记录 checkInput(){ if (this.searchValue === '') { - this.showHistory = true; - this.restaurantList = []; + this.showHistory = true; //显示历史记录 + this.restaurantList = []; //清空搜索结果 + this.emptyResult = false; //隐藏搜索为空提示 } + }, + //点击删除按钮,删除当前历史记录 + deleteHistory(index){ + this.searchHistory.splice(index, 1); + setStore('searchHistory',this.searchHistory); + }, + //清除所有历史记录 + clearAllHistory(){ + this.searchHistory = []; + setStore('searchHistory',this.searchHistory); } - }, - computed:{ - - }, + } } @@ -200,4 +222,37 @@ export default { } } } + .search_history{ + .history_list{ + background-color: #fff; + border-bottom: 0.025rem solid $bc; + @include font(0.7rem, 2rem); + padding: 0 0.3rem; + display: flex; + justify-content: space-between; + align-items: center; + .history_text{ + display: inline-block; + width: 80%; + } + .delete_icon{ + @include wh(1rem, 1rem); + } + } + .clear_history{ + background-color: #fff; + color: $blue; + @include font(.7rem, 2rem); + font-weight: bold; + text-align: center; + } + } + .search_none{ + margin: 0 auto; + @include font(0.65rem, 1.75rem); + color: #333; + background-color: #fff; + text-align: center; + margin-top: 0.125rem; + } diff --git a/src/service/getData.js b/src/service/getData.js index cb5da5f271dc2ec78dec8ef12b18cdd95401c7c6..b96dbe5bc3a649acf0ec73ad52e6945f88705b12 100644 --- a/src/service/getData.js +++ b/src/service/getData.js @@ -34,11 +34,11 @@ import * as search from './tempdata/search' /** * 获取msite商铺列表 */ -//export const msiteShopList = (latitude, longitude, offset) => fetch('GET', '/shopping/restaurants', {latitude, longitude, offset, limit: '20', 'extras[]':'activities'}) +//export const shopList = (latitude, longitude, offset, restaurant_category_id = '') => fetch('GET', '/shopping/restaurants', {latitude, longitude, offset, limit: '20', 'extras[]':'activities', keyword: '', restaurant_category_id}) /** - * 获取msite商铺列表 + * 获取search页面搜索结果 */ -//export const searchRestaurant = (geohash, keyword) => fetch('GET', '/v4/restaurants', {'extras[]':'restaurant_activity', geohash, keyword, type: 'search'}) +export const searchRestaurant = (geohash, keyword) => fetch('GET', '/v4/restaurants', {'extras[]':'restaurant_activity', geohash, keyword, type: 'search'}) @@ -56,6 +56,6 @@ export const currentcity = number => setpromise(city.currentcity); export const searchplace = (cityid, value) => setpromise(city.searchdata); export const msiteAdress = geohash => setpromise(msite.msiteAdress); export const msiteFoodTypes = geohash => setpromise(msite.foodTypes); -export const msiteShopList = (latitude, longitude, offset) => setpromise(msite.shopList); -export const searchRestaurant = (geohash, keyword) => setpromise(search.searchData); +export const shopList = (latitude, longitude, offset) => setpromise(msite.shopList); +//export const searchRestaurant = (geohash, keyword) => setpromise(search.searchData);