Fix:3116 【商城小程序】全国特产,搜索页面,右上角需要增加购物车按钮,右上角红点显示当前购物车商品数,点击进入购物车页面

This commit is contained in:
modendeveloper
2025-01-23 02:13:16 +08:00
parent 37266a4e97
commit 0ace784593
3 changed files with 94 additions and 8 deletions
+45 -3
View File
@@ -20,7 +20,11 @@
<u-notice-bar duration="4000" @change="change" :text="recommendKeyword" :icon="' '" color="#999" fontSize="12" bgColor="transparent" direction="column"></u-notice-bar>
</view>
</view>
<view @click="goShoppingCart()" class="item animated bounceIn">
<view class="iconfont icon-gouwuche1">
<text class="num bg-color-lightred" v-if="CartCount > 0">{{ CartCount > 99 ? '99+' : CartCount }}</text>
</view>
</view>
</view>
<view v-if="historyKey.length" class="page-content">
<view
@@ -113,6 +117,10 @@
import {
getSearchPageConfig
} from '@/api/search'
import {
getCartCount,
} from '@/api/store'
import { mapGetters } from 'vuex'
import {trim} from '@/utils'
export default {
name: 'GoodSearch',
@@ -124,16 +132,33 @@ export default {
search: '',
historyKey: [],
rankingArr: [],
recommendKeyword: []
recommendKeyword: [],
CartCount: 0
}
},
computed: mapGetters(['isLogin', 'location', 'userInfo']),
mounted: function () {
this.getData()
this.getCartCount()
},
onShow() {
this.getHistory()
},
methods: {
// 获取购物车数量
getCartCount () {
const isLogin = this.isLogin
if (isLogin) {
getCartCount({
numType: 0
}).then(res => {
this.CartCount = res.data.count
})
}
},
goShoppingCart() {
this.$yrouter.switchTab('/pages/cart')
},
showHistory() {
if(this.search) {
this.showkey = false
@@ -225,6 +250,22 @@ export default {
</script>
<style lang="less">
.iconfont{
position: relative;
}
.item .iconfont.icon-gouwuche1 .num {
right: -15rpx !important;
top: -15rpx!important;
font-size: 20rpx;
position: absolute;
width: 30rpx;
height: 30rpx;
background: #C52733 !important;
color: #fff;
border-radius: 50%;
text-align: center;
padding: 2rpx;
}
.good-search {
min-height: 100vh;
background: #fff !important;
@@ -232,7 +273,8 @@ export default {
.header {
padding: 40rpx 32rpx 32rpx;
background: #F9F9F9;
display: flex;
align-items: center;
.search-box {
width: 686rpx;
height: 72rpx;