You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
4.8 KiB
185 lines
4.8 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
</head>
|
|
<body>
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<th></th>
|
|
<th>Название</th>
|
|
<th>Цена за 50 гр</th>
|
|
<th>Вес</th>
|
|
<th></th>
|
|
</tr>
|
|
</tbody>
|
|
{% for category_name,category in categories.items %}
|
|
<tbody>
|
|
<tr class="category_tr">
|
|
<th colspan="5">
|
|
<h3>{{ category_name }}</h3>
|
|
</th>
|
|
</tr>
|
|
</tbody>
|
|
<tbody>
|
|
{% for type_name,type in category.items %}
|
|
<tr>
|
|
<td>
|
|
<img src="{{ type.pic }}" alt="{{ type_name }}" height="100px" width="100px">
|
|
|
|
</td>
|
|
<td>
|
|
<label for="{{ type_name }}">{{ type_name }}</label>
|
|
</td>
|
|
<td>{{ type.price }}</td>
|
|
<td>
|
|
<select name="{{ type_name }}" id="{{ type_name }}" onchange="change(value, '{{ type_name }}')">
|
|
{% for m in ms %}
|
|
<option value="{{ m }}">{{ m }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</td>
|
|
<td id="price {{ type_name }}">
|
|
0
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
{% endfor %}
|
|
</table>
|
|
<h3 id="sum_h">0</h3>
|
|
<button onclick="confirm_choice()" id="confirm_button">Подтвердить</button>
|
|
</body>
|
|
<script>
|
|
function getCookie(name) {
|
|
let cookieValue = null;
|
|
if (document.cookie && document.cookie !== '') {
|
|
const cookies = document.cookie.split(';');
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
const cookie = cookies[i].trim();
|
|
// Does this cookie string begin with the name we want?
|
|
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return cookieValue;
|
|
}
|
|
|
|
const csrftoken = getCookie('csrftoken');
|
|
choice = {}
|
|
a = {
|
|
{% for category_name,category in categories.items %}
|
|
{% for type_name,type in category.items %}
|
|
"{{ type_name }}": {
|
|
{% for key,item in type.items%}
|
|
"{{ key }}": "{{ item }}",
|
|
{% endfor %}
|
|
},
|
|
{% endfor %}
|
|
{% endfor %}
|
|
}
|
|
|
|
function change(value, type) {
|
|
choice[type] = parseInt(value)
|
|
const price_el = document.getElementById('price ' + type);
|
|
price_el.innerText = parseInt(value) / 50 * parseInt(a[type].price)
|
|
sum_price()
|
|
}
|
|
|
|
function sum_price() {
|
|
s = 0
|
|
for (let tea in choice) {
|
|
s += choice[tea] / 50 * parseInt(a[tea].price)
|
|
}
|
|
const butt = document.getElementById('confirm_button');
|
|
const sum_h = document.getElementById('sum_h');
|
|
sum_h.innerText = s
|
|
if (s > 7000) {
|
|
butt.disabled = true
|
|
sum_h.style.color = "red"
|
|
} else {
|
|
butt.disabled = false
|
|
sum_h.style.color = "black"
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function confirm_choice() {
|
|
let mychoice = {}
|
|
for (let key in choice)
|
|
mychoice[a[key].preferred] = choice[key]
|
|
const request = new Request(
|
|
'confirm-choice',
|
|
{
|
|
method: 'POST',
|
|
headers: {'X-CSRFToken': csrftoken},
|
|
mode: 'same-origin',
|
|
body: JSON.stringify(mychoice)
|
|
}
|
|
);
|
|
fetch(request).then((response) => response.json())
|
|
.then((data) => {
|
|
console.log(data);
|
|
})
|
|
}
|
|
</script>
|
|
<style>
|
|
table {
|
|
border: none;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
table th {
|
|
font-weight: bold;
|
|
text-align: left;
|
|
border: none;
|
|
padding: 10px 15px;
|
|
background: #d8d8d8;
|
|
font-size: 14px;
|
|
}
|
|
|
|
table tr th:first-child {
|
|
border-radius: 8px 0 0 8px;
|
|
}
|
|
|
|
table tr th:last-child {
|
|
border-radius: 0 8px 8px 0;
|
|
width: 35px;
|
|
}
|
|
|
|
table td {
|
|
text-align: left;
|
|
border: none;
|
|
padding: 10px 15px;
|
|
font-size: 14px;
|
|
vertical-align: top;
|
|
}
|
|
|
|
table tbody tr:nth-child(even) {
|
|
background: #f3f3f3;
|
|
}
|
|
|
|
table tr td:first-child {
|
|
border-radius: 8px 0 0 8px;
|
|
}
|
|
|
|
table tr td:last-child {
|
|
border-radius: 0 8px 8px 0;
|
|
}
|
|
|
|
table tr.category_tr th {
|
|
border-radius: 8px 8px 8px 8px;
|
|
background: #ececec;
|
|
}
|
|
|
|
table h3 {
|
|
margin-top: 0px;
|
|
margin-bottom: 0px;
|
|
}
|
|
</style>
|
|
</html> |