diff --git a/mixins/goCartMixins.js b/mixins/goCartMixins.js index 2bc136f..d41ebe0 100644 --- a/mixins/goCartMixins.js +++ b/mixins/goCartMixins.js @@ -33,10 +33,22 @@ export default { unique: '' } }, - cart_num: 1 + cart_num: 1, + CartCount: 0, } }, methods: { + // 获取购物车数量 + getCartCount () { + const isLogin = this.isLogin + if (isLogin) { + getCartCount({ + numType: 0 + }).then(res => { + this.CartCount = res.data.count + }) + } + }, getSkuActiveStatus(selectedSku) { getProductSkuBySelected({ id: this.id, selectedSku }).then(res => { const { success, data } = res @@ -100,7 +112,7 @@ export default { const onlyOne = Object.keys(data.productValue).length === 1 if(onlyOne) { - this.handleOk() + this.handleOk(this.getCartCount()) return } this.attr.cartAttr = !this.isOpen ? true : false diff --git a/pages/shop/GoodsList/index.vue b/pages/shop/GoodsList/index.vue index 8a55008..30308fc 100644 --- a/pages/shop/GoodsList/index.vue +++ b/pages/shop/GoodsList/index.vue @@ -201,7 +201,6 @@ export default { mixins: [goCartMixin], data () { return { - CartCount: 0, webUrl: this.$VUE_APP_RESOURCES_URL, list: [], query: { @@ -232,17 +231,7 @@ export default { !this.loading && this.getList() }, methods: { - // 获取购物车数量 - getCartCount () { - const isLogin = this.isLogin - if (isLogin) { - getCartCount({ - numType: 0 - }).then(res => { - this.CartCount = res.data.count - }) - } - }, + goShoppingCart() { this.$yrouter.switchTab('/pages/cart') },