修复多次添加购物车问题
This commit is contained in:
parent
b88ac1f9c4
commit
6f8cd6e00f
|
|
@ -88,7 +88,7 @@ export default {
|
||||||
tabIndex: 0, // 1评价
|
tabIndex: 0, // 1评价
|
||||||
currentBanner: 1,
|
currentBanner: 1,
|
||||||
pageTitle: "",
|
pageTitle: "",
|
||||||
timer: null,
|
canUseCart: true,
|
||||||
id: 0,
|
id: 0,
|
||||||
detail: {
|
detail: {
|
||||||
title: "",
|
title: "",
|
||||||
|
|
@ -176,10 +176,14 @@ export default {
|
||||||
* 加入购物车
|
* 加入购物车
|
||||||
*/
|
*/
|
||||||
addToCart() {
|
addToCart() {
|
||||||
this.$models.cart.toCart(this.id).then((msg) => {
|
if (this.canUseCart) {
|
||||||
this.$store.dispatch("cart/update", true);
|
this.canUseCart = false;
|
||||||
this.$utils.toast(msg);
|
this.$models.cart.toCart(this.id).then(async (msg) => {
|
||||||
});
|
await this.$store.dispatch("cart/update", true);
|
||||||
|
this.$utils.toast(msg);
|
||||||
|
this.canUseCart = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 创建订单
|
* 创建订单
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<text class="text">{{ briefCart.count }}</text>
|
<text class="text">{{ briefCart.count }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="order-btn" :class="{ active: canUse }" @click="toCart">
|
<view class="order-btn" :class="{ active: canUseCartBtn }" @click="toCart">
|
||||||
<text class="text">去下单</text>
|
<text class="text">去下单</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -37,7 +37,8 @@ export default {
|
||||||
utils: this.$utils,
|
utils: this.$utils,
|
||||||
pageConfig: {},
|
pageConfig: {},
|
||||||
data: [],
|
data: [],
|
||||||
canUse: false,
|
canUseCartBtn: false,
|
||||||
|
canChangeCartNumber: true,
|
||||||
currentId: 0,
|
currentId: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -62,7 +63,7 @@ export default {
|
||||||
onShareAppMessage() {},
|
onShareAppMessage() {},
|
||||||
watch: {
|
watch: {
|
||||||
briefCart(cart) {
|
briefCart(cart) {
|
||||||
this.canUse = cart.count > 0;
|
this.canUseCartBtn = cart.count > 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -74,7 +75,7 @@ export default {
|
||||||
if (this.isLogin) {
|
if (this.isLogin) {
|
||||||
this.$store.dispatch("cart/update");
|
this.$store.dispatch("cart/update");
|
||||||
}
|
}
|
||||||
this.canUse = this.briefCart.count > 0;
|
this.canUseCartBtn = this.briefCart.count > 0;
|
||||||
if (!e.id) {
|
if (!e.id) {
|
||||||
return this.$utils.toast("参数错误");
|
return this.$utils.toast("参数错误");
|
||||||
}
|
}
|
||||||
|
|
@ -123,27 +124,33 @@ export default {
|
||||||
* 数量改变
|
* 数量改变
|
||||||
*/
|
*/
|
||||||
changeNumber(e, id) {
|
changeNumber(e, id) {
|
||||||
if (e.value > 0) {
|
if (this.canChangeCartNumber) {
|
||||||
if (e.type == "add" && e.value == 1) {
|
this.canChangeCartNumber = false;
|
||||||
this.$models.cart.toCart(id).then(() => {
|
if (e.value > 0) {
|
||||||
this.$store.dispatch("cart/update", true);
|
if (e.type == "add" && e.value == 1) {
|
||||||
});
|
this.$models.cart.toCart(id).then(async () => {
|
||||||
|
await this.$store.dispatch("cart/update", true);
|
||||||
|
this.canChangeCartNumber = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$models.cart.change(id, e.type).then(async () => {
|
||||||
|
await this.$store.dispatch("cart/update", true);
|
||||||
|
this.canChangeCartNumber = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$models.cart.change(id, e.type).then(() => {
|
this.$models.cart.delete(id).then(async () => {
|
||||||
this.$store.dispatch("cart/update", true);
|
await this.$store.dispatch("cart/update", true);
|
||||||
|
this.canChangeCartNumber = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.$models.cart.delete(id).then(() => {
|
|
||||||
this.$store.dispatch("cart/update", true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 去下单
|
* 去下单
|
||||||
*/
|
*/
|
||||||
toCart() {
|
toCart() {
|
||||||
if (this.canUse) {
|
if (this.canUseCartBtn) {
|
||||||
this.$utils.toPage("/pages/service/cart");
|
this.$utils.toPage("/pages/service/cart");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue