You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
244 lines
6.1 KiB
244 lines
6.1 KiB
<template>
|
|
<view>
|
|
<lf-nav title="搜索" :showIcon="true" @changeHeight="e => nav_height = e"></lf-nav>
|
|
<view class="head">
|
|
<u-search placeholder="请输入商品名或商户名"
|
|
action-text="取消"
|
|
v-model="value"
|
|
@custom="customClick"
|
|
@search="search">
|
|
</u-search>
|
|
</view>
|
|
<view>
|
|
<u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="false" :current="tab_current" @change="tabChange"></u-tabs>
|
|
</view>
|
|
<swiper :current="tab_current" @change="swiperChange" :style="{height: autoHeight}">
|
|
<swiper-item v-for="(tab_item, tab_index) in tab_list" :key="tab_index">
|
|
<scroll-view :scroll-y="true" :style="{height: autoHeight}" @scrolltolower="scrolltolower">
|
|
<view class="scroll-content" v-if="tab_index == 0">
|
|
<lf-waterfall :list="goods_list" ref="searchWaterfall"></lf-waterfall>
|
|
<lf-nocontent src="/static/images/empty.png" v-if="goods_list.length <= 0"></lf-nocontent>
|
|
</view>
|
|
<view class="scroll-content" v-else>
|
|
<view class="shop-box"
|
|
v-for="(item, index) in brand_list" :key="index"
|
|
@click="$url('/pages/shop/shopdetail?id='+ item.id)">
|
|
<image class="shop-img" :src="item.logo"></image>
|
|
<view class="shop-info">
|
|
<view class="lf-line-1">{{ item.name }}</view>
|
|
<view>{{ item.category }}</view>
|
|
</view>
|
|
</view>
|
|
<lf-nocontent src="/static/images/empty.png" v-if="brand_list.length <= 0"></lf-nocontent>
|
|
</view>
|
|
</scroll-view>
|
|
</swiper-item>
|
|
</swiper>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import lfWaterfall from '@/components/lf-waterfall-shopdetails/lf-waterfall.vue';
|
|
export default {
|
|
components: {
|
|
lfWaterfall
|
|
},
|
|
data() {
|
|
return {
|
|
value: '',
|
|
tab_current: 0,
|
|
tab_list: [{
|
|
name: '商品'
|
|
},{
|
|
name: '商户'
|
|
}],
|
|
scrollH: 0,
|
|
nav_height: 0,
|
|
goods_list: [],
|
|
brand_list: [],
|
|
page: 1,
|
|
isPage: true
|
|
}
|
|
},
|
|
computed: {
|
|
autoHeight(){
|
|
return `calc(${this.scrollH}px - ${this.nav_height}px - 124rpx - 86rpx)`;
|
|
}
|
|
},
|
|
onLoad(options){
|
|
let info = uni.getSystemInfoSync();
|
|
this.scrollH = info.screenHeight;
|
|
this.value = options.value || '';
|
|
if(options.value){
|
|
this.getSearchList(options.value);
|
|
}
|
|
},
|
|
methods: {
|
|
// 点击取消,返回上一个页面
|
|
customClick(){
|
|
this.$toBack();
|
|
},
|
|
// 开始搜索
|
|
search(value){
|
|
if(!value || !value.trim()) return this.$msg('搜索内容不能为空');
|
|
// 重置页面请求值
|
|
this.page = 1;
|
|
this.isPage = true;
|
|
this.$refs.searchWaterfall[0].clear();
|
|
// 执行上一个页面的保存搜索历史
|
|
let pages = getCurrentPages();
|
|
let beforePage = pages[pages.length - 2]; // 上个页面
|
|
if(beforePage){
|
|
beforePage.$vm.updateHistory(value).then(() => {
|
|
beforePage.$vm.setHistorySearch();
|
|
})
|
|
this.getSearchList(value);
|
|
}else{
|
|
this.$msg('页面路径出错,当前搜索值将不被记录搜索历史').then(() => {
|
|
this.getSearchList(value);
|
|
})
|
|
}
|
|
},
|
|
// 获取搜索列表
|
|
getSearchList(value){
|
|
uni.showLoading({
|
|
title: '正在搜索中'
|
|
})
|
|
this.$http.get({
|
|
api: 'api/store/list',
|
|
data: {
|
|
keyword: value,
|
|
page: this.page
|
|
}
|
|
}).then(res => {
|
|
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);
|
|
}
|
|
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})`;
|
|
}else{
|
|
this.$msg('该关键词没有数据哦~')
|
|
}
|
|
}else{
|
|
this.$msg(res.data.message || '服务器错误,请稍后再试');
|
|
}
|
|
uni.hideLoading();
|
|
}).catch(err => uni.hideLoading());
|
|
},
|
|
// 切换tab
|
|
tabChange(event){
|
|
this.tab_current = event;
|
|
},
|
|
// 切换swiper
|
|
swiperChange(event){
|
|
this.tab_current = event.detail.current;
|
|
},
|
|
// 商品scroll滚动到底部
|
|
scrolltolower(){
|
|
// 只做商品加载下一页,品牌不做
|
|
if(this.tab_current == 0){
|
|
if(this.isPage){
|
|
this.page++;
|
|
this.getSearchList(this.value);
|
|
}else{
|
|
this.$msg('没有更多啦~');
|
|
}
|
|
}else{
|
|
this.$msg('没有更多啦~');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.head{
|
|
padding: 30rpx 32rpx;
|
|
}
|
|
.scroll-content{
|
|
padding: 30rpx 32rpx;
|
|
}
|
|
.shop-box{
|
|
width: 100%;
|
|
height: 100rpx;
|
|
display: flex;
|
|
&:nth-child(n+2){
|
|
margin-top: 60rpx;
|
|
}
|
|
.shop-img{
|
|
width: 100rpx;
|
|
height: 100rpx;
|
|
background-color: #EEEEEE;
|
|
border-radius: 5rpx;
|
|
margin-right: 15rpx;
|
|
}
|
|
.shop-info{
|
|
width: 570rpx;
|
|
height: 100rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
&>view:nth-child(1){
|
|
font-size: 36rpx;
|
|
color: #222222;
|
|
font-weight: bold;
|
|
}
|
|
&>view:nth-child(2){
|
|
font-size: 24rpx;
|
|
color: #777777;
|
|
}
|
|
}
|
|
}
|
|
|
|
// tabs 样式修改
|
|
/deep/.u-scroll-box {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
|
|
}
|
|
/deep/.u-scroll-box .u-tab-bar {
|
|
background-color: #15716E!important;
|
|
width: 80rpx!important;
|
|
position: absolute;
|
|
left: 0;
|
|
bottom: -12rpx;
|
|
}
|
|
|
|
/deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
|
|
background-color: #15716E!important;
|
|
width: 56rpx!important;
|
|
position: absolute;
|
|
height: 5rpx!important;
|
|
left: 8rpx;
|
|
bottom: -4rpx;
|
|
}
|
|
|
|
/deep/ .u-tab-item {
|
|
font-size: 28rpx!important;
|
|
}
|
|
</style>
|