Enzo 4 years ago
parent
commit
8c9e0f9652
  1. 85
      pages/shop/searchList.vue

85
pages/shop/searchList.vue

@ -70,7 +70,8 @@
this.scrollH = info.screenHeight; this.scrollH = info.screenHeight;
this.value = options.value || ''; this.value = options.value || '';
if(options.value){ if(options.value){
this.getSearchList(options.value);
this.getSearchGoodsList(options.value);
this.getSearchBrandList(options.value);
} }
}, },
methods: { methods: {
@ -92,15 +93,17 @@
beforePage.$vm.updateHistory(value).then(() => { beforePage.$vm.updateHistory(value).then(() => {
beforePage.$vm.setHistorySearch(); beforePage.$vm.setHistorySearch();
}) })
this.getSearchList(value);
this.getSearchGoodsList(value);
this.getSearchBrandList(value);
}else{ }else{
this.$msg('页面路径出错,当前搜索值将不被记录搜索历史').then(() => { this.$msg('页面路径出错,当前搜索值将不被记录搜索历史').then(() => {
this.getSearchList(value);
this.getSearchGoodsList(value);
this.getSearchBrandList(value);
}) })
} }
}, },
//
getSearchList(value){
//
getSearchGoodsList(value){
uni.showLoading({ uni.showLoading({
title: '正在搜索中' title: '正在搜索中'
}) })
@ -111,44 +114,56 @@
page: this.page page: this.page
} }
}).then(res => { }).then(res => {
uni.hideLoading();
if(res.data.status){ if(res.data.status){
// TODO
if(this.$isRight(res.data.data)){
let goods = res.data.data.goods;
let brand = res.data.data.brand;
let isPage = this.$isRight(goods.next_page_url);
this.isPage = isPage;
let list = goods.data.map(item => {
return {
id: item.id,
original_price: item.min_market_price,
picture: item.img,
pictures: [item.img],
price: item.min_price,
sale: item.sale_count,
title: item.name
}
})
if(this.page == 1){
this.goods_list = list;
}else{
this.goods_list.push(...list);
let goods = res.data.data || [];
let pagination = res.data.meta.pagination;
let isPage = pagination.current_page != pagination.total_pages;
this.isPage = isPage;
if(goods.length <= 0){
this.tab_list[0].name = `商品(0)`;
return;
}
let list = goods.map(item => {
return {
id: item.id,
original_price: item.market_price,
picture: item.img,
pictures: [item.img],
price: item.sell_price,
sale: item.sale_count,
title: item.name
} }
console.log("this.goods_list", this.goods_list)
this.brand_list = brand;
this.tab_list[1].name = `商户(${brand.length})`;
this.tab_list[0].name = `商品(${this.goods_list.length})`;
})
if(this.page == 1){
this.goods_list = list;
}else{ }else{
this.$msg('该关键词没有数据哦~')
this.goods_list.push(...list);
} }
this.tab_list[0].name = `商品(${this.goods_list.length})`;
}else{ }else{
this.$msg(res.data.message || '服务器错误,请稍后再试'); this.$msg(res.data.message || '服务器错误,请稍后再试');
} }
uni.hideLoading();
}).catch(err => uni.hideLoading()); }).catch(err => uni.hideLoading());
}, },
//
getSearchBrandList(value){
this.$http.get({
api: 'api/brand',
data: {
name: value
}
}).then(res => {
if(res.data.status){
let list = res.data.data.list || [];
this.brand_list = list;
this.tab_list[1].name = `商户(${list.length})`;
}else{
this.$msg(res.data.message || '服务器错误,请稍后再试');
}
})
},
// tab // tab
tabChange(event){ tabChange(event){
this.tab_current = event; this.tab_current = event;
@ -163,7 +178,7 @@
if(this.tab_current == 0){ if(this.tab_current == 0){
if(this.isPage){ if(this.isPage){
this.page++; this.page++;
this.getSearchList(this.value);
this.getSearchGoodsList(this.value);
}else{ }else{
this.$msg('没有更多啦~'); this.$msg('没有更多啦~');
} }

Loading…
Cancel
Save