cartfixed.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <view class="">
  3. <view class="cart u-flex u-row-center" @click="$u.route('/shopping/cart',{type:'redirectTo'})">
  4. <u-icon size="52rpx" class="icon" :name="staticUrl+'/img/cartico.png'"></u-icon>
  5. <u-badge type="error" max="99" :value="cartTotal" :absolute="true" :offset="[0,5]"></u-badge>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name:'cartfixed',
  12. data() {
  13. return {
  14. cartTotal:0,
  15. staticUrl:this.$commonConfig.staticUrl,
  16. }
  17. },
  18. onShow() {
  19. },
  20. onLoad() {
  21. },
  22. mounted(){
  23. this.getCartList()
  24. },
  25. methods: {
  26. getCartList(){
  27. this.$u.api.cartList().then(res=>{
  28. this.cartTotal = res.data.total;
  29. console.log('getCartList',res);
  30. }).catch(err=>{
  31. console.log('getCartList',err.data);
  32. })
  33. },
  34. addToCart(num){
  35. this.getCartList()
  36. // this.cartTotal += num;
  37. console.log('addToCart',num);
  38. }
  39. }
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .cart{
  44. position: fixed;
  45. width: 100rpx;
  46. height: 100rpx;
  47. border-radius: 50%;
  48. right: 20rpx;
  49. bottom: 300rpx;
  50. background: #FFFFFF;
  51. box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.12);
  52. }
  53. </style>