|
|
@@ -12,10 +12,16 @@
|
|
|
<text class="member-banner-action">立即开通 ›</text>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 搜索栏 -->
|
|
|
- <view class="search-bar" @click="goSearch">
|
|
|
- <text class="search-icon">🔍</text>
|
|
|
- <text class="search-placeholder">搜索商品</text>
|
|
|
+ <!-- 搜索栏 + 购物车 -->
|
|
|
+ <view class="search-row">
|
|
|
+ <view class="search-bar" @click="goSearch">
|
|
|
+ <text class="search-icon">🔍</text>
|
|
|
+ <text class="search-placeholder">搜索商品</text>
|
|
|
+ </view>
|
|
|
+ <view class="cart-btn" @click="goCart">
|
|
|
+ <text class="cart-icon">🛒</text>
|
|
|
+ <text v-if="cartCount > 0" class="cart-badge">{{ cartCount > 99 ? '99+' : cartCount }}</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
|
|
|
<!-- Level 1 分类:2列横排网格 -->
|
|
|
@@ -142,7 +148,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { goodsCategory, productList, getMyMembership } from '@/utils/api.js'
|
|
|
+import { goodsCategory, productList, getMyMembership, cartCount } from '@/utils/api.js'
|
|
|
import config from '@/config.js'
|
|
|
export default {
|
|
|
data() {
|
|
|
@@ -159,7 +165,8 @@ export default {
|
|
|
noMore: false,
|
|
|
isLoggedIn: false,
|
|
|
isMember: false,
|
|
|
- recommended: []
|
|
|
+ recommended: [],
|
|
|
+ cartCount: 0
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
@@ -168,10 +175,12 @@ export default {
|
|
|
this.loadCategories()
|
|
|
this.loadProducts()
|
|
|
this.loadRecommended()
|
|
|
+ this.loadCartCount()
|
|
|
},
|
|
|
onShow() {
|
|
|
this.checkMemberStatus()
|
|
|
this.isLoggedIn = !!uni.getStorageSync('token')
|
|
|
+ this.loadCartCount()
|
|
|
},
|
|
|
methods: {
|
|
|
loadCategories() {
|
|
|
@@ -275,6 +284,20 @@ export default {
|
|
|
goSearch() {
|
|
|
uni.navigateTo({ url: '/pages/shop/search/search' })
|
|
|
},
|
|
|
+ goCart() {
|
|
|
+ uni.navigateTo({ url: '/pages/shop/cart/cart' })
|
|
|
+ },
|
|
|
+ loadCartCount() {
|
|
|
+ if (!uni.getStorageSync('token')) {
|
|
|
+ this.cartCount = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ cartCount().then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.cartCount = res.data || 0
|
|
|
+ }
|
|
|
+ }).catch(() => {})
|
|
|
+ },
|
|
|
loadRecommended() {
|
|
|
productList({ page: 1, size: 6, sort: 'sales' }).then(res => {
|
|
|
if (res.code === 200 && res.data) {
|
|
|
@@ -358,12 +381,18 @@ export default {
|
|
|
font-weight: bold;
|
|
|
}
|
|
|
|
|
|
-/* 搜索栏 */
|
|
|
+/* 搜索栏 + 购物车 */
|
|
|
+.search-row {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin: 16rpx 16rpx 0;
|
|
|
+ gap: 16rpx;
|
|
|
+}
|
|
|
.search-bar {
|
|
|
+ flex: 1;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
background: #fff;
|
|
|
- margin: 16rpx 16rpx 0;
|
|
|
padding: 16rpx 24rpx;
|
|
|
border-radius: 50rpx;
|
|
|
border: 1rpx solid #eee;
|
|
|
@@ -376,6 +405,36 @@ export default {
|
|
|
font-size: 26rpx;
|
|
|
color: #bbb;
|
|
|
}
|
|
|
+.cart-btn {
|
|
|
+ position: relative;
|
|
|
+ width: 72rpx;
|
|
|
+ height: 72rpx;
|
|
|
+ border-radius: 50%;
|
|
|
+ background: #fff;
|
|
|
+ border: 1rpx solid #eee;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ flex-shrink: 0;
|
|
|
+}
|
|
|
+.cart-icon {
|
|
|
+ font-size: 36rpx;
|
|
|
+}
|
|
|
+.cart-badge {
|
|
|
+ position: absolute;
|
|
|
+ top: -6rpx;
|
|
|
+ right: -6rpx;
|
|
|
+ min-width: 32rpx;
|
|
|
+ height: 32rpx;
|
|
|
+ line-height: 32rpx;
|
|
|
+ padding: 0 8rpx;
|
|
|
+ border-radius: 16rpx;
|
|
|
+ background: #FF4D4F;
|
|
|
+ color: #fff;
|
|
|
+ font-size: 20rpx;
|
|
|
+ text-align: center;
|
|
|
+ box-sizing: border-box;
|
|
|
+}
|
|
|
|
|
|
/* Member Upgrade Banner */
|
|
|
.member-banner {
|