feat: сохранение и экспорт ручной цены (buy/sale) из вкладки Ценообразование

Сохранение:
- restoreAutosaveDraftIfAny теперь восстанавливает pricing_ui из notes драфта
- saveConfigOnExit привязан к pagehide и visibilitychange — цены сохраняются
  на сервер при уходе со страницы без явного нажатия «Сохранить»

Экспорт CSV:
- exportPricingCSV передаёт manual_price (buy для FOB, sale для DDP)
- ProjectPricingExportOptions.ManualPrice *float64 — новое поле
- distributeManualPrice распределяет ручную цену пропорционально estimate
  с коррекцией остатка на последней строке
- Колонка «Ручная цена» в CSV (заголовок, строки, итог конфига)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-06-17 09:59:27 +03:00
parent c6385f6cf1
commit 76d93c6be8
2 changed files with 85 additions and 18 deletions

View File

@@ -879,6 +879,12 @@ document.addEventListener('DOMContentLoaded', async function() {
}
});
// Save pricing state (ручная цена) on page exit so it survives navigation
window.addEventListener('pagehide', saveConfigOnExit);
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') saveConfigOnExit();
});
// Load vendor spec BOM for this configuration
if (configUUID) {
loadVendorSpec(configUUID);
@@ -2440,6 +2446,9 @@ function restoreAutosaveDraftIfAny() {
customPriceInput.value = '';
}
}
if (payload.notes) {
restorePricingStateFromNotes(payload.notes);
}
hasUnsavedChanges = true;
} catch (_) {
// ignore invalid draft
@@ -4388,6 +4397,8 @@ function setPricingCustomPriceFromVendor() {
async function exportPricingCSV(table) {
if (!configUUID) { showToast('Сохраните конфигурацию перед экспортом', 'error'); return; }
const basis = table === 'sale' ? 'ddp' : 'fob';
const manualInputId = table === 'sale' ? 'pricing-custom-price-sale' : 'pricing-custom-price-buy';
const manualPrice = parseDecimalInput(document.getElementById(manualInputId)?.value || '');
try {
const resp = await fetch(`/api/configs/${configUUID}/export/pricing`, {
method: 'POST',
@@ -4399,6 +4410,7 @@ async function exportPricingCSV(table) {
include_stock: true,
include_competitor: true,
basis: basis,
manual_price: manualPrice > 0 ? manualPrice : null,
}),
});
if (!resp.ok) { showToast('Ошибка экспорта', 'error'); return; }