Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -111,51 +111,56 @@ function updateCart() {
|
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
});
|
| 126 |
-
});
|
| 127 |
|
| 128 |
-
// Открытие/закрытие модального окна корзины
|
| 129 |
-
const cartIcon = document.getElementById('cartIcon');
|
| 130 |
-
const cartModal = document.getElementById('cartModal');
|
| 131 |
-
const closeModal = document.getElementById('closeModal');
|
| 132 |
|
| 133 |
-
cartIcon.addEventListener('click', () => {
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
});
|
| 137 |
|
| 138 |
-
closeModal.addEventListener('click', () => {
|
| 139 |
-
|
| 140 |
-
});
|
| 141 |
|
| 142 |
-
// Очистка корзины
|
| 143 |
-
document.getElementById('clearCartBtn').addEventListener('click', () => {
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
});
|
| 148 |
|
| 149 |
-
// Рассчитать стоимость
|
| 150 |
-
document.getElementById('calculateBtn').addEventListener('click', () => {
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
| 159 |
});
|
| 160 |
|
| 161 |
// Инициализация корзины при загрузке страницы
|
|
|
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
| 114 |
+
// Убедимся, что кнопки добавления в корзину работают
|
| 115 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 116 |
+
document.querySelectorAll('.add-to-cart-btn').forEach(button => {
|
| 117 |
+
button.addEventListener('click', () => {
|
| 118 |
+
const serviceCard = button.closest('.service-card');
|
| 119 |
+
const serviceName = serviceCard.getAttribute('data-service');
|
| 120 |
+
if (!cart.includes(serviceName)) {
|
| 121 |
+
cart.push(serviceName);
|
| 122 |
+
updateCart();
|
| 123 |
+
alert(`${serviceName} добавлено в корзину!`);
|
| 124 |
+
} else {
|
| 125 |
+
alert(`${serviceName} уже в корзине!`);
|
| 126 |
+
}
|
| 127 |
+
});
|
| 128 |
});
|
|
|
|
| 129 |
|
| 130 |
+
// Открытие/закрытие модального окна корзины
|
| 131 |
+
const cartIcon = document.getElementById('cartIcon');
|
| 132 |
+
const cartModal = document.getElementById('cartModal');
|
| 133 |
+
const closeModal = document.getElementById('closeModal');
|
| 134 |
|
| 135 |
+
cartIcon.addEventListener('click', () => {
|
| 136 |
+
cartModal.style.display = 'flex';
|
| 137 |
+
updateCart();
|
| 138 |
+
});
|
| 139 |
|
| 140 |
+
closeModal.addEventListener('click', () => {
|
| 141 |
+
cartModal.style.display = 'none';
|
| 142 |
+
});
|
| 143 |
|
| 144 |
+
// Очистка корзины
|
| 145 |
+
document.getElementById('clearCartBtn').addEventListener('click', () => {
|
| 146 |
+
cart = [];
|
| 147 |
+
updateCart();
|
| 148 |
+
alert('Корзина очищена!');
|
| 149 |
+
});
|
| 150 |
|
| 151 |
+
// Рассчитать стоимость
|
| 152 |
+
document.getElementById('calculateBtn').addEventListener('click', () => {
|
| 153 |
+
if (cart.length > 0) {
|
| 154 |
+
const message = `Здравствуйте! Интересуют следующие услуги: ${cart.join(', ')}. Прошу рассчитать стоимость.`;
|
| 155 |
+
const whatsappUrl = `https://wa.me/996500398754?text=${encodeURIComponent(message)}`;
|
| 156 |
+
window.open(whatsappUrl, '_blank');
|
| 157 |
+
cartModal.style.display = 'none';
|
| 158 |
+
cart = []; // Очищаем корзину после отправки
|
| 159 |
+
updateCart();
|
| 160 |
+
} else {
|
| 161 |
+
alert('Пожалуйста, выберите хотя бы одну услугу!');
|
| 162 |
+
}
|
| 163 |
+
});
|
| 164 |
});
|
| 165 |
|
| 166 |
// Инициализация корзины при загрузке страницы
|