cartfixed.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="">
  3. <view class="cart u-flex u-row-center" @click="$u.route('/shopping/cart',{type:'reLaunch'})">
  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. <u-toast ref="uToast"></u-toast>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name:'cartfixed',
  13. data() {
  14. return {
  15. cartTotal:0,
  16. staticUrl:this.$commonConfig.staticUrl,
  17. }
  18. },
  19. onShow() {
  20. },
  21. onLoad() {
  22. },
  23. mounted(){
  24. this.getCartList()
  25. },
  26. methods: {
  27. getCartList(isAdd){
  28. this.$u.api.cartList().then(res=>{
  29. if(isAdd){
  30. if(res.data.total==this.cartTotal){
  31. this.$refs.uToast.show({
  32. type:"success",
  33. message:'已在购物车'
  34. });
  35. }else{
  36. this.$refs.uToast.show({
  37. type:"success",
  38. message:'加入成功'
  39. });
  40. }
  41. }
  42. this.cartTotal = res.data.total;
  43. console.log('getCartList',res);
  44. }).catch(err=>{
  45. console.log('getCartList',err.data);
  46. })
  47. },
  48. addToCart(num){
  49. this.getCartList()
  50. // this.cartTotal += num;
  51. console.log('addToCart',num);
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="scss" scoped>
  57. .cart{
  58. position: fixed;
  59. width: 100rpx;
  60. height: 100rpx;
  61. border-radius: 50%;
  62. right: 20rpx;
  63. bottom: 300rpx;
  64. background: #FFFFFF;
  65. box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.12);
  66. }
  67. </style>