cartfixed.vue 1.7 KB

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