import { mapGetters,mapActions } from 'vuex';
export default {
  computed: {
    ...mapGetters(['cartList'])
  },
  onShow() {
    this.setTabBadge()
    this.getCartList()
  },
  methods: {
    ...mapActions({
       getCartList: 'goods/getCartList',
    }),
    setTabBadge() {
      const e = this.cartList
      if (e.length > 0) {
        uni.setTabBarBadge({
          index: 2,
          text: e.length + ''
        })
      } else {
        uni.removeTabBarBadge({
          index: 2
        })
      }
    }
  },
  watch: {
    cartList: {
      immediate: true,
      deep: true,
      handler(e) {
        this.setTabBadge()
      }
    }
  },
}
