| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <template>
- <view class="footer-bar safe-area-inset-bottom">
- <view class="icons-area">
- <view class="icon-item" @click="onHome">
- <image src="/pages-sell/static/goods/icon-home.png" class="bar-icon" mode="widthFix"
- style="width: 36rpx;"></image>
- <text>首页</text>
- </view>
- <view class="icon-item" @click="onCollect">
- <image v-if="isCollect" src="/pages-sell/static/goods/icon-star-active.png" class="bar-icon" mode="aspectFit"></image>
- <image v-else src="/pages-sell/static/goods/icon-star.png" class="bar-icon" mode="aspectFit"></image>
- <text :style="{ color: isCollect ? '#FFC107' : '#666' }">{{ isCollect ? '已收藏' : '收藏' }}</text>
- </view>
- <view class="icon-item cart-item" @click="onCart">
- <image src="/pages-sell/static/goods/icon-car.png" class="bar-icon" mode="aspectFit"></image>
- <text>购物车</text>
- <u-badge v-if="cartCount > 0" :count="cartCount" type="error" absolute :offset="[-5, 10]"></u-badge>
- </view>
- </view>
- <view class="action-btn-area">
- <view v-if="hasStock" class="action-btn in-stock" @click="onAddCart">
- <text>加入购物车</text>
- </view>
- <view v-else class="action-btn no-stock" @click="onNotify">
- <text>到货通知</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'FooterBar',
- props: {
- hasStock: {
- type: Boolean,
- default: true
- },
- isCollect: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- cartCount: 0
- };
- },
- mounted() {
- this.fetchCartCount();
- uni.$on('cartCountChanged', this.updateCartCount);
- },
- beforeDestroy() {
- uni.$off('cartCountChanged', this.updateCartCount);
- },
- methods: {
- fetchCartCount() {
- const token = uni.getStorageSync('token');
- if (token && uni.$u && uni.$u.http) {
- uni.$u.http.post('/token/shop/cart/getCount').then(res => {
- if (res.code == 200) {
- this.cartCount = res.data;
- }
- });
- }
- },
- updateCartCount(count) {
- this.cartCount = count;
- },
- onHome() {
- uni.switchTab({
- url: '/pages/sell/index'
- })
- },
- onCart() {
- uni.switchTab({
- url: '/pages/cart/index'
- })
- },
- onCollect() {
- this.$emit('collect');
- },
- onAddCart() {
- this.$emit('addCart', 3);
- },
- onNotify() {
- this.$emit('notify');
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .footer-bar {
- position: fixed;
- bottom: 0;
- left: 0;
- width: 100%;
- height: 200rpx;
- background: #fff;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 20rpx;
- box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
- z-index: 3;
- padding-bottom: env(safe-area-inset-bottom);
- .icons-area {
- display: flex;
- margin-right: 20rpx;
- .icon-item {
- position: relative;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 80rpx;
- margin-right: 10rpx;
- .bar-icon {
- width: 40rpx;
- height: 40rpx;
- margin-bottom: 6rpx;
- }
- .bar-icon-2 {
- width: 50rpx;
- height: 50rpx;
- }
- text {
- font-size: 20rpx;
- color: #666;
- text-align: center;
- }
- }
- }
- .action-btn-area {
- flex: 1;
- display: flex;
- height: 80rpx;
- max-width: 360rpx;
- .action-btn {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 40rpx;
- font-size: 30rpx;
- color: #fff;
- font-weight: bold;
- background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
- }
- }
- }
- </style>
|