diff --git a/myproject/pos/static/pos/js/terminal.js b/myproject/pos/static/pos/js/terminal.js index f263565..3cba106 100644 --- a/myproject/pos/static/pos/js/terminal.js +++ b/myproject/pos/static/pos/js/terminal.js @@ -12,6 +12,38 @@ function roundQuantity(value, decimals = 3) { return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals); } +/** + * Показывает toast уведомление в правом верхнем углу + * @param {string} type - 'success' или 'error' + * @param {string} message - Текст сообщения + */ +function showToast(type, message) { + const toastId = type === 'success' ? 'orderSuccessToast' : 'orderErrorToast'; + const messageId = type === 'success' ? 'toastMessage' : 'errorMessage'; + const bgClass = type === 'success' ? 'bg-success' : 'bg-danger'; + + const toastElement = document.getElementById(toastId); + const messageElement = document.getElementById(messageId); + + // Устанавливаем сообщение + messageElement.textContent = message; + + // Добавляем цвет фона + toastElement.classList.add(bgClass, 'text-white'); + + // Создаём и показываем toast (автоматически скроется через 3 секунды) + const toast = new bootstrap.Toast(toastElement, { + delay: 3000, + autohide: true + }); + toast.show(); + + // Убираем класс цвета после скрытия + toastElement.addEventListener('hidden.bs.toast', () => { + toastElement.classList.remove(bgClass, 'text-white'); + }, { once: true }); +} + const CATEGORIES = JSON.parse(document.getElementById('categoriesData').textContent); let ITEMS = []; // Будем загружать через API let showcaseKits = JSON.parse(document.getElementById('showcaseKitsData').textContent); @@ -3415,8 +3447,8 @@ async function handleCheckoutSubmit(paymentsData) { if (result.success) { console.log('✅ Заказ успешно создан:', result); - // Успех - alert(`Заказ #${result.order_number} успешно создан!\nСумма: ${result.total_amount.toFixed(2)} руб.`); + // Показываем toast уведомление + showToast('success', `Заказ #${result.order_number} успешно создан! Сумма: ${result.total_amount.toFixed(2)} руб.`); // Очищаем корзину cart.clear(); @@ -3437,12 +3469,12 @@ async function handleCheckoutSubmit(paymentsData) { }, 500); } else { - alert('Ошибка: ' + result.error); + showToast('error', 'Ошибка: ' + result.error); } } catch (error) { console.error('Ошибка checkout:', error); - alert('Ошибка при проведении продажи: ' + error.message); + showToast('error', 'Ошибка при проведении продажи: ' + error.message); } finally { // Разблокируем кнопку const btn = document.getElementById('confirmCheckoutBtn'); diff --git a/myproject/pos/templates/pos/terminal.html b/myproject/pos/templates/pos/terminal.html index a1ba5f9..279bd07 100644 --- a/myproject/pos/templates/pos/terminal.html +++ b/myproject/pos/templates/pos/terminal.html @@ -729,6 +729,28 @@ {% include 'pos/components/edit_cart_item_modal.html' %} + + +