feat(product): change router history driver, change add to cart behaviour
This commit is contained in:
@@ -80,6 +80,7 @@
|
||||
</div>
|
||||
|
||||
<Quantity
|
||||
v-if="isInCart === false"
|
||||
:modelValue="quantity"
|
||||
@update:modelValue="setQuantity"
|
||||
size="lg"
|
||||
@@ -91,7 +92,7 @@
|
||||
|
||||
<script setup>
|
||||
import {computed, onMounted, ref} from "vue";
|
||||
import {useRoute} from 'vue-router'
|
||||
import {useRoute, useRouter} from 'vue-router'
|
||||
import ProductOptions from "../components/ProductOptions/ProductOptions.vue";
|
||||
import {useCartStore} from "../stores/CartStore.js";
|
||||
import ProductImageSwiper from "../components/ProductImageSwiper.vue";
|
||||
@@ -105,6 +106,7 @@ const product = ref({});
|
||||
const cart = useCartStore();
|
||||
const quantity = ref(1);
|
||||
const error = ref('');
|
||||
const router = useRouter();
|
||||
|
||||
const isInCart = ref(false);
|
||||
const btnText = computed(() => isInCart.value ? 'В корзине' : 'Купить');
|
||||
@@ -126,9 +128,16 @@ const canAddToCart = computed(() => {
|
||||
async function actionBtnClick() {
|
||||
try {
|
||||
error.value = '';
|
||||
await cart.addProduct(productId.value, product.value.name, product.value.price, quantity.value, product.value.options);
|
||||
isInCart.value = true;
|
||||
window.Telegram.WebApp.HapticFeedback.notificationOccurred('success');
|
||||
|
||||
if (isInCart.value === false) {
|
||||
await cart.addProduct(productId.value, product.value.name, product.value.price, quantity.value, product.value.options);
|
||||
isInCart.value = true;
|
||||
window.Telegram.WebApp.HapticFeedback.notificationOccurred('success');
|
||||
} else {
|
||||
window.Telegram.WebApp.HapticFeedback.selectionChanged();
|
||||
await router.push({'name': 'cart'});
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
await window.Telegram.WebApp.HapticFeedback.notificationOccurred('error');
|
||||
error.value = e.message;
|
||||
|
||||
Reference in New Issue
Block a user