cartfixed.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. uni.showToast({
  32. title:'已在购物车',
  33. icon:'success'
  34. })
  35. // this.$refs.uToast.show({
  36. // type:"success",
  37. // message:'已在购物车'
  38. // });
  39. }else{
  40. uni.showToast({
  41. title:'加入成功',
  42. icon:'success'
  43. })
  44. // this.$refs.uToast.show({
  45. // type:"success",
  46. // message:'加入成功'
  47. // });
  48. }
  49. }
  50. this.cartTotal = res.data.total;
  51. console.log('getCartList',res);
  52. }).catch(err=>{
  53. console.log('getCartList',err.data);
  54. })
  55. },
  56. addToCart(num){
  57. this.getCartList()
  58. // this.cartTotal += num;
  59. console.log('addToCart',num);
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .cart{
  66. position: fixed;
  67. width: 100rpx;
  68. height: 100rpx;
  69. border-radius: 50%;
  70. right: 20rpx;
  71. bottom: 300rpx;
  72. background: #FFFFFF;
  73. box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.12);
  74. }
  75. </style>