footer-bar.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. uni.switchTab({
  76. url: '/pages/cart/index'
  77. })
  78. },
  79. onCollect() {
  80. this.$emit('collect');
  81. },
  82. onAddCart() {
  83. this.$emit('addCart', 3);
  84. },
  85. onNotify() {
  86. this.$emit('notify');
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .footer-bar {
  93. position: fixed;
  94. bottom: 0;
  95. left: 0;
  96. width: 100%;
  97. height: 200rpx;
  98. background: #fff;
  99. display: flex;
  100. align-items: center;
  101. justify-content: space-between;
  102. padding: 0 20rpx;
  103. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  104. z-index: 3;
  105. padding-bottom: env(safe-area-inset-bottom);
  106. .icons-area {
  107. display: flex;
  108. margin-right: 20rpx;
  109. .icon-item {
  110. position: relative;
  111. display: flex;
  112. flex-direction: column;
  113. align-items: center;
  114. justify-content: center;
  115. width: 80rpx;
  116. margin-right: 10rpx;
  117. .bar-icon {
  118. width: 40rpx;
  119. height: 40rpx;
  120. margin-bottom: 6rpx;
  121. }
  122. .bar-icon-2 {
  123. width: 50rpx;
  124. height: 50rpx;
  125. }
  126. text {
  127. font-size: 20rpx;
  128. color: #666;
  129. text-align: center;
  130. }
  131. }
  132. }
  133. .action-btn-area {
  134. flex: 1;
  135. display: flex;
  136. height: 80rpx;
  137. max-width: 360rpx;
  138. .action-btn {
  139. flex: 1;
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. border-radius: 40rpx;
  144. font-size: 30rpx;
  145. color: #fff;
  146. font-weight: bold;
  147. background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
  148. }
  149. }
  150. }
  151. </style>