diff --git a/api/static/js/index.js b/api/static/js/index.js index 6615484..c21c8e5 100644 --- a/api/static/js/index.js +++ b/api/static/js/index.js @@ -775,6 +775,9 @@ function renderToolboxTab(tabData) { // Создаем навигацию по складам + // Сортируем список складов по названию + tabData.sort((a, b) => a.title.localeCompare(b.title, 'ru')); + const toolboxNav = `
${tabData.map((toolbox, index) => ` @@ -862,9 +865,45 @@ async function loadToolboxContent(toolboxId) { if (resp.status === 'ok') { const toolboxData = resp.data; const toolboxInfo = currentToolboxData.find(t => t.id === toolboxId); + const toolboxOwn = toolboxInfo.owner_id === userData.id ? 'Мой склад' : toolboxInfo.owner_id ? 'Склад сотрудника' : 'Общий склад'; + + function handleEditBtn() { + if (accessData.manage_toolboxes) { + contentContainer.querySelector('#editToolbox').addEventListener('click', () => { + addToolbox(toolboxInfo); + }); + } else { + contentContainer.querySelector('#editToolbox').remove(); + } + } + + function handleFillBtn() { + if (accessData.tools_registration && !toolboxInfo.owner_id) { + contentContainer.querySelector('#fillToolbox').addEventListener('click', () => { + fillToolbox(toolboxInfo); + }); + } else { + contentContainer.querySelector('#fillToolbox').remove(); + } + } if (toolboxData.length === 0) { contentContainer.innerHTML = ` +
+
+
+
${toolboxInfo?.title || 'Склад'}
+

${toolboxInfo?.description || 'Описание отсутствует'}

+
+ + + ${toolboxOwn} +
+

Склад пуст

@@ -885,18 +924,20 @@ async function loadToolboxContent(toolboxId) { } else { document.getElementById('deleteToolbox').remove(); } + handleEditBtn(); + handleFillBtn() return; } // Находим информацию о выбранном складе - - const toolboxOwn = toolboxInfo.owner_id === userData.id ? 'Мой склад' : toolboxInfo.owner_id ? 'Склад сотрудника' : 'Общий склад'; const quantityMonitoring = toolboxInfo.monitoring && accessData.view_all_toolboxes; // Обрабатываем данные в единый список const processedData = processToolboxData(toolboxData, toolboxId, quantityMonitoring); const totalQuantity = processedData.reduce((sum, item) => sum + item.totalQuantity, 0); const totalCost = formatPrice(processedData.reduce((sum, item) => sum + item.totalCost, 0)); + const notEnough = processedData.reduce((sum, item) => sum + (item.indicator?.text !== 'Достаточно' ? 1 : 0), 0); + // console.log(processedData); // Отображаем содержимое склада contentContainer.innerHTML = ` @@ -909,6 +950,9 @@ async function loadToolboxContent(toolboxId) { + ${toolboxOwn}
@@ -924,6 +968,18 @@ async function loadToolboxContent(toolboxId) { + ${notEnough > 0 && quantityMonitoring ? ` +
+ +
+ ` : ''}
Количество позиций: ${processedData.length} @@ -964,14 +1020,8 @@ async function loadToolboxContent(toolboxId) {
`; - if (accessData.manage_toolboxes) { - contentContainer.querySelector('#editToolbox').addEventListener('click', () => { - addToolbox(toolboxInfo); - }); - } else { - contentContainer.querySelector('#editToolbox').remove(); - } - + handleEditBtn(); + handleFillBtn() // Инициализация таблицы с данными await initializeToolboxTable(processedData, toolboxOwn, quantityMonitoring); @@ -997,6 +1047,11 @@ async function loadToolboxContent(toolboxId) { } } +function fillToolbox(toolboxInfo) { + console.log(toolboxInfo); + showInfo('Функционал еще в разработке', 'warning'); +} + async function deleteToolbox(toolboxId) { // Находим информацию о складе const toolboxInfo = currentToolboxData.find(t => t.id === toolboxId); @@ -1476,17 +1531,22 @@ async function initializeToolboxTable(data, toolboxOwn, quantityMonitoring) { const searchLower = searchText.toLowerCase(); filteredData = data.filter(item => item.title.toLowerCase().includes(searchLower) || - item.category.toLowerCase().includes(searchLower) || - item.placement.toLowerCase().includes(searchLower) || - item.totalQuantity.toString().includes(searchLower) || - item.totalCost.toString().includes(searchLower) || - (item.indicator?.text && item.indicator.text.toLowerCase().includes(searchLower)) + item.toolkitData.description.toLowerCase().includes(searchLower) ); } currentPage = 1; sortData(currentSort.field, currentSort.direction); await initializePagination(); } + async function filterIndicator() { + const searchLower = 'мало'; + filteredData = data.filter(item => + (item.indicator?.text && item.indicator.text.toLowerCase().includes(searchLower)) + ); + currentPage = 1; + sortData(currentSort.field, currentSort.direction); + await initializePagination(); + } // Инициализация сортировки по заголовкам document.querySelectorAll('#toolboxItemsTable th[data-sort]').forEach(th => { @@ -1522,9 +1582,26 @@ async function initializeToolboxTable(data, toolboxOwn, quantityMonitoring) { // Инициализация кнопки сброса фильтра document.getElementById('resetFilter').addEventListener('click', async () => { searchInput.value = ''; + searchInput.placeholder = 'Поиск по всем полям...'; await filterData(''); }); + // Инициализация кнопки "мало" + try { + document.getElementById('notEnoughBtn').addEventListener('click', async () => { + const showAll = 'Сбросить фильтр -->'; + if (searchInput.placeholder === showAll) { + searchInput.placeholder = 'Поиск по всем полям...'; + searchInput.value = ''; + await filterData(''); + return; + } + searchInput.value = ''; + searchInput.placeholder = showAll; + await filterIndicator(); + }); + } catch (_) { } + // Начальная инициализация sortData(currentSort.field, currentSort.direction); await initializePagination(); @@ -1727,12 +1804,12 @@ async function showOperationModal(operation, selectedItem) {