feat(ui/core): срез 6.2 — правка сметы → пересчёт ДВИЖКОМ (не JS)
Объёмы в панели редактируемы (input); «Пересчитать движком» → POST /api/recalc → estimate_contract.calc_estimate в threadpool (не блокирует сервер) → новая панель с детерминир. пересчётом. JS не считает — только движок. Браузер-verified (100→250 → итог пересчитан). APP_VERSION 2026-07-17r.
This commit is contained in:
+43
-3
@@ -126,6 +126,8 @@ button { font-family: inherit; }
|
||||
.est-actions { padding: .5rem .9rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
|
||||
.est-dl { font-size: .82rem; padding: .35rem .8rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-sunken); color: var(--text); cursor: pointer; }
|
||||
.est-dl:hover { border-color: var(--accent); color: var(--accent); }
|
||||
.est-qty { width: 5.5rem; padding: .15rem .3rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-card); color: var(--text); font-size: .8rem; text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.est-qty:focus { border-color: var(--accent); outline: none; }
|
||||
.msg-system { align-self: center; background: var(--system-bg); border: none; font-size: .8rem; color: var(--system-text); box-shadow: none; padding: .4rem .8rem; }
|
||||
.typing { align-self: flex-start; color: var(--text-light); font-style: italic; font-size: .85rem; padding: .4rem 0; }
|
||||
|
||||
@@ -1257,17 +1259,28 @@ function addEstimatePanel(data) {
|
||||
const th = document.createElement('th'); th.textContent = h; thead.appendChild(th);
|
||||
});
|
||||
table.appendChild(thead);
|
||||
const editable = !!(data.positions || []).some(p => p.code); // движок сможет пересчитать
|
||||
(data.positions || []).forEach((p, i) => {
|
||||
const tr = document.createElement('tr');
|
||||
const cells = [i + 1, p.code || '', p.name || '', p.unit || '',
|
||||
p.qty != null ? p.qty : '', fmtMoney(p.unit_cost), fmtMoney(p.total)];
|
||||
cells.forEach((c, ci) => {
|
||||
const td = document.createElement('td');
|
||||
td.textContent = c;
|
||||
if (ci >= 4) td.className = 'num'; // числовые колонки — правое выравнивание/tabular
|
||||
if (ci === 4 && editable && p.code) {
|
||||
// объём — редактируемый; правка пересчитывается ДВИЖКОМ (не JS)
|
||||
const inp = document.createElement('input');
|
||||
inp.type = 'number'; inp.step = 'any'; inp.className = 'est-qty';
|
||||
inp.value = p.qty != null ? p.qty : '';
|
||||
inp.setAttribute('aria-label', 'Объём: ' + (p.name || p.code));
|
||||
inp.dataset.code = p.code; if (p.unit) inp.dataset.unit = p.unit;
|
||||
td.appendChild(inp); td.className = 'num';
|
||||
} else {
|
||||
td.textContent = c;
|
||||
if (ci >= 4) td.className = 'num';
|
||||
}
|
||||
tr.appendChild(td);
|
||||
});
|
||||
if (p.unresolved) tr.classList.add('est-unresolved'); // подсветить нерассчитанную позицию
|
||||
if (p.unresolved) tr.classList.add('est-unresolved');
|
||||
table.appendChild(tr);
|
||||
});
|
||||
scroll.appendChild(table);
|
||||
@@ -1316,6 +1329,33 @@ function addEstimatePanel(data) {
|
||||
tableToExcel(panel.querySelector('.est-table'), 'смета.xlsx', title);
|
||||
};
|
||||
acts.appendChild(dl);
|
||||
// Пересчитать движком (срез 6.2): правки объёмов → движок считает заново (не JS)
|
||||
if (editable) {
|
||||
const rc = document.createElement('button');
|
||||
rc.className = 'est-dl'; rc.type = 'button'; rc.textContent = '↻ Пересчитать движком';
|
||||
rc.onclick = async () => {
|
||||
const inputs = Array.from(panel.querySelectorAll('.est-qty'));
|
||||
const positions = inputs.map(inp => {
|
||||
const o = {code: inp.dataset.code, qty: parseFloat(inp.value)};
|
||||
if (inp.dataset.unit) o.unit = inp.dataset.unit;
|
||||
return o;
|
||||
}).filter(o => o.code && isFinite(o.qty));
|
||||
if (!positions.length) return;
|
||||
rc.disabled = true; rc.textContent = '↻ Считаю...';
|
||||
try {
|
||||
const r = await authFetch('/api/recalc', {method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({positions, meta: {title: data.title}})});
|
||||
if (!r.ok) { rc.textContent = httpErrText(r.status); return; }
|
||||
const upd = await r.json();
|
||||
const fresh = addEstimatePanel(upd); // новая панель с пересчётом
|
||||
panel.replaceWith(fresh); // заменить старую
|
||||
} catch (e) {
|
||||
rc.textContent = 'Нет связи'; rc.disabled = false;
|
||||
}
|
||||
};
|
||||
acts.appendChild(rc);
|
||||
}
|
||||
panel.appendChild(acts);
|
||||
|
||||
const ob = document.getElementById('onboarding'); if (ob) ob.remove();
|
||||
|
||||
Reference in New Issue
Block a user