Build browsable norm table with inline composition

This commit is contained in:
anor
2026-12-04 15:46:19 +10:00
parent 30955ccfc9
commit 6520ce9357
7 changed files with 403 additions and 39 deletions
+63 -6
View File
@@ -13,7 +13,7 @@
button { cursor:pointer; }
:focus-visible { outline:3px solid #65aba4; outline-offset:2px; }
a { color:var(--accent); }
.wrap { max-width:1240px; margin:auto; padding:24px clamp(16px,3vw,40px) 64px; }
.wrap { max-width:1600px; margin:auto; padding:24px clamp(16px,3vw,40px) 64px; }
header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:32px; }
.brand { font-weight:750; font-size:1.15rem; text-decoration:none; color:var(--text); }
h1 { font-size:clamp(2rem,4vw,3rem); line-height:1.1; margin:0 0 12px; }
@@ -71,23 +71,72 @@
.draft-row input { width:110px; }
.quote-controls label { min-width:140px; }
.quote-controls #qty { width:125px; }
.workspace { display:grid; grid-template-columns:minmax(230px,280px) minmax(0,1fr); gap:16px; align-items:start; }
.catalog-tree { max-height:72vh; overflow:auto; position:sticky; top:12px; }
.catalog-tree h2 { font-size:1.05rem; }
.tree-list { list-style:none; margin:0; padding:0 0 0 12px; border-left:1px solid var(--line); }
.tree-list button { width:100%; text-align:left; border:0; border-radius:5px; background:transparent;
padding:6px; color:var(--text); font-size:.84rem; line-height:1.3; }
.tree-list button:hover,.tree-list button[aria-current="true"] { background:#e9f4f1; color:var(--accent); }
.table-panel { min-width:0; }
.table-panel h2 { margin:0; }
.table-heading { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
.norm-scroll { max-width:100%; overflow-x:auto; }
.norm-table { min-width:680px; }
.norm-table th { background:#f6f7f4; position:sticky; top:0; z-index:1; }
.norm-table .norm-row:hover { background:#f8faf8; }
.norm-table .norm-row button { min-height:32px; }
.norm-table .norm-name { min-width:240px; }
.norm-table .inline-cell { padding:0; background:#f8faf8; }
.inline-content { padding:16px; border-left:3px solid var(--accent); }
.inline-content .detail-grid { grid-template-columns:minmax(0,1fr); }
.inline-content .panel { border:0; padding:12px 0; background:transparent; }
.inline-content #quote-panel { border-top:1px solid var(--line); }
.inline-actions { display:flex; align-items:center; flex-wrap:wrap; gap:6px; }
.inline-actions .secondary { min-height:32px; }
.breadcrumb { color:var(--muted); font-size:.84rem; overflow-wrap:anywhere; }
.catalog-mobile { display:none; }
[hidden] { display:none !important; }
@media (max-width:760px) { .wrap { padding:18px 14px 40px; } header { margin-bottom:24px; }
.detail-grid,.comparison { grid-template-columns:minmax(0,1fr); } .panel,.card { padding:15px; }
.search-row > *, .controls > label { flex:1 1 100%; } .search-row button { width:100%; }
.quote-controls label { min-width:0; } }
.quote-controls label { min-width:0; } .workspace { display:block; }
.catalog-mobile { display:block; margin-bottom:10px; }
.catalog-tree { position:static; max-height:45vh; margin-bottom:12px; }
.catalog-tree[hidden] { display:none !important; }
.norm-scroll { overflow:visible; }
.norm-table,.norm-table > tbody,.norm-table > tbody > .norm-detail-row,
.norm-table > tbody > .norm-detail-row > td { display:block; min-width:0; width:100%; }
.norm-table thead { display:none; }
.norm-table .norm-row { display:grid; grid-template-columns:minmax(0,1fr) auto;
gap:5px 12px; padding:13px 0; border-top:1px solid var(--line); }
.norm-table .norm-row td { border:0; padding:0; min-width:0; }
.norm-table .norm-row td:nth-child(1) { grid-column:1 / -1; }
.norm-table .norm-row td:nth-child(2) { grid-column:1 / -1; overflow-wrap:anywhere; }
.norm-table .norm-row td:nth-child(3) { grid-column:1; }
.norm-table .norm-row td:nth-child(4) { grid-column:2; }
.norm-table .norm-row td:nth-child(5) { grid-column:1 / -1; }
.norm-table .norm-row .inline-actions { gap:6px; }
.norm-table .norm-row .inline-actions button { flex:1 1 auto; }
.inline-content { padding:12px 10px; }
.inline-content #detail-title { font-size:1.05rem; overflow-wrap:anywhere; }
.inline-content .scroll { overflow-x:auto; }
.inline-content .scroll table { min-width:560px; }
.inline-content .detail-grid { display:block; }
}
</style>
</head>
<body>
<main class="wrap">
<header><a class="brand" href="/">ИНФОСМЕТА</a><a href="/">Вернуться в чат</a></header>
<h1>Подбор норм</h1>
<p class="intro">Найдите работу по названию или шифру, проверьте состав и измеритель, сравните варианты. Цены считаются только по доступной форме выбранной зоны и квартала.</p>
<p class="intro">Выберите сборник и раздел или найдите норму по шифру и названию. Раскройте строку, чтобы увидеть состав работ, ресурсы и источник.</p>
<div id="auth-notice" class="notice" hidden>Нормы можно искать без входа. Для расчёта по ценам и сохранения подборки <a href="/">войдите в Инфосмету</a>.</div>
<form id="search-form" class="panel">
<div class="search-row">
<label for="query">Работа или шифр<input id="query" type="search" maxlength="160" placeholder="Например, монтаж пожарного извещателя" required></label>
<label for="base">Нормативная база<select id="base" aria-label="Нормативная база"></select></label>
<label for="base-type">Сборник<select id="base-type" aria-label="Сборник"></select></label>
<button class="primary" type="submit">Найти нормы</button>
</div>
<div class="examples">Примеры: <button type="button" data-query="монтаж извещателя">монтаж извещателя</button>
@@ -95,8 +144,16 @@
<button type="button" data-query="10-08-002-02">10-08-002-02</button></div>
</form>
<div id="status" class="status" role="status" aria-live="polite"></div>
<section id="results-section" class="section" hidden><h2>Подходящие нормы</h2><div id="results" class="results"></div>
<div class="actions" style="margin-top:16px"><button id="more-results" type="button" class="secondary" hidden>Показать ещё нормы</button></div></section>
<button id="catalog-mobile" class="secondary catalog-mobile" type="button" aria-controls="catalog-tree" aria-expanded="false">Разделы сборника</button>
<div class="workspace section">
<aside id="catalog-tree" class="panel catalog-tree"><h2>Разделы сборника</h2><div id="tree-root"></div></aside>
<section id="results-section" class="panel table-panel" aria-label="Нормы сборника">
<div class="table-heading"><h2 id="results-title">Нормы сборника</h2><span id="result-count" class="hint"></span></div>
<p id="breadcrumb" class="breadcrumb"></p>
<div class="norm-scroll"><table class="norm-table"><thead><tr><th>Шифр</th><th>Наименование</th><th>Ед. изм.</th><th class="num">Базисная стоимость</th><th>Действия</th></tr></thead><tbody id="results"></tbody></table></div>
<div class="actions" style="margin-top:16px"><button id="more-results" type="button" class="secondary" hidden>Показать ещё нормы</button></div>
</section>
</div>
<section id="detail-section" class="section" hidden><div class="detail-grid">
<div class="panel"><h2 id="detail-title">Состав нормы</h2><div id="detail"></div></div>
<div class="panel" id="quote-panel"><h2>Предварительный расчёт</h2><p class="hint">Объём вводится в выбранной единице. Недостающие цены и затраты будут отмечены.</p>
@@ -124,6 +181,6 @@
<section id="compare-section" class="section" hidden><h2>Сравнение норм</h2><p id="compare-warning" class="notice" hidden></p>
<div id="comparison" class="comparison"></div></section>
</main>
<script src="/static/norm-finder.js?v=2026-12-04e" defer></script>
<script src="/static/norm-finder.js?v=2026-12-04f" defer></script>
</body>
</html>
+157 -28
View File
@@ -19,6 +19,12 @@
let savedQuote = null;
let draft = null;
let searchPage = null;
let browsePage = null;
let catalogRows = [];
let requestSeq = 0;
let detailSeq = 0;
let openedRow = null;
let rowSeq = 0;
let subjects = [];
let priceZones = [];
const compared = new Map();
@@ -99,18 +105,33 @@
} catch (e) { status(e.message, true); }
}
function detachDetail() {
$('detail-section').hidden = true;
document.querySelector('.workspace').after($('detail-section'));
if (openedRow) openedRow.hidden = true;
openedRow = null;
}
function renderSearchItem(item) {
const card = node('article', null, 'card');
const head = node('div', null, 'card-head');
head.append(node('span', item.code, 'code'), node('span', item.base_type, 'badge'));
card.append(head, node('h3', item.name || 'Без наименования'),
node('p', (item.base || '') + ' · измеритель: ' + (item.unit || 'не указан'), 'meta'));
if (item.section_path) card.append(node('p', item.section_path, 'hint'));
if (item.match_reason) card.append(node('p', item.match_reason, 'hint'));
if (item.provenance?.decree) card.append(node('p', 'Источник: ' + item.provenance.decree, 'hint'));
const actions = node('div', null, 'actions');
const fragment = document.createDocumentFragment();
const row = node('tr', null, 'norm-row');
const detailRow = node('tr', null, 'norm-detail-row');
detailRow.hidden = true;
const detailCell = node('td', null, 'inline-cell');
detailCell.colSpan = 5;
const inline = node('div', null, 'inline-content');
const variantList = node('div', null, 'variant-list'); variantList.hidden = true;
inline.append(variantList); detailCell.append(inline); detailRow.append(detailCell);
const controlId = 'norm-detail-' + (++rowSeq);
detailRow.id = controlId;
row.append(node('td', item.code, 'code'), node('td', item.name || 'Без наименования', 'norm-name'),
node('td', item.unit || '—'),
node('td', item.cost != null ? money(item.cost) : '—', 'num'));
const actionsCell = node('td');
const actions = node('div', null, 'inline-actions');
const open = node('button', 'Открыть состав', 'primary small');
open.type = 'button'; open.addEventListener('click', () => openDetail(item));
open.type = 'button'; open.setAttribute('aria-controls', controlId);
open.setAttribute('aria-expanded', 'false');
open.addEventListener('click', () => openDetail(item, detailRow));
const compare = node('button', compared.has(key(item)) ? 'Убрать из сравнения' : 'Сравнить', 'secondary small');
compare.type = 'button';
compare.dataset.compareKey = key(item);
@@ -119,11 +140,11 @@
const variants = node('button', 'Варианты таблицы', 'secondary small');
variants.type = 'button';
variants.setAttribute('aria-expanded', 'false');
const variantList = node('div', null, 'variant-list');
variantList.hidden = true;
variants.addEventListener('click', async () => {
if (variants.getAttribute('aria-expanded') === 'true') {
variantList.hidden = true; variants.setAttribute('aria-expanded', 'false'); return;
variantList.hidden = true; variants.setAttribute('aria-expanded', 'false');
if ($('detail-section').parentElement !== inline) detailRow.hidden = true;
return;
}
variants.disabled = true;
try {
@@ -137,7 +158,7 @@
const line = node('div', null, 'variant-row');
const button = node('button', row.code + ' — ' + row.name + ' · ' + (row.unit || 'измеритель не указан'),
'variant-option');
button.type = 'button'; button.addEventListener('click', () => openDetail(row));
button.type = 'button'; button.addEventListener('click', () => openDetail(row, detailRow));
const compareVariant = node('button', compared.has(key(row)) ? 'Убрать из сравнения' : 'Сравнить',
'secondary small');
compareVariant.type = 'button';
@@ -145,12 +166,71 @@
compareVariant.addEventListener('click', () => toggleCompare(row));
line.append(button, compareVariant); variantList.append(line);
}
variantList.hidden = false; variants.setAttribute('aria-expanded', 'true');
variantList.hidden = false; detailRow.hidden = false;
variants.setAttribute('aria-expanded', 'true');
} catch (e) { status(e.message, true); }
finally { variants.disabled = false; }
});
actions.append(open, compare, variants); card.append(actions, variantList);
return card;
actions.append(open, compare, variants); actionsCell.append(actions); row.append(actionsCell);
fragment.append(row, detailRow);
return fragment;
}
function showRows(items, append=false) {
if (!append) { detachDetail(); $('results').replaceChildren(); }
$('results').append(...items.map(renderSearchItem));
}
function fillBaseTypes() {
const base = $('base').value === '2020' ? 'ФЕР-2020' : 'ГЭСН-2022';
const types = catalogRows.filter(row => row.base === base && row.base_type)
.map(row => ({id:row.base_type,name:row.base_type + ' · ' + row.count + ' норм'}));
if (!types.length) types.push({id:base === 'ФЕР-2020' ? 'ФЕР' : 'ГЭСН',name:'Основной сборник'});
fillSelect($('base-type'), types, 'id', 'name', 'Выберите сборник');
$('base-type').selectedIndex = 1;
}
function treeNode(child) {
const li = node('li');
const button = node('button', child.name); button.type = 'button';
button.setAttribute('aria-expanded', 'false');
button.addEventListener('click', () => loadBrowse(child.path, li));
li.append(button);
return li;
}
async function loadBrowse(path='', treeItem=null, nextPage=false) {
const base = $('base').value, baseType = $('base-type').value;
if (!base || !baseType) return;
const offset = nextPage ? browsePage?.offset || 0 : 0;
const seq = ++requestSeq;
status('Загружаю нормы сборника…');
$('more-results').disabled = true;
try {
const data = await api(readPath('browse') + '?' + new URLSearchParams({
base,base_type:baseType,path,limit:publicMode ? '20' : '40',offset:String(offset)}));
if (seq !== requestSeq) return;
if (!nextPage) {
searchPage = null;
showRows(data.items || []);
$('results-title').textContent = path ? path.split(' > ').at(-1) : baseType + ' · все нормы';
$('breadcrumb').textContent = [baseType,path].filter(Boolean).join(' › ');
} else showRows(data.items || [], true);
browsePage = {base,baseType,path,offset:offset + (data.items || []).length};
$('result-count').textContent = 'Показано ' + browsePage.offset;
$('more-results').hidden = !data.has_more;
if (treeItem) {
const button = treeItem.querySelector('button');
button.setAttribute('aria-expanded', 'true');
document.querySelectorAll('#tree-root button[aria-current]').forEach(x => x.removeAttribute('aria-current'));
button.setAttribute('aria-current', 'true');
let list = treeItem.querySelector(':scope > ul');
if (!list) { list = node('ul', null, 'tree-list'); treeItem.append(list); }
list.replaceChildren(...(data.children || []).map(treeNode));
} else if (!path) {
const list = node('ul', null, 'tree-list');
list.replaceChildren(...(data.children || []).map(treeNode));
$('tree-root').replaceChildren(list);
}
status('Откройте строку для состава работ и ресурсов.');
} catch (e) { if (seq === requestSeq) status(e.message, true); }
finally { $('more-results').disabled = false; }
}
async function search(event, nextPage=false) {
event?.preventDefault();
@@ -159,20 +239,23 @@
const offset = nextPage ? searchPage?.offset || 0 : 0;
if (q.length < 2) { status('Введите хотя бы два символа', true); return; }
status('Ищу нормы…');
const seq = ++requestSeq;
if (!nextPage) {
searchPage = null;
$('results-section').hidden = true; $('detail-section').hidden = true;
$('more-results').hidden = true;
}
$('more-results').disabled = true;
try {
const data = await api(readPath('search') + '?' +
new URLSearchParams({q,base,limit:publicMode ? '8' : '12',offset:String(offset)}));
if (seq !== requestSeq) return;
const items = data.items || [];
if (nextPage) $('results').append(...items.map(renderSearchItem));
else $('results').replaceChildren(...items.map(renderSearchItem));
$('results-section').hidden = !$('results').children.length;
showRows(items, nextPage);
browsePage = null;
$('results-title').textContent = 'Результаты поиска';
$('breadcrumb').textContent = q;
searchPage = {q, base, offset:offset + items.length};
$('result-count').textContent = 'Показано ' + searchPage.offset;
$('more-results').hidden = !data.has_more || !items.length;
const correction = data.interpreted_query && data.interpreted_query !== q
? 'Поиск по уточнённой формулировке: «' + data.interpreted_query + '». ' : '';
@@ -208,20 +291,45 @@
table.append(tbody); scroll.append(table); root.append(scroll);
const provenance = item.provenance || {};
const source = [provenance.decree, provenance.file].filter(Boolean).join(' · ');
root.append(node('p', source ? 'Источник: ' + source : 'Источник в индексе не указан', 'hint'));
const sourcePanel = node('details');
sourcePanel.append(node('summary', 'Источник нормы'));
sourcePanel.append(node('p', source || 'Источник в индексе не указан', 'hint'));
if (provenance.dataset) sourcePanel.append(node('p', 'Набор данных: ' + provenance.dataset, 'hint'));
if (provenance.url) {
try {
const url = new URL(provenance.url);
if (url.protocol === 'https:' && url.hostname === 'fgiscs.minstroyrf.ru') {
const link = node('a', 'Открыть официальный набор данных');
link.href = url.href; link.target = '_blank'; link.rel = 'noopener noreferrer';
sourcePanel.append(link);
}
} catch {}
}
root.append(sourcePanel);
if (item.prices?.cost != null) root.append(node('p', 'Базисная стоимость: ' + money(item.prices.cost) +
' (уровень ' + (item.price_level || 'не указан') + '). Это не цена выбранного квартала.', 'notice'));
}
async function openDetail(item) {
async function openDetail(item, targetRow=null) {
const seq = ++detailSeq;
const listing = requestSeq;
status('Загружаю состав нормы…');
try {
active = await detailFor(item); savedQuote = null;
const loaded = await detailFor(item);
if (seq !== detailSeq || listing !== requestSeq || (targetRow && !targetRow.isConnected)) return;
active = loaded; savedQuote = null;
$('quote').replaceChildren(); renderDetail(active);
setUnits(active.unit);
$('calc').disabled = !active.current_price_supported;
if (active.calculation_limitation) $('quote').append(node('p', active.calculation_limitation, 'notice'));
if (targetRow) {
if (openedRow && openedRow !== targetRow) openedRow.hidden = true;
targetRow.querySelector('.inline-content').append($('detail-section'));
targetRow.hidden = false; openedRow = targetRow;
document.querySelectorAll('.norm-row button[aria-controls]').forEach(button =>
button.setAttribute('aria-expanded', String(button.getAttribute('aria-controls') === targetRow.id)));
}
$('detail-section').hidden = false;
$('detail-section').scrollIntoView({behavior:'smooth', block:'start'});
if (targetRow) targetRow.scrollIntoView({behavior:'smooth', block:'nearest'});
status('Состав нормы загружен. Сверьте измеритель и ресурсы.');
} catch (e) { status(e.message, true); }
}
@@ -401,8 +509,12 @@
draft = await api('/api/norm-finder/drafts/' + id);
renderDraft();
const first = draft.positions?.[0];
if (first) await openDetail({base:first.base === '2020' ? 'ФЕР-2020' : 'ГЭСН-2022',
base_type:first.base_type,code:first.code});
if (first) {
const row = {base:first.base === '2020' ? 'ФЕР-2020' : 'ГЭСН-2022',
base_type:first.base_type,code:first.code,name:first.name,unit:first.unit};
showRows([row]);
await openDetail(row, $('results').querySelector('.norm-detail-row'));
}
if (first) { $('qty').value = String(first.quantity); $('unit').value = first.unit; }
const selection = draft.price_selection || {};
if (selection.subject_id) {
@@ -426,6 +538,11 @@
const selection = data.selection || {};
active = await detailFor({base:selection.base === '2020' ? 'ФЕР-2020' : 'ГЭСН-2022',
base_type:selection.base_type, code:selection.code});
showRows([active]);
const target = $('results').querySelector('.norm-detail-row');
target.querySelector('.inline-content').append($('detail-section'));
target.hidden = false; openedRow = target;
$('results').querySelector('button[aria-controls]').setAttribute('aria-expanded', 'true');
renderDetail(active); $('detail-section').hidden = false;
$('calc').disabled = !active.current_price_supported;
$('qty').value = String(selection.quantity); setUnits(active.unit); $('unit').value = selection.unit;
@@ -443,14 +560,26 @@
fillSelect($('base'), bases.map(b => ({id:b === 'ФЕР-2020' ? '2020' : '2022',name:b})),
'id', 'name', 'Выберите базу');
if (bases.length) $('base').selectedIndex = 1;
catalogRows = data.bases || [];
fillBaseTypes();
subjects = data.subjects || [];
if (!publicMode) fillSelect($('subject'), subjects, 'id', 'name', 'Выберите регион');
if (!bases.length) status('Нормативная база пока недоступна', true);
await loadBrowse();
if (!publicMode && !(await restoreDraft())) await restoreQuote();
} catch (e) { status(e.message, true); }
}
$('search-form').addEventListener('submit', search);
$('more-results').addEventListener('click', event => search(event, true));
$('more-results').addEventListener('click', event => browsePage
? loadBrowse(browsePage.path, null, true) : search(event, true));
$('base').addEventListener('change', () => { fillBaseTypes(); loadBrowse(); });
$('base-type').addEventListener('change', () => loadBrowse());
$('catalog-mobile').addEventListener('click', () => {
const tree = $('catalog-tree');
tree.hidden = !tree.hidden;
$('catalog-mobile').setAttribute('aria-expanded', String(!tree.hidden));
});
if (matchMedia('(max-width:760px)').matches) $('catalog-tree').hidden = true;
document.querySelectorAll('[data-query]').forEach(button => button.addEventListener('click', () => {
$('query').value = button.dataset.query; $('search-form').requestSubmit();
}));