// singing.js (function () { // Глобальная переменная для хранения текущего уведомления let currentMessageEl = null; let messageTimeout = null; let isSending = false; // Функция для отображения сообщений function showMessage(message, type = 'success', duration = 3000) { // Удаляем предыдущее уведомление, если оно есть if (currentMessageEl && currentMessageEl.parentNode) { clearTimeout(messageTimeout); document.body.removeChild(currentMessageEl); currentMessageEl = null; } const messageEl = document.createElement('div'); messageEl.className = `el-message el-message--${type}`; messageEl.style.cssText = ` position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; min-width: 380px; padding: 15px 15px 15px 20px; border-radius: 4px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); background-color: ${type === 'success' ? '#f0f9eb' : type === 'info' ? '#f4f4f5' : '#fef0f0'}; border: 1px solid ${type === 'success' ? '#e1f3d8' : type === 'info' ? '#e9e9eb' : '#fde2e2'}; color: ${type === 'success' ? '#67c23a' : type === 'info' ? '#909399' : '#f56c6c'}; display: flex; align-items: center; `; const iconClass = type === 'success' ? 'el-icon-success' : type === 'info' ? 'el-icon-info' : 'el-icon-error'; const iconColor = type === 'success' ? '#67c23a' : type === 'info' ? '#909399' : '#f56c6c'; messageEl.innerHTML = ` ${message} `; document.body.appendChild(messageEl); currentMessageEl = messageEl; // Скрываем через указанное время messageTimeout = setTimeout(() => { if (currentMessageEl === messageEl && messageEl.parentNode) { document.body.removeChild(messageEl); currentMessageEl = null; } }, duration); } // Функция отправки сообщения function sendMessageToContent(type, payload) { return new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { reject(new Error('Таймаут ожидания ответа')); }, 60000); const messageHandler = (event) => { if ( event.source !== window || !event.data || event.data.source !== 'medods-extension' || event.data.type !== `${type}Response` ) { return; } window.removeEventListener('message', messageHandler); clearTimeout(timeoutId); resolve(event.data.payload); }; window.addEventListener('message', messageHandler); window.postMessage({ source: 'medods-extension', type: type, payload: payload, }, '*'); }); } // Обработчик для финальных результатов от background function setupBackgroundResultHandler() { window.addEventListener('message', (event) => { if ( event.source !== window || !event.data || event.data.source !== 'medods-extension' || event.data.type !== 'backgroundProcessingResult' ) { return; } console.log('Получен финальный результат от background:', event.data); const result = event.data.payload; if (result.success) { showMessage(`Успешно отправлено документов: ${result.sentCount || 1}`, 'success'); } else { const errorMessage = result.message || 'Неизвестная ошибка'; showMessage(`Ошибка: ${errorMessage}`, 'error'); } }); } // Проверка совместимости документов function checkDocumentsCompatibility(documents) { if (documents.length === 0) { return { compatible: true, type: null }; } let hasIds = false; let hasNonIds = false; for (const doc of documents) { if (doc.title.includes('ИДС')) { hasIds = true; } else { hasNonIds = true; } if (hasIds && hasNonIds) { return { compatible: false, type: 'error', message: 'Нельзя одновременно отправлять документы требующие для подписания авторизацию ЕСИА (ГосУслуги) - "ИДС" и другие документы. Выберите документы одного типа.' }; } } const docType = hasIds ? 'через ЕСИА (ГосУслуги)' : 'ПЭП'; return { compatible: true, type: docType }; } // Функция получения выбранных документов function getSelectedDocuments() { const table = document.querySelector('.m-table.m-table-generator.m-si-generator__table'); if (!table) return []; const checkboxes = table.querySelectorAll('.el-checkbox__original'); const selectedDocs = []; checkboxes.forEach((checkbox) => { if (checkbox.checked) { const row = checkbox.closest('.m-table-row'); if (row) { const rowData = {}; const numberCell = row.querySelector('.col__number .m-table-row-cell__struct'); const titleCell = row.querySelector('.col__title .m-table-row-cell__struct'); if (numberCell) rowData.number = numberCell.textContent.trim(); if (titleCell) rowData.title = titleCell.textContent.trim(); if (rowData.number && rowData.title) { selectedDocs.push(rowData); } } } }); return selectedDocs; } // Функция проверки ограничения в 5 документов function validateDocumentCount(documents) { if (documents.length === 0) { return { valid: false, message: 'Выберите хотя бы один документ для отправки' }; } if (documents.length > 5) { return { valid: false, message: 'Нельзя отправить более 5 документов за раз' }; } return { valid: true, message: '' }; } // Функция создания модального окна предварительной проверки function showPreSingingDialog(documents, preSingingData) { // Проверяем данные const signature = preSingingData.signature || {}; const inProgress = preSingingData.inProgress || []; const complete = preSingingData.complete || []; const daysRemainingControl = preSingingData.daysRemainingControl || 30; const deliveryType = preSingingData.deliveryType || ["sms"]; const multipleSending = preSingingData.multipleSending || false; // Массив получателей (только если multipleSending = true) let recipients = []; // Маппинг типов доставки на отображаемые названия const deliveryTypeLabels = { 'sms': 'СМС-сообщение', 'max': 'МАХ-сообщение', 'mila': 'Mila-сообщение', 'goskey': 'Goskey-сообщение' }; // Определяем тип документов const hasIds = documents.some(doc => doc.title.includes('ИДС')); // Проверяем соответствие типов let typeMatch = false; if (signature.type === 'eSignature' && hasIds) { typeMatch = true; } else if (signature.type === 'eAttorney' && !hasIds) { typeMatch = true; } // Проверяем срок действия let expirationInfo = ''; let expirationFormatted = ''; let expirationClass = 'info'; let expirationTitle = ''; let isExpired = false; let daysRemaining = 0; if (signature.expiration) { const expirationDate = new Date(signature.expiration); const today = new Date(); const timeDiff = expirationDate - today; daysRemaining = Math.ceil(timeDiff / (1000 * 3600 * 24)); // Форматируем дату const dateFormatter = new Intl.DateTimeFormat('ru-RU', { day: 'numeric', month: 'long', year: 'numeric' }); expirationFormatted = dateFormatter.format(expirationDate); expirationInfo = expirationFormatted; // Определяем тип для заголовка if (signature.type === 'eSignature') { expirationTitle = 'Электронная подпись'; } else if (signature.type === 'eAttorney') { expirationTitle = 'Электронная доверенность'; } if (daysRemaining < 0) { expirationClass = 'danger'; isExpired = true; } else if (daysRemaining < daysRemainingControl) { expirationClass = 'warning'; } else { expirationClass = 'success'; } } // Определяем статусы документов const documentsWithStatus = documents.map(doc => { const docNumber = parseInt(doc.number, 10); let status = 'ready'; let statusClass = 'success'; let statusIcon = 'el-icon-success'; if (inProgress.includes(docNumber)) { status = 'in-progress'; statusClass = 'info'; statusIcon = 'el-icon-time'; } else if (complete.includes(docNumber)) { status = 'complete'; statusClass = 'primary'; statusIcon = 'el-icon-check'; } return { ...doc, status, statusClass, statusIcon, isEsia: doc.title.includes('ИДС') }; }); // Определяем, можно ли отправлять let canSend = typeMatch && !isExpired; // Проверяем статусы документов const hasInProgress = documentsWithStatus.some(doc => doc.status === 'in-progress'); const hasComplete = documentsWithStatus.some(doc => doc.status === 'complete'); if (hasInProgress || hasComplete) { canSend = false; } // Если нет signature - нельзя отправлять if (!signature.type) { canSend = false; } // Если типы не соответствуют if (!typeMatch && signature.type) { canSend = false; } // Создаем элементы модального окна напрямую const modalWrapper = document.createElement('div'); modalWrapper.className = 'el-dialog__wrapper'; modalWrapper.style.cssText = 'z-index: 2001; position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: auto;'; const backdrop = document.createElement('div'); backdrop.className = 'v-modal'; backdrop.style.cssText = 'z-index: 2001;'; backdrop.tabIndex = 0; const dialog = document.createElement('div'); dialog.className = 'el-dialog'; dialog.style.cssText = 'margin-top: 15vh; width: 750px; z-index: 2002; position: relative; margin: 15vh auto 50px; background: #fff; border-radius: 4px; box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);'; // Создаем заголовок const dialogHeader = document.createElement('div'); dialogHeader.className = 'el-dialog__header'; const dialogTitle = document.createElement('span'); dialogTitle.className = 'el-dialog__title'; dialogTitle.style.cssText = 'line-height: 24px; font-size: 18px; color: #303133;'; dialogTitle.textContent = 'Подготовка документов к отправке для электронного подписания'; const closeButton = document.createElement('button'); closeButton.type = 'button'; closeButton.className = 'el-dialog__headerbtn'; closeButton.style.cssText = 'position: absolute; top: 20px; right: 20px; padding: 0; background: 0 0; border: none; outline: 0; cursor: pointer; font-size: 16px;'; const closeIcon = document.createElement('i'); closeIcon.className = 'el-dialog__close el-icon el-icon-close'; closeButton.appendChild(closeIcon); dialogHeader.appendChild(dialogTitle); dialogHeader.appendChild(closeButton); // Создаем тело диалога const dialogBody = document.createElement('div'); dialogBody.className = 'el-dialog__body'; dialogBody.style.cssText = 'padding: 15px; padding-bottom: 0; color: #606266; font-size: 14px;'; // Создаем контент const dialogContent = document.createElement('div'); dialogContent.className = 'dialog-content'; // Предупреждения (ближе к заголовку) if (!canSend) { const warningsSection = document.createElement('div'); warningsSection.className = 'warnings-section'; warningsSection.style.cssText = 'margin-bottom: 15px;'; // Собираем все предупреждения в один массив const warnings = []; if (!signature.type) { warnings.push({ type: 'error', title: 'Нет прав на отправку', message: 'У вас нет прав на электронное подписание документов' }); } if (daysRemaining < 0) { let typeName = 'документа'; if (signature.type === 'eSignature') { typeName = 'электронной подписи'; } else if (signature.type === 'eAttorney') { typeName = 'электронной доверенности'; } warnings.push({ type: 'error', title: 'Срок действия истек', message: `Срок действия ${typeName} истек ${Math.abs(daysRemaining)} дней назад` }); } if (!typeMatch && signature.type) { const availableType = signature.type === 'eSignature' ? 'электронная подпись' : 'электронная доверенность'; const neededType = hasIds ? 'электронная подпись' : 'электронная доверенность'; warnings.push({ type: 'warning', title: 'Несоответствие типов документов', message: `Для подписания подготовлены документы для которых требуется "${neededType}", но у вас доступна "${availableType}"` }); } if (hasInProgress || hasComplete) { warnings.push({ type: 'warning', title: 'Невозможно отправить документы', message: 'Среди выбранных документов есть уже подписанные (✔️) или направленные для подписания (🕒)' }); } // Отображаем все предупреждения warnings.forEach(warning => { const warningEl = document.createElement('div'); warningEl.className = `el-alert el-alert--${warning.type} is-light`; warningEl.style.cssText = 'margin-bottom: 8px; padding: 8px; border-radius: 4px;'; const warningContent = document.createElement('div'); warningContent.className = 'el-alert__content'; const warningTitle = document.createElement('span'); warningTitle.className = 'el-alert__title'; warningTitle.style.cssText = 'font-size: 13px; color: ' + (warning.type === 'error' ? '#f56c6c' : '#e6a23c') + ';'; warningTitle.textContent = warning.title; const warningDesc = document.createElement('p'); warningDesc.className = 'el-alert__description'; warningDesc.style.cssText = 'font-size: 12px; margin-top: 3px; color: ' + (warning.type === 'error' ? '#f56c6c' : '#e6a23c') + ';'; warningDesc.textContent = warning.message; warningContent.appendChild(warningTitle); warningContent.appendChild(warningDesc); warningEl.appendChild(warningContent); warningsSection.appendChild(warningEl); }); dialogContent.appendChild(warningsSection); } // Список документов const documentsSection = document.createElement('div'); documentsSection.className = 'documents-section'; const documentsTitle = document.createElement('h4'); documentsTitle.style.cssText = 'margin: 0 0 10px 0; color: #303133; font-size: 16px;'; documentsTitle.textContent = 'Список документов:'; const documentsList = document.createElement('div'); documentsList.style.cssText = 'border: 1px solid #EBEEF5; border-radius: 4px; padding: 0 10px; max-height: 200px; overflow-y: auto;'; // Добавляем документы в список documentsWithStatus.forEach((doc, index) => { const docItem = document.createElement('div'); // Для последнего элемента не добавляем нижнюю границу if (index === documentsWithStatus.length - 1) { docItem.style.cssText = 'display: flex; align-items: center; padding: 8px 0;'; } else { docItem.style.cssText = 'display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid #F0F0F0;'; } // Статус (иконка слева) const docStatusIcon = document.createElement('div'); docStatusIcon.style.cssText = 'flex: 0 0 24px; margin-right: 8px;'; const statusIcon = document.createElement('i'); statusIcon.className = doc.statusIcon; statusIcon.style.cssText = `font-size: 16px; color: ${doc.status === 'ready' ? '#67c23a' : doc.status === 'in-progress' ? '#909399' : '#409eff' };`; docStatusIcon.appendChild(statusIcon); // Номер документа (стилизован в зависимости от статуса) const docNumber = document.createElement('div'); docNumber.style.cssText = 'flex: 0 0 60px;'; const numberTag = document.createElement('span'); if (doc.status === 'ready') { numberTag.className = 'el-tag el-tag--success el-tag--small'; numberTag.style.cssText = 'display: inline-block; padding: 0 7px; height: 24px; line-height: 22px; font-size: 12px; border-width: 1px; border-style: solid; border-radius: 4px; box-sizing: border-box; white-space: nowrap;'; } else if (doc.status === 'in-progress') { numberTag.className = 'el-tag el-tag--info el-tag--small'; numberTag.style.cssText = 'display: inline-block; padding: 0 7px; height: 24px; line-height: 22px; font-size: 12px; border-width: 1px; border-style: solid; border-radius: 4px; box-sizing: border-box; white-space: nowrap;'; } else { numberTag.className = 'el-tag el-tag--primary el-tag--small'; numberTag.style.cssText = 'display: inline-block; padding: 0 7px; height: 24px; line-height: 22px; font-size: 12px; border-width: 1px; border-style: solid; border-radius: 4px; box-sizing: border-box; white-space: nowrap;'; } numberTag.textContent = `№${doc.number}`; docNumber.appendChild(numberTag); // Название документа (занимает все оставшееся пространство) const docTitle = document.createElement('div'); docTitle.style.cssText = 'flex: 1; color: #606266; font-size: 13px; padding: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'; docTitle.textContent = doc.title; docItem.appendChild(docStatusIcon); docItem.appendChild(docNumber); docItem.appendChild(docTitle); documentsList.appendChild(docItem); }); documentsSection.appendChild(documentsTitle); documentsSection.appendChild(documentsList); dialogContent.appendChild(documentsSection); // ========== НАЧАЛО: Блок дополнительных получателей (только при multipleSending=true) ========== if (multipleSending) { // Функция рендеринга блока получателей (будет вызываться при изменениях) function renderRecipientsBlock() { // Удаляем старый контейнер, если он есть const oldContainer = dialogContent.querySelector('.recipients-container'); if (oldContainer) { oldContainer.remove(); } // Если получателей нет - не отображаем блок if (recipients.length === 0) { return; } const recipientsContainer = document.createElement('div'); recipientsContainer.className = 'recipients-container'; recipientsContainer.style.cssText = 'margin-top: 15px; margin-bottom: 0px;'; // Заголовок с количеством получателей const recipientsHeader = document.createElement('div'); recipientsHeader.style.cssText = 'display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;'; const recipientsTitle = document.createElement('h4'); recipientsTitle.style.cssText = 'margin: 0; color: #303133; font-size: 14px; font-weight: 500;'; recipientsTitle.textContent = 'Дополнительные получатели:'; const recipientsCount = document.createElement('span'); recipientsCount.className = 'el-tag el-tag--info el-tag--mini'; recipientsCount.style.cssText = 'margin-left: 6px;'; recipientsCount.textContent = recipients.length; const titleWrapper = document.createElement('div'); titleWrapper.style.cssText = 'display: flex; align-items: center;'; titleWrapper.appendChild(recipientsTitle); titleWrapper.appendChild(recipientsCount); recipientsHeader.appendChild(titleWrapper); // Компактный список получателей const recipientsList = document.createElement('div'); recipientsList.className = 'recipients-list'; recipientsList.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px;'; recipients.forEach((recipient, index) => { const recipientTag = document.createElement('span'); recipientTag.className = 'el-tag el-tag--info el-tag--small'; recipientTag.style.cssText = 'display: inline-flex; align-items: center; height: 24px; line-height: 22px; padding: 0 8px; margin-right: 4px; margin-bottom: 4px;'; const nameSpan = document.createElement('span'); nameSpan.textContent = `${recipient.surname} ${recipient.name.charAt(0)}. ${recipient.secondName ? recipient.secondName.charAt(0) + '.' : ''}`; const closeIcon = document.createElement('i'); closeIcon.className = 'el-icon-close'; closeIcon.style.cssText = 'margin-left: 4px; cursor: pointer; font-size: 12px;'; closeIcon.addEventListener('click', (e) => { e.stopPropagation(); if (window.confirm(`Удалить получателя ${recipient.surname} ${recipient.name}?`)) { recipients.splice(index, 1); renderRecipientsBlock(); // Перерисовываем блок } }); recipientTag.appendChild(nameSpan); recipientTag.appendChild(closeIcon); recipientsList.appendChild(recipientTag); }); recipientsContainer.appendChild(recipientsHeader); recipientsContainer.appendChild(recipientsList); // Вставляем после списка документов dialogContent.insertBefore(recipientsContainer, documentsSection.nextSibling); } // Кнопка добавления получателя const addButtonContainer = document.createElement('div'); addButtonContainer.style.cssText = 'margin: 10px 0;'; const addRecipientBtn = document.createElement('button'); addRecipientBtn.type = 'button'; addRecipientBtn.className = 'el-button m-button el-button--success el-button--small is-plain button-with-icon'; if (!canSend) { addRecipientBtn.classList.add('is-disabled'); addRecipientBtn.disabled = true; } addRecipientBtn.innerHTML = ' Добавить получателя'; addButtonContainer.appendChild(addRecipientBtn); dialogContent.appendChild(addButtonContainer); // Контейнер для аккордеона (поиск получателей) const searchAccordion = document.createElement('div'); searchAccordion.className = 'search-accordion'; searchAccordion.style.cssText = 'margin-top: 10px; display: none;'; const searchCard = document.createElement('div'); searchCard.className = 'el-card'; searchCard.style.cssText = 'border: 1px solid #EBEEF5; border-radius: 4px;'; const searchBody = document.createElement('div'); searchBody.className = 'el-card__body'; searchBody.style.cssText = 'padding: 12px;'; // Поле ввода номера телефона и кнопка поиска const searchRow = document.createElement('div'); searchRow.style.cssText = 'display: flex; gap: 8px; margin-bottom: 10px;'; const phoneInput = document.createElement('input'); phoneInput.type = 'text'; phoneInput.placeholder = 'Введите номер телефона'; phoneInput.className = 'el-input__inner'; phoneInput.style.cssText = 'flex: 1; height: 28px; line-height: 28px; border: 1px solid #DCDFE6; border-radius: 4px; padding: 0 8px; font-size: 12px;'; const searchBtn = document.createElement('button'); searchBtn.type = 'button'; searchBtn.className = 'el-button m-button el-button--primary el-button--small is-plain button-with-icon'; searchBtn.innerHTML = ' Найти'; searchBtn.style.cssText = 'height: 28px;'; searchRow.appendChild(phoneInput); searchRow.appendChild(searchBtn); // Контейнер для результатов поиска const searchResults = document.createElement('div'); searchResults.className = 'search-results'; searchResults.style.cssText = 'max-height: 150px; overflow-y: auto; font-size: 12px;'; // Кнопка отмены const cancelSearchBtn = document.createElement('button'); cancelSearchBtn.type = 'button'; cancelSearchBtn.className = 'el-button m-button el-button--small is-plain button-with-icon cancel-button'; const cancelSearchIcon = document.createElement('i'); cancelSearchIcon.className = 'm-icon fa-times button-icon fad'; cancelSearchIcon.style.cssText = 'font-size: 14px; margin-right: 6px;'; const cancelSearchText = document.createElement('span'); cancelSearchText.textContent = 'Отмена'; cancelSearchBtn.appendChild(cancelSearchIcon); cancelSearchBtn.appendChild(cancelSearchText); searchBody.appendChild(searchRow); searchBody.appendChild(searchResults); searchBody.appendChild(cancelSearchBtn); searchCard.appendChild(searchBody); searchAccordion.appendChild(searchCard); dialogContent.appendChild(searchAccordion); // Функция поиска получателей по номеру телефона async function searchRecipients(phone) { if (!phone || phone.trim() === '') { showMessage('Введите номер телефона', 'info'); return; } // Показываем загрузку searchResults.innerHTML = '
Поиск...
' + error.message + '