BottomActionBar.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="bottom-action-bar">
  3. <!-- 左侧:优惠券按钮 -->
  4. <view class="coupon-btn" @click="handleCouponClick">
  5. <image :src="getFileUrl('img/icon/shopBtn1.png')" mode="aspectFit" class="bg-img"></image>
  6. <view class="coupon-content">
  7. <image :src="getFileUrl('img/icon/coupon.png')" mode="widthFix" class="icon-coupon"></image>
  8. <view class="coupon-text">优惠券</view>
  9. </view>
  10. </view>
  11. <!-- 右侧:购物车按钮 -->
  12. <view class="cart-btn">
  13. <image :src="getFileUrl('img/icon/shopBtn2.png')" mode="aspectFit" class="bg-img"></image>
  14. <view class="shop-cart">
  15. <view class="shop-cart-content" @click="handleCartClick">
  16. <image :src="getFileUrl('img/icon/shoppingCart.png')" mode="widthFix" class="icon-shopping-cart"></image>
  17. <view class='number'>{{ totalQuantity }}</view>
  18. <view class="price">
  19. <text class="price-symbol">¥</text>
  20. <text class="price-number">{{ formatPrice(totalPrice) }}</text>
  21. </view>
  22. </view>
  23. <!-- 下单 -->
  24. <view class='order-btn' @click="handleOrderClick">去下单</view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import { computed } from 'vue';
  31. import { getFileUrl } from '@/utils/file.js';
  32. const props = defineProps({
  33. // 购物车数据列表
  34. cartList: {
  35. type: Array,
  36. default: () => []
  37. }
  38. });
  39. const emit = defineEmits(['coupon-click', 'cart-click', 'order-click']);
  40. // 计算总数量
  41. const totalQuantity = computed(() => {
  42. return props.cartList.reduce((sum, item) => {
  43. return sum + (item.quantity || 0);
  44. }, 0);
  45. });
  46. // 计算总价格
  47. const totalPrice = computed(() => {
  48. return props.cartList.reduce((sum, item) => {
  49. const quantity = item.quantity || 0;
  50. const price = item.price || 0;
  51. return sum + (quantity * price);
  52. }, 0);
  53. });
  54. // 格式化价格(显示为整数)
  55. const formatPrice = (price) => {
  56. return Math.round(price).toFixed(0);
  57. };
  58. // 优惠券点击
  59. const handleCouponClick = () => {
  60. emit('coupon-click');
  61. };
  62. // 购物车点击
  63. const handleCartClick = () => {
  64. emit('cart-click');
  65. };
  66. // 下单点击
  67. const handleOrderClick = () => {
  68. if (totalQuantity.value === 0) return;
  69. emit('order-click', {
  70. cartList: props.cartList,
  71. totalPrice: totalPrice.value,
  72. totalQuantity: totalQuantity.value
  73. });
  74. };
  75. </script>
  76. <style lang="scss" scoped>
  77. .bottom-action-bar {
  78. display: flex;
  79. justify-content: space-between;
  80. align-items: center;
  81. border-radius: 0;
  82. padding: 20rpx;
  83. box-sizing: border-box;
  84. position: fixed;
  85. left: 0;
  86. right: 0;
  87. bottom: 0;
  88. z-index: 999;
  89. padding-bottom: env(safe-area-inset-bottom);
  90. background-color: #fff;
  91. box-shadow: 0rpx -11rpx 46rpx 0rpx rgba(0, 0, 0, 0.05);
  92. }
  93. .coupon-btn {
  94. width: 140rpx;
  95. height: 100rpx;
  96. position: relative;
  97. .bg-img {
  98. width: 100%;
  99. height: 100%;
  100. position: absolute;
  101. left: 0;
  102. top: 0;
  103. }
  104. .coupon-content {
  105. position: absolute;
  106. left: 0;
  107. top: 0;
  108. z-index: 1;
  109. width: 100%;
  110. height: 100%;
  111. color: #fff;
  112. text-align: center;
  113. padding-top: 6rpx;
  114. .icon-coupon {
  115. width: 30rpx;
  116. height: 21rpx;
  117. }
  118. .coupon-text {
  119. width: 100%;
  120. font-size: 24rpx;
  121. }
  122. }
  123. }
  124. .cart-btn {
  125. width: 561rpx;
  126. height: 100rpx;
  127. position: relative;
  128. .bg-img {
  129. width: 100%;
  130. height: 100%;
  131. position: absolute;
  132. left: 0;
  133. top: 0;
  134. }
  135. .shop-cart {
  136. display: flex;
  137. align-items: center;
  138. justify-content: space-between;
  139. width: 100%;
  140. height: 100%;
  141. position: absolute;
  142. left: 0;
  143. top: 0;
  144. z-index: 1;
  145. color: #fff;
  146. padding-left: 30rpx;
  147. .shop-cart-content {
  148. display: flex;
  149. align-items: center;
  150. }
  151. .icon-shopping-cart {
  152. width: 76rpx;
  153. height: 76rpx;
  154. }
  155. .price {
  156. display: flex;
  157. align-items: baseline;
  158. color: #FFFFFF;
  159. font-weight: bold;
  160. .price-symbol {
  161. font-size: 24rpx;
  162. margin-right: 2rpx;
  163. }
  164. .price-number {
  165. font-size: 38rpx;
  166. }
  167. }
  168. .number{
  169. display: inline-block;
  170. padding: 2rpx 10rpx;
  171. background-color: #FF4545;
  172. position: absolute;
  173. left: 80rpx;
  174. top: 10rpx;
  175. border-radius: 40rpx;
  176. color: #fff;
  177. font-size: 24rpx;
  178. }
  179. }
  180. .order-btn {
  181. width: 200rpx;
  182. height: 100rpx;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. font-weight: bold;
  187. font-size: 31rpx;
  188. color: #FFFFFF;
  189. }
  190. }
  191. </style>