|
|
<template>
|
|
|
<div class="search-slider">
|
|
|
<div class="search-block">
|
|
|
<input-search ref="search" class="search" v-model="searchValue" :loading="product.isSearching" @enter="enter"></input-search>
|
|
|
<input-search ref="search" class="search" v-model="keyword" :loading="product.isSearching" @enter="enter"></input-search>
|
|
|
<button class="btn btn-trans btn-cancel" @click="cancel">取消</button>
|
|
|
</div>
|
|
|
<div class="search-content" v-show="extend">
|
|
|
<div class="search-list" v-if="!searchEmpty">
|
|
|
<ul>
|
|
|
<a-link
|
|
|
<li
|
|
|
v-for="item in searchList"
|
|
|
:key="item.keyword"
|
|
|
:to="`/channel/search?query=${item.keyword}`">
|
|
|
<li>
|
|
|
{{item.keyword}}
|
|
|
<i class="icon icon-right"></i>
|
|
|
</li>
|
|
|
</a-link>
|
|
|
@click="toSearch(item.keyword)">
|
|
|
{{item.keyword}}
|
|
|
<i class="icon icon-right"></i>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
<div class="search-tip" v-else>
|
...
|
...
|
@@ -42,11 +40,10 @@ export default { |
|
|
name: 'SearchBar',
|
|
|
props: {
|
|
|
full: Boolean,
|
|
|
keyword: String
|
|
|
value: String
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
searchValue: this.keyword,
|
|
|
searchList: [],
|
|
|
searchEmpty: false
|
|
|
};
|
...
|
...
|
@@ -58,6 +55,19 @@ export default { |
|
|
return true;
|
|
|
}
|
|
|
return this.searchEmpty || this.searchList.length;
|
|
|
},
|
|
|
keyword: {
|
|
|
get() {
|
|
|
return this.value;
|
|
|
},
|
|
|
set(val) {
|
|
|
this.$emit('input', val);
|
|
|
if (val) {
|
|
|
this.searchDebounce(val);
|
|
|
} else {
|
|
|
this.clear();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
created() {
|
...
|
...
|
@@ -67,8 +77,16 @@ export default { |
|
|
cancel() {
|
|
|
this.$emit('cancel');
|
|
|
},
|
|
|
clear() {
|
|
|
this.searchEmpty = false;
|
|
|
this.searchList = [];
|
|
|
},
|
|
|
enter() {
|
|
|
this.$router.push(`/channel/search?query=${this.searchValue}`);
|
|
|
this.toSearch(this.value);
|
|
|
},
|
|
|
toSearch(searchKey) {
|
|
|
this.clear();
|
|
|
this.$router.push(`/channel/search?query=${searchKey}`);
|
|
|
},
|
|
|
focus() {
|
|
|
this.$refs.search.focus();
|
...
|
...
|
@@ -76,7 +94,7 @@ export default { |
|
|
async search(val) {
|
|
|
const result = await this.$store.dispatch(FETCH_SEARCH_REQUEST, {keyword: val});
|
|
|
|
|
|
if (result && this.searchValue) {
|
|
|
if (result && this.value) {
|
|
|
if (result.data.length) {
|
|
|
this.searchEmpty = false;
|
|
|
this.searchList = result.data;
|
...
|
...
|
@@ -86,16 +104,6 @@ export default { |
|
|
}
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
searchValue(val) {
|
|
|
if (val) {
|
|
|
this.searchDebounce(val);
|
|
|
} else {
|
|
|
this.searchEmpty = false;
|
|
|
this.searchList = [];
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
components: {InputSearch}
|
|
|
};
|
|
|
</script>
|
...
|
...
|
|