-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
129 lines (111 loc) · 5.47 KB
/
script.js
File metadata and controls
129 lines (111 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Данные о мастерах и услугах
const masters = [
{ id: 1, name: "Анна", coefficient: 1.2 },
{ id: 2, name: "Иван", coefficient: 1.0 },
{ id: 3, name: "Мария", coefficient: 1.5 },
{ id: 4, name: "Олег", coefficient: 1.3 }
];
const services = [
{ id: 1, name: "Стрижка мужская", basePrice: 500 },
{ id: 2, name: "Стрижка женская", basePrice: 700 },
{ id: 3, name: "Стрижка детская", basePrice: 400 },
{ id: 4, name: "Укладка", basePrice: 600 },
{ id: 5, name: "Окрашивание", basePrice: 1200 }
];
// Временные слоты (с 9:00 до 18:00 с интервалом 30 минут)
const timeSlots = [];
for (let hour = 9; hour <= 17; hour++) {
for (let minute = 0; minute < 60; minute += 30) {
const timeString = `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
timeSlots.push(timeString);
}
}
// Загрузка данных при загрузке страницы
document.addEventListener('DOMContentLoaded', function() {
// Заполнение списка мастеров
const masterSelect = document.getElementById('master');
masters.forEach(master => {
const option = document.createElement('option');
option.value = master.id;
option.textContent = `${master.name} (коэфф. ${master.coefficient})`;
masterSelect.appendChild(option);
});
// Заполнение списка услуг
const serviceSelect = document.getElementById('service');
services.forEach(service => {
const option = document.createElement('option');
option.value = service.id;
option.textContent = `${service.name} (${service.basePrice} руб.)`;
serviceSelect.appendChild(option);
});
// Заполнение временных слотов
const timeSelect = document.getElementById('time');
timeSlots.forEach(time => {
const option = document.createElement('option');
option.value = time;
option.textContent = time;
timeSelect.appendChild(option);
});
// Установка минимальной даты как сегодня
const today = new Date().toISOString().split('T')[0];
document.getElementById('date').min = today;
// Обработчик изменения выбора мастера или услуги для пересчета цены
document.getElementById('master').addEventListener('change', calculateTotalPrice);
document.getElementById('service').addEventListener('change', calculateTotalPrice);
// Обработчик формы
document.getElementById('bookingForm').addEventListener('submit', function(e) {
e.preventDefault();
confirmBooking();
});
});
// Функция расчета общей стоимости
function calculateTotalPrice() {
const masterId = parseInt(document.getElementById('master').value);
const serviceId = parseInt(document.getElementById('service').value);
if (masterId && serviceId) {
const master = masters.find(m => m.id === masterId);
const service = services.find(s => s.id === serviceId);
if (master && service) {
const basePrice = service.basePrice;
const totalPrice = Math.round(basePrice * master.coefficient);
document.getElementById('basePrice').textContent = basePrice;
document.getElementById('coefficient').textContent = master.coefficient.toFixed(1);
document.getElementById('totalPrice').textContent = totalPrice;
}
} else {
document.getElementById('basePrice').textContent = '0';
document.getElementById('coefficient').textContent = '1.0';
document.getElementById('totalPrice').textContent = '0';
}
}
// Функция подтверждения бронирования
function confirmBooking() {
const masterId = parseInt(document.getElementById('master').value);
const serviceId = parseInt(document.getElementById('service').value);
const date = document.getElementById('date').value;
const time = document.getElementById('time').value;
if (!masterId || !serviceId || !date || !time) {
alert('Пожалуйста, заполните все поля');
return;
}
const master = masters.find(m => m.id === masterId);
const service = services.find(s => s.id === serviceId);
const totalPrice = Math.round(service.basePrice * master.coefficient);
// Показываем информацию о бронировании
document.getElementById('confirmMaster').textContent = master.name;
document.getElementById('confirmDate').textContent = formatDate(date);
document.getElementById('confirmTime').textContent = time;
document.getElementById('confirmService').textContent = service.name;
document.getElementById('confirmPrice').textContent = totalPrice;
// Скрываем форму и показываем подтверждение
document.querySelector('#bookingForm').classList.add('hidden');
document.querySelector('#confirmation').classList.remove('hidden');
}
// Функция форматирования даты
function formatDate(dateString) {
const date = new Date(dateString);
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear();
return `${day}.${month}.${year}`;
}