Загрузка данных
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Список работников</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #f8f9fa; }
.search-block { background: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.table-wrapper { overflow-x: auto; margin-bottom: 20px; }
table.table-bordered { border: 2px solid #dee2e6; }
table.table-bordered th, table.table-bordered td { border: 1px solid #dee2e6; vertical-align: middle; }
thead.table-dark th { background-color: #343a40; color: white; }
.table tbody tr.selected {
background-color: #cfe2ff !important;
cursor: pointer;
}
.table tbody tr:hover {
background-color: #f1f3f5;
cursor: pointer;
}
.btn-select {
min-width: 120px;
}
#selectedTabnum {
display: none;
}
/* ---------- Новые цвета кнопок ---------- */
#searchBtn {
background-color: #003274;
border-color: #003274;
color: white;
}
#searchBtn:hover {
background-color: #00255a;
border-color: #00255a;
color: white;
}
#resetBtn {
background-color: #7F7F7F;
border-color: #7F7F7F;
color: white;
}
#resetBtn:hover {
background-color: #666666;
border-color: #666666;
color: white;
}
#selectBtn {
background-color: #6CACE4;
border-color: #6CACE4;
color: white;
}
#selectBtn:hover:not(:disabled) {
background-color: #4a8fc9;
border-color: #4a8fc9;
color: white;
}
#selectBtn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* ---------------------------------------- */
</style>
</head>
<body>
<div class="container mt-4">
<h2 class="mb-4 text-center">Список работников</h2>
<form id="selectForm" method="get" action="/employee/__tabnum__/children">
<div class="table-wrapper">
<table class="table table-bordered table-hover" id="workerTable">
<thead class="table-dark">
<tr>
{% for col in column_names %}
<th>{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr data-tabnum="{{ row[0] }}">
<td>{{ row[0] }}</td>
<td>{{ row[1] }}</td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
<td>{{ row[4] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Скрытое поле для хранения выбранного tabnum -->
<input type="hidden" id="selectedTabnum" name="tabnum" value="">
<!-- Блок поиска и кнопки -->
<div class="search-block mt-3">
<div class="row g-3 align-items-end">
<div class="col-md-3">
<label for="tabnum" class="form-label">Табельный номер</label>
<input type="text" class="form-control" id="tabnum" name="tabnum_search" value="{{ search_tabnum }}" placeholder="Например, 06520001">
</div>
<div class="col-md-3">
<label for="fam" class="form-label">Фамилия</label>
<input type="text" class="form-control" id="fam" name="fam" value="{{ search_fam }}" placeholder="Иванов">
</div>
<div class="col-md-6 d-flex gap-2">
<button type="submit" class="btn flex-grow-1" id="searchBtn">Поиск</button>
<a href="/" class="btn flex-grow-1" id="resetBtn">Сбросить</a>
<button type="button" class="btn btn-select" id="selectBtn" disabled>Выбрать</button>
</div>
</div>
</div>
</form>
<script>
(function() {
const table = document.getElementById('workerTable');
const rows = table.querySelectorAll('tbody tr');
const selectBtn = document.getElementById('selectBtn');
const selectedInput = document.getElementById('selectedTabnum');
const selectForm = document.getElementById('selectForm');
let selectedRow = null;
function clearSelection() {
rows.forEach(row => row.classList.remove('selected'));
selectedRow = null;
selectBtn.disabled = true;
selectedInput.value = '';
}
function selectRow(row) {
clearSelection();
row.classList.add('selected');
selectedRow = row;
const tabnum = row.getAttribute('data-tabnum');
selectedInput.value = tabnum;
selectBtn.disabled = false;
}
rows.forEach(row => {
row.addEventListener('click', function(e) {
selectRow(this);
});
});
selectBtn.addEventListener('click', function() {
const tabnum = selectedInput.value;
if (tabnum) {
selectForm.action = '/employee/' + tabnum + '/children';
selectForm.submit();
}
});
})();
</script>
</div>
</body>
</html>