代码优化

master
waynaqua 12 months ago
parent 4c220f960e
commit e70807d070

@ -1,7 +1,13 @@
<template> <template>
<div class="search-container"> <div class="search-container">
<!--搜索栏--> <div class="search-nav-bar">
<form action="/"> <van-icon
size="16"
name="arrow-left"
style="padding: 12px 0 12px 12px"
@click="$router.back()"
/>
<!--搜索栏-->
<van-search <van-search
v-model="searchText" v-model="searchText"
style="width: 100%" style="width: 100%"
@ -12,10 +18,10 @@
@cancel="onCancel" @cancel="onCancel"
> >
<template #action> <template #action>
<div @click="onCancel"></div> <div @click="onSearch"></div>
</template> </template>
</van-search> </van-search>
</form> </div>
<search-words v-if="searchText == ''" :hot-list="hotList" /> <search-words v-if="searchText == ''" :hot-list="hotList" />
<!--联想建议--> <!--联想建议-->
<search-suggestion v-else-if="searchText" :search-text="searchText" /> <search-suggestion v-else-if="searchText" :search-text="searchText" />
@ -73,7 +79,10 @@ export default {
} }
</script> </script>
<style scoped> <style lang="scss" scoped>
.search-nav-bar {
display: flex;
align-items: center;
}
</style> </style>

@ -1,34 +1,38 @@
<template> <template>
<div class="search-list"> <div class="search-list">
<nav-bar v-model="value" @handleSearch="handleSearch" /> <nav-bar v-model="curSearchText" @handleSearch="handleSearch" />
<filter-bar @changeGoods="changeGoods($event)" /> <div v-if="searchText == curSearchText">
<filter-bar @changeGoods="changeGoods($event)" />
<van-list <van-list
v-model="loading" v-model="loading"
:finished="finished" :finished="finished"
finished-text="没有更多了" finished-text="没有更多了"
:immediate-check="false" :immediate-check="false"
@load="onReachBottom" @load="onReachBottom"
> >
<div class="main"> <div class="main">
<goods-item <goods-item
v-for="(item,idx) in list" v-for="(item,idx) in list"
:key="idx" :key="idx"
:goods-id="item.id" :goods-id="item.id"
:img="item.picUrl" :img="item.picUrl"
:title="item.name" :title="item.name"
:desc="item.brief" :desc="item.brief"
:price="item.retailPrice" :price="item.retailPrice"
:discount="item.counterPrice" :discount="item.counterPrice"
/> />
</div> </div>
</van-list> </van-list>
<van-empty v-if="list && list.length <=0 " description="没有搜索到商品" /> <van-empty v-if="list && list.length <=0 " description="没有搜索到商品" />
</div>
<!--联想建议-->
<search-suggestion v-else :search-text="curSearchText" />
</div> </div>
</template> </template>
<script> <script>
import { getSearchList } from '@/api/search' import { getSearchList } from '@/api/search'
import SearchSuggestion from './modules/Suggest'
import NavBar from './modules/NavBar' import NavBar from './modules/NavBar'
import FilterBar from './modules/FilterBar' import FilterBar from './modules/FilterBar'
import GoodsItem from '@/components/GoodsItem' import GoodsItem from '@/components/GoodsItem'
@ -37,12 +41,14 @@ export default {
name: 'SearchList', name: 'SearchList',
components: { components: {
NavBar, NavBar,
SearchSuggestion,
FilterBar, FilterBar,
GoodsItem GoodsItem
}, },
data() { data() {
return { return {
value: '', searchText: '',
curSearchText: '',
list: [], list: [],
pageSize: 10, pageSize: 10,
pageNum: 1, pageNum: 1,
@ -66,7 +72,8 @@ export default {
duration: 0 duration: 0
}) })
const { keyword } = this.$route.query const { keyword } = this.$route.query
this.value = keyword this.searchText = keyword
this.curSearchText = keyword
this.keyword = keyword this.keyword = keyword
this.getList() this.getList()
}, },

Loading…
Cancel
Save