uni-cart-fix.vue 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <view class="cart-fix" @click="toCart">
  3. <u-image width="70rpx" height="70rpx" src="/static/cart.png"></u-image>
  4. <u-badge absolute :offset="[15,10]" type="error" :count="count"></u-badge>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. computed: {
  10. count() {
  11. let arr = this.$store.state.vuex_cartList
  12. let count = 0
  13. arr.map(item=>{
  14. count = count + item.shoppingCartGoodsList.length
  15. })
  16. return count
  17. },
  18. },
  19. methods: {
  20. toCart() {
  21. if(this.count > 0){
  22. uni.navigateTo({
  23. url:"/pages/cart/cart"
  24. })
  25. }else{
  26. uni.showToast({
  27. icon:'none',
  28. title:'购物车是空的,请先加入商品'
  29. })
  30. }
  31. }
  32. },
  33. }
  34. </script>
  35. <style lang="scss">
  36. .cart-fix{
  37. position: fixed;
  38. z-index: 100000;
  39. background: rgba($color: #ffffff, $alpha: 0.7);
  40. padding: 10upx;
  41. border-radius: 100%;
  42. bottom: 40%;
  43. right: 2%;
  44. box-shadow: 3upx 3upx 8upx #ccc;
  45. }
  46. </style>