quick-cart.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="component" v-if="show">
  3. <view class="sub-block">
  4. <view class="b-main" @click="onClose()">
  5. <view class="b-info">
  6. <view class="b-count" @click.stop="onJumpCart()">
  7. <view class="iconfont icon-user-cart"></view>
  8. <view class="s-num">{{ cartCount }}</view>
  9. </view>
  10. <view class="b-price">¥{{ totalPrice }}</view>
  11. </view>
  12. <view class="b-action" @click.stop="onPreview()">
  13. <view class="s-submit">去结算</view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'quick-cart',
  22. props: {
  23. show: {
  24. type: Boolean,
  25. default: false
  26. }
  27. },
  28. data() {
  29. return {};
  30. },
  31. computed: {
  32. cartCount() {
  33. return this.$store.getters.cartCount;
  34. },
  35. totalPrice() {
  36. const cartList = this.$store.getters.cartList;
  37. let totalPrice = 0;
  38. for (var i = 0; i < cartList.length; i++) {
  39. totalPrice += parseFloat(cartList[i].goods_price);
  40. }
  41. return totalPrice;
  42. }
  43. },
  44. methods: {
  45. onJumpCart(e) {
  46. console.log('onJumpCart');
  47. uni.navigateTo({
  48. url: '/pages/order/cart'
  49. });
  50. },
  51. onClose(e) {
  52. console.log('onClose');
  53. this.$emit('close');
  54. },
  55. onPreview() {
  56. console.log('onPreview');
  57. const cartList = this.$store.getters.cartList;
  58. let goodsData = [];
  59. for (var i = 0; i < cartList.length; i++) {
  60. let cartItem = cartList[i];
  61. goodsData.push({
  62. cart_id: cartItem.id,
  63. goods_type: cartItem.goods_type,
  64. goods_id: cartItem.goods_id
  65. });
  66. }
  67. uni.navigateTo({
  68. url: '/pages/order/preview?goods_data=' + JSON.stringify(goodsData)
  69. });
  70. }
  71. }
  72. };
  73. </script>
  74. <style>
  75. .sub-block {
  76. position: fixed;
  77. left: 30upx;
  78. bottom: 150upx;
  79. z-index: 100;
  80. width: 690upx;
  81. }
  82. .sub-block image {
  83. width: 100%;
  84. }
  85. .b-main {
  86. width: 690upx;
  87. height: 100upx;
  88. background: #fff;
  89. border: 2upx solid #eee;
  90. border-radius: 50upx;
  91. display: flex;
  92. align-items: center;
  93. justify-content: space-between;
  94. }
  95. .b-info {
  96. padding: 0 20upx;
  97. display: flex;
  98. align-items: center;
  99. }
  100. .b-info .b-count {
  101. position: relative;
  102. }
  103. .b-info .b-count .iconfont {
  104. font-size: 50upx;
  105. width: 60upx;
  106. height: 60upx;
  107. color: #666;
  108. }
  109. .b-info .b-count .s-num {
  110. position: absolute;
  111. right: -10upx;
  112. top: -30upx;
  113. font-size: 24upx;
  114. background: #da5650;
  115. color: #fff;
  116. width: 40upx;
  117. height: 40upx;
  118. line-height: 40upx;
  119. text-align: center;
  120. border-radius: 20upx;
  121. }
  122. .b-info .b-price {
  123. margin-left: 20upx;
  124. font-size: 28upx;
  125. font-weight: bold;
  126. color: #da5650;
  127. }
  128. .b-action {
  129. padding: 0 20upx;
  130. display: flex;
  131. align-items: center;
  132. }
  133. .b-action .s-submit {
  134. padding: 0 50upx;
  135. height: 70upx;
  136. line-height: 70upx;
  137. font-size: 26upx;
  138. color: #fff;
  139. background: #da5650;
  140. border-radius: 35upx;
  141. }
  142. </style>