diff --git a/miniapp/assets/clients.js b/miniapp/assets/clients.js index a16efc6..2ceae9e 100644 --- a/miniapp/assets/clients.js +++ b/miniapp/assets/clients.js @@ -1205,58 +1205,98 @@ const Clients = (function () {
📝 Примечание + +
+ + +
+

Загружаем...

-
- + + +
`); - const textarea = section.querySelector("#noteText"); - const meta = section.querySelector("#noteMeta"); - const status = section.querySelector("#noteStatus"); + const view = section.querySelector("#noteView"); + const editor = section.querySelector("#noteEditor"); + const displayTx = section.querySelector("#noteDisplayText"); + const textarea = section.querySelector("#noteText"); + const meta = section.querySelector("#noteMeta"); + const status = section.querySelector("#noteStatus"); + const editBtn = section.querySelector("#noteEditBtn"); + let savedText = ""; + + function showView(text, updatedAt) { + savedText = text || ""; + displayTx.style.fontStyle = text ? "normal" : "italic"; + displayTx.style.color = text ? "var(--ink,#1F1A14)" : "var(--muted,#998877)"; + displayTx.textContent = text || "Нет примечания"; + if (updatedAt) meta.textContent = "обновлено " + formatDate(updatedAt); + editor.style.display = "none"; + view.style.display = ""; + editBtn.textContent = "Изменить"; + } + + function showEditor() { + textarea.value = savedText; + status.textContent = ""; + status.className = "note-status"; + editor.style.display = ""; + view.style.display = "none"; + editBtn.textContent = "Свернуть"; + textarea.focus(); + } // Загружаем сохранённую заметку - fetchClientNote(client).then(data => { - if (data?.note) textarea.value = data.note; - if (data?.updated_at) { - meta.textContent = "обновлено " + formatDate(data.updated_at); - } - }).catch(() => {}); + fetchClientNote(client) + .then(data => showView(data?.note || "", data?.updated_at || "")) + .catch(() => showView("", "")); + + // Переключатель просмотр ↔ редактирование + editBtn.addEventListener("click", () => { + if (editor.style.display === "none") showEditor(); + else showView(savedText, meta.textContent.replace("обновлено ", "")); + }); + + // Отмена — вернуть исходный текст + section.querySelector("#noteCancel").addEventListener("click", () => { + showView(savedText, meta.textContent.replace("обновлено ", "")); + }); // Сохранение section.querySelector("#noteSave").addEventListener("click", async () => { const btn = section.querySelector("#noteSave"); - btn.disabled = true; - btn.textContent = "Сохраняем..."; + btn.disabled = true; btn.textContent = "Сохраняем..."; + status.textContent = ""; status.className = "note-status"; try { const data = await saveClientNote(client, textarea.value); if (data?.ok) { - status.textContent = "✓ сохранено"; - status.className = "note-status ok"; - if (data.updated_at) meta.textContent = "обновлено " + formatDate(data.updated_at); - setTimeout(() => { status.textContent = ""; }, 2500); + haptic && haptic("success"); + showView(textarea.value, data.updated_at || ""); } else { status.textContent = "Ошибка: " + (data?.error || "не сохранилось"); status.className = "note-status err"; + btn.disabled = false; btn.textContent = "Сохранить"; } } catch (e) { status.textContent = "Сеть: " + e.message; status.className = "note-status err"; + btn.disabled = false; btn.textContent = "Сохранить"; } - btn.disabled = false; - btn.textContent = "Сохранить"; }); - // Голосовой ввод через Web Speech API - const micBtn = section.querySelector("#noteMic"); - setupVoiceInput(micBtn, textarea, status); + // Голосовой ввод + setupVoiceInput(section.querySelector("#noteMic"), textarea, status); return section; } diff --git a/miniapp/assets/podbor.css b/miniapp/assets/podbor.css index 82d7340..789052c 100644 --- a/miniapp/assets/podbor.css +++ b/miniapp/assets/podbor.css @@ -2309,7 +2309,41 @@ .client-note-block .block-head { display: flex; align-items: center; - justify-content: space-between; + gap: 8px; +} +.client-note-block .block-head > span:first-child { + flex: 1; +} + +/* Кнопка-переключатель Изменить / Свернуть */ +.note-edit-toggle { + padding: 4px 12px; + background: transparent; + border: 1px solid rgba(107, 74, 43, 0.30); + border-radius: 20px; + font-size: 12px; + font-weight: 500; + color: var(--walnut, #6B4A2B); + cursor: pointer; + font-family: inherit; + white-space: nowrap; + transition: background 0.12s, color 0.12s; +} +.note-edit-toggle:active { + background: rgba(107, 74, 43, 0.10); +} + +/* Просмотр-режим */ +.note-view { + padding: 6px 2px 4px; +} +.note-text { + font-size: 14px; + line-height: 1.5; + color: var(--ink, #1F1A14); + white-space: pre-wrap; + word-break: break-word; + margin: 0 0 4px; } .client-note-block .note-meta { font-size: 11px; diff --git a/miniapp/index.html b/miniapp/index.html index e8da3ec..33fad5c 100644 --- a/miniapp/index.html +++ b/miniapp/index.html @@ -12,14 +12,14 @@ - - + +
- +
- - - - - - - - - - + + + + + + + + + +