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.
289 lines
7.2 KiB
289 lines
7.2 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Choose your set of tea</title>
|
|
</head>
|
|
<body>
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<th></th>
|
|
<th>Название</th>
|
|
<th>Цена за минимальную массу</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>
|
|
{{ type_name }}
|
|
</td>
|
|
<td>{{ type.price }}</td>
|
|
<td>
|
|
<div class="select-wrapper">
|
|
<select class="selector" name="{{ type_name }}" id="{{ type_name }}"
|
|
onchange="change(value, '{{ type_name }}', {{ type.ms.1 }})">
|
|
{% for m in type.ms %}
|
|
<option value="{{ m }}">{{ m }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
<div class="select-arrow"></div>
|
|
<div class="select-arrow"></div>
|
|
</div>
|
|
</td>
|
|
<td id="price {{ type_name }}">
|
|
0
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
{% endfor %}
|
|
</table>
|
|
<h3 id="sum_h">0</h3>
|
|
<button class="btn" 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%}
|
|
{% if not key == 'ms' %}
|
|
"{{ key }}": "{{ item }}",
|
|
{% else %}
|
|
"{{ key }}": {{ item }},
|
|
{% endif %}
|
|
{% endfor %}
|
|
},
|
|
{% endfor %}
|
|
{% endfor %}
|
|
}
|
|
|
|
function change(value, type, step) {
|
|
choice[type] = parseInt(value)
|
|
const price_el = document.getElementById('price ' + type);
|
|
price_el.innerText = parseInt(value) / step * 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) => {
|
|
if (data.response == 'ok') {
|
|
window.location.replace("/");
|
|
} else {
|
|
window.alert(data.response)
|
|
}
|
|
})
|
|
}
|
|
</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: 16px;
|
|
vertical-align: center;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
.selector {
|
|
padding-left: 10px;
|
|
}
|
|
|
|
.select-wrapper {
|
|
width: 65px;
|
|
position: relative;
|
|
height: 38px;
|
|
color: #444;
|
|
background: transparent;
|
|
border: 1px solid #bcbcbc;
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
.select-wrapper > select {
|
|
width: 100%;
|
|
height: 37px;
|
|
background: transparent;
|
|
border: 0;
|
|
appearance: none;
|
|
z-index: 1;
|
|
-webkit-appearance: none;
|
|
-moz-appearance: none;
|
|
}
|
|
|
|
.select-wrapper > select::-ms-expand {
|
|
display: none;
|
|
}
|
|
|
|
.select-arrow {
|
|
position: absolute;
|
|
z-index: -1;
|
|
border: 8px solid transparent;
|
|
border-bottom: 0;
|
|
right: 11px;
|
|
}
|
|
|
|
.select-arrow:nth-child(2) {
|
|
top: 15px;
|
|
border-top-color: #bdbdbd;
|
|
}
|
|
|
|
.select-arrow:nth-child(3) {
|
|
top: 13px;
|
|
border-top-color: #FFF;
|
|
}
|
|
|
|
.btn {
|
|
display: inline-block;
|
|
box-sizing: border-box;
|
|
padding: 0 13px;
|
|
margin: 0 15px 15px 0;
|
|
outline: none;
|
|
border: 1px solid transparent;
|
|
border-radius: 3px;
|
|
height: 32px;
|
|
line-height: 32px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
text-decoration: none;
|
|
color: #fff;
|
|
background-color: #65a3be;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
appearance: none;
|
|
touch-action: manipulation;
|
|
}
|
|
|
|
.btn:focus-visible {
|
|
box-shadow: 0 0 0 3px lightskyblue;
|
|
}
|
|
|
|
.btn:hover {
|
|
border-color: transparent;
|
|
background-color: #4986a1;
|
|
color: #fff;
|
|
}
|
|
|
|
.btn:active {
|
|
border-color: #6f9cbc !important;
|
|
background-color: #367089 !important;
|
|
}
|
|
|
|
.btn:disabled {
|
|
background-color: #afafaf;
|
|
color: #fff;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|
|
</html> |