footer-bar.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="footer-bar safe-area-inset-bottom">
  3. <view class="icons-area">
  4. <view class="icon-item" @click="onHome">
  5. <image src="/pages-sell/static/goods/icon-home.png" class="bar-icon" mode="widthFix"
  6. style="width: 36rpx;"></image>
  7. <text>首页</text>
  8. </view>
  9. <view class="icon-item" @click="onCollect">
  10. <image v-if="isCollect" src="/pages-sell/static/goods/icon-star-active.png" class="bar-icon" mode="aspectFit"></image>
  11. <image v-else src="/pages-sell/static/goods/icon-star.png" class="bar-icon" mode="aspectFit"></image>
  12. <text :style="{ color: isCollect ? '#FFC107' : '#666' }">{{ isCollect ? '已收藏' : '收藏' }}</text>
  13. </view>
  14. <view class="icon-item cart-item" @click="onCart">
  15. <image src="/pages-sell/static/goods/icon-car.png" class="bar-icon" mode="aspectFit"></image>
  16. <text>购物车</text>
  17. <u-badge v-if="cartCount > 0" :count="cartCount" type="error" absolute :offset="[-5, 10]"></u-badge>
  18. </view>
  19. </view>
  20. <view class="action-btn-area">
  21. <view v-if="hasStock" class="action-btn in-stock" @click="onAddCart">
  22. <text>加入购物车</text>
  23. </view>
  24. <view v-else class="action-btn no-stock" @click="onNotify">
  25. <text>到货通知</text>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'FooterBar',
  33. props: {
  34. hasStock: {
  35. type: Boolean,
  36. default: true
  37. },
  38. isCollect: {
  39. type: Boolean,
  40. default: false
  41. }
  42. },
  43. data() {
  44. return {
  45. cartCount: 0
  46. };
  47. },
  48. mounted() {
  49. this.fetchCartCount();
  50. uni.$on('cartCountChanged', this.updateCartCount);
  51. },
  52. beforeDestroy() {
  53. uni.$off('cartCountChanged', this.updateCartCount);
  54. },
  55. methods: {
  56. fetchCartCount() {
  57. const token = uni.getStorageSync('token');
  58. if (token && uni.$u && uni.$u.http) {
  59. uni.$u.http.post('/token/shop/cart/getCount').then(res => {
  60. if (res.code == 200) {
  61. this.cartCount = res.data;
  62. }
  63. });
  64. }
  65. },
  66. updateCartCount(count) {
  67. this.cartCount = count;
  68. },
  69. onHome() {
  70. uni.switchTab({
  71. url: '/pages/sell/index'
  72. })
  73. },
  74. onCart() {
  75. // 获取全局购物车角标并更新本地
  76. if (uni.getStorageSync('token')) {
  77. this.$updateCartBadge();
  78. }
  79. uni.switchTab({
  80. url: '/pages/cart/index'
  81. })
  82. },
  83. onCollect() {
  84. this.$emit('collect');
  85. },
  86. onAddCart() {
  87. this.$emit('addCart', 3);
  88. },
  89. onNotify() {
  90. this.$emit('notify');
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .footer-bar {
  97. position: fixed;
  98. bottom: 0;
  99. left: 0;
  100. width: 100%;
  101. height: 200rpx;
  102. background: #fff;
  103. display: flex;
  104. align-items: center;
  105. justify-content: space-between;
  106. padding: 0 20rpx;
  107. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  108. z-index: 3;
  109. padding-bottom: env(safe-area-inset-bottom);
  110. .icons-area {
  111. display: flex;
  112. margin-right: 20rpx;
  113. .icon-item {
  114. position: relative;
  115. display: flex;
  116. flex-direction: column;
  117. align-items: center;
  118. justify-content: center;
  119. width: 80rpx;
  120. margin-right: 10rpx;
  121. .bar-icon {
  122. width: 40rpx;
  123. height: 40rpx;
  124. margin-bottom: 6rpx;
  125. }
  126. .bar-icon-2 {
  127. width: 50rpx;
  128. height: 50rpx;
  129. }
  130. text {
  131. font-size: 20rpx;
  132. color: #666;
  133. text-align: center;
  134. }
  135. }
  136. }
  137. .action-btn-area {
  138. flex: 1;
  139. display: flex;
  140. height: 80rpx;
  141. max-width: 360rpx;
  142. .action-btn {
  143. flex: 1;
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. border-radius: 40rpx;
  148. font-size: 30rpx;
  149. color: #fff;
  150. font-weight: bold;
  151. background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
  152. }
  153. }
  154. }
  155. </style>