v7: saveTemplate теперь берёт КАТО напрямую из колонки, loadTemplate/autoProcess ищут по значению КАТО

This commit is contained in:
Dauren777 2026-06-24 07:46:12 +00:00
parent 3bd259c5d2
commit 03f6e1456a

View File

@ -374,24 +374,45 @@ const TEMPLATE_KEY = 'snp_marked_template';
function saveTemplate() {
if (markedIds.size === 0) { alert('Нет отмеченных пунктов. Сначала отметьте.'); return; }
const arr = [...markedIds].filter(id => !id.startsWith('row_'));
if (arr.length === 0) { alert('Не найдены КАТО-коды. Отметка работает только если в файле есть колонка КАТО.'); return; }
localStorage.setItem(TEMPLATE_KEY, JSON.stringify(arr));
document.getElementById('templateStatus').textContent = `✅ Шаблон сохранён (${arr.length} кодов)`;
setTimeout(() => document.getElementById('templateStatus').textContent = '', 3000);
// build list of КАТО codes directly from the data
const katoIx = dataColumns.indexOf('kato');
if (katoIx === -1) { alert('Колонка КАТО не найдена. Проверьте название колонки.'); return; }
const katoHeader = allData.columns[katoIx];
const katoCodes = [];
allData.forEach(row => {
if (markedIds.has(row._id)) {
const code = String(row[katoHeader] || '').trim();
if (code) katoCodes.push(code);
}
});
if (katoCodes.length === 0) {
alert('Отмеченные строки не содержат КАТО-коды. Проверьте колонку "' + katoHeader + '".');
return;
}
localStorage.setItem(TEMPLATE_KEY, JSON.stringify(katoCodes));
document.getElementById('templateStatus').textContent = `✅ Шаблон сохранён (${katoCodes.length} кодов)`;
setTimeout(() => document.getElementById('templateStatus').textContent = '', 5000);
}
function loadTemplate() {
const raw = localStorage.getItem(TEMPLATE_KEY);
if (!raw) { alert('Нет сохранённого шаблона. Сначала отметьте пункты и сохраните.'); return; }
const saved = JSON.parse(raw);
const katoIx = dataColumns.indexOf('kato');
if (katoIx === -1) { alert('Колонка КАТО не найдена'); return; }
const katoHeader = allData.columns[katoIx];
let found = 0;
allData.forEach(r => {
if (saved.includes(r._id)) { markedIds.add(r._id); found++; }
const code = String(r[katoHeader] || '').trim();
if (code && saved.includes(code)) { markedIds.add(r._id); found++; }
});
renderTable();
document.getElementById('templateStatus').textContent = `📂 Применено: ${found} совпадений`;
setTimeout(() => document.getElementById('templateStatus').textContent = '', 3000);
setTimeout(() => document.getElementById('templateStatus').textContent = '', 4000);
}
const KATO_REGIONS = {
@ -440,9 +461,13 @@ function autoProcess() {
const raw = localStorage.getItem(TEMPLATE_KEY);
if (!raw) return;
const saved = JSON.parse(raw);
const katoIx = dataColumns.indexOf('kato');
if (katoIx === -1) return;
const katoHeader = allData.columns[katoIx];
let found = 0;
allData.forEach(r => {
if (saved.includes(r._id)) { markedIds.add(r._id); found++; }
const code = String(r[katoHeader] || '').trim();
if (code && saved.includes(code)) { markedIds.add(r._id); found++; }
});
renderTable();
if (found > 0) {