Fix:3284 【商城小程序】搜索页面—编辑搜索框内容时,浮动词条没有隐藏

This commit is contained in:
modendeveloper
2025-03-01 16:54:33 +08:00
parent e5e63f3e2f
commit 2df4d6f286
+24 -14
View File
@@ -14,10 +14,10 @@
@change="hideHistory"
@compositionstart="hideHistory"
/>
<view class="btn flex-0 flex jc-center ai-center" @click.stop="submit">
<button class="btn flex-0 flex jc-center ai-center" @click.stop="submit">
<text class="iconfont icon-sousuo2"></text>
<text>搜索</text>
</view>
</button>
<view class="swpier-bar" v-if="showkey">
<u-notice-bar duration="4000" @change="change" :text="recommendKeyword" :icon="' '" color="#999" fontSize="12" bgColor="transparent" direction="column"></u-notice-bar>
</view>
@@ -145,11 +145,21 @@ export default {
this.getCartCount()
},
onLoad(opts){
this.keywords1 = opts.keywords
this.search = opts.keywords
},
onShow() {
this.getHistory()
},
watch: {
search(val) {
if(val) {
this.showkey = false
} else {
this.showkey = true
this.currentSearch = this.recommendKeyword[0]
}
}
},
methods: {
// 获取购物车数量
getCartCount () {
@@ -166,6 +176,7 @@ export default {
this.$yrouter.switchTab('/pages/cart')
},
showHistory() {
if(this.showkey) return
if(this.search) {
this.showkey = false
return
@@ -174,10 +185,10 @@ export default {
},
hideHistory() {
// if(!this.search) {
// this.showkey = true
// return
// }
if(!this.search) {
this.showkey = true
return
}
this.showkey = false
},
change(e) {
@@ -186,17 +197,15 @@ export default {
submit() {
if (this.showkey) {
const search = trim(this.currentSearch) || ''
console.log(search);
if (!search) return
this.setHistory(search)
this.search = ''
// this.search = ''
this.toSearch(search)
} else {
const search = trim(this.search) || ''
if (!search) return
this.setHistory(search)
this.search = ''
// this.search = ''
this.toSearch(search)
}
@@ -213,8 +222,8 @@ export default {
this.rankingArr.push(data.ranking1)
this.rankingArr.push(data.ranking2)
this.recommendKeyword = data.recommendKeyword.split(',')
const index = this.recommendKeyword.indexOf(this.keywords1)
[this.recommendKeyword[0], this.recommendKeyword[index]] = [this.recommendKeyword[index], this.recommendKeyword[0]];
// const index = this.recommendKeyword.indexOf(this.keywords1)
// [this.recommendKeyword[0], this.recommendKeyword[index]] = [this.recommendKeyword[index], this.recommendKeyword[0]];
}
})
},
@@ -311,7 +320,8 @@ export default {
border-radius: 28rpx;
color: #fff;
font-weight: bold;
padding: 0;
font-size: 26rpx;
.icon-sousuo2 {
margin-right: 4rpx;
font-size: 28rpx;