fix(tahesab): open invoice PDF window synchronously on click

Awaiting settings before window.open left a blank tab; open about:blank on click then fill via blob URL.
This commit is contained in:
2026-10-24 14:09:46 +03:30
parent f50246dc46
commit 1ba352f127
2 changed files with 66 additions and 13 deletions
@@ -411,15 +411,35 @@ async function exportAsnadPdf(g: {
rows: Record<string, unknown>[];
}) {
error.value = '';
// باز کردن هم‌زمان با کلیک — وگرنه بعد از await پاپ‌آپ بلاک/خالی می‌شود
const preview = window.open('about:blank', '_blank');
if (preview) {
try {
preview.document.write(
'<!DOCTYPE html><html lang="fa" dir="rtl"><head><meta charset="utf-8" /><title>فاکتور</title></head><body style="font-family:Tahoma,sans-serif;padding:24px">در حال آماده‌سازی فاکتور…</body></html>',
);
preview.document.close();
} catch {
/* ignore */
}
}
if (!invoiceSettings.value) {
await loadInvoiceSettings();
}
printTahesabInvoicePdf({
const okPrint = printTahesabInvoicePdf({
group: g,
settings: invoiceSettings.value,
customerName: props.personName?.trim() || 'مشتری',
moshtariCode: currentLink.value?.moshtariCode ?? null,
targetWindow: preview,
});
if (!okPrint) {
error.value =
'خروجی فاکتور باز نشد. پاپ‌آپ مرورگر را برای این سایت مجاز کنید و دوباره بزنید.';
preview?.close();
}
}
async function loadAsnad() {