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