fix(tahesab): make sales report apply and sync actions fire

Bypass Ant form required validation that blocked the apply button, and surface API errors with toasts.
This commit is contained in:
2026-10-22 20:04:59 +03:30
parent 42b3fc72cc
commit 2ca2650b69
+41 -25
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { theme } from 'ant-design-vue';
import { message, theme } from 'ant-design-vue';
import type { TableColumnsType, TablePaginationConfig } from 'ant-design-vue';
import {
ArrowRightOutlined,
@@ -9,6 +9,7 @@ import {
SearchOutlined,
SyncOutlined,
} from '@ant-design/icons-vue';
import axios from 'axios';
import {
TAHESAB_ASNAD_KIND_LABELS,
TAHESAB_ASNAD_KINDS,
@@ -216,10 +217,20 @@ async function searchPeople(q: string) {
}
}
async function loadReport() {
function apiErrMessage(e: unknown, fallback: string): string {
if (!axios.isAxiosError(e)) return fallback;
const raw = e.response?.data as { message?: string | string[] } | undefined;
const msg = raw?.message;
if (Array.isArray(msg)) return msg.filter(Boolean).join(' · ') || fallback;
if (typeof msg === 'string' && msg.trim()) return msg;
return fallback;
}
async function loadReport(opts?: { notifyEmpty?: boolean }) {
const params = filterParams.value;
if (!params) {
error.value = 'تاریخ از و تا را انتخاب کنید.';
message.warning(error.value);
return;
}
loading.value = true;
@@ -236,11 +247,14 @@ async function loadReport() {
]);
report.value = pageRes.data;
summary.value = sumRes.data;
if (opts?.notifyEmpty && (pageRes.data.total ?? 0) === 0) {
message.info(
'ردیفی نیست. اول «به‌روزرسانی از ته‌حساب» را برای همین بازه بزنید.',
);
}
} catch (e: unknown) {
const msg =
(e as { response?: { data?: { message?: string } } })?.response?.data
?.message ?? 'بارگذاری گزارش ناموفق بود.';
error.value = String(msg);
error.value = apiErrMessage(e, 'بارگذاری گزارش ناموفق بود.');
message.error(error.value);
report.value = null;
summary.value = null;
} finally {
@@ -289,6 +303,7 @@ async function startSync() {
const params = filterParams.value;
if (!params) {
error.value = 'ابتدا بازه تاریخ را مشخص کنید، بعد به‌روزرسانی را بزنید.';
message.warning(error.value);
return;
}
syncing.value = true;
@@ -304,21 +319,32 @@ async function startSync() {
},
{ timeout: 60_000 },
);
message.success('همگام‌سازی شروع شد.');
await pollJob(data.id);
} catch (e: unknown) {
syncing.value = false;
const msg =
(e as { response?: { data?: { message?: string } } })?.response?.data
?.message ?? 'شروع همگام‌سازی ناموفق بود.';
error.value = String(msg);
syncHint.value = '';
error.value = apiErrMessage(e, 'شروع همگام‌سازی ناموفق بود.');
message.error(error.value);
}
}
function applyFilters() {
page.value = 1;
void loadReport();
void loadReport({ notifyEmpty: true });
}
onMounted(async () => {
defaultRange();
try {
await Promise.all([loadConnections(), loadCustomerGroups()]);
await loadReport();
} catch (e: unknown) {
error.value = apiErrMessage(e, 'بارگذاری اولیه ناموفق بود.');
message.error(error.value);
}
});
function onTableChange(pag: TablePaginationConfig) {
page.value = pag.current ?? 1;
pageSize.value = pag.pageSize ?? 50;
@@ -329,16 +355,6 @@ watch([connectionId, groupIds, kinds, jensFelez, personId], () => {
page.value = 1;
});
onMounted(async () => {
defaultRange();
try {
await Promise.all([loadConnections(), loadCustomerGroups()]);
await loadReport();
} catch {
error.value = 'بارگذاری اولیه ناموفق بود.';
}
});
onUnmounted(() => stopPoll());
</script>
@@ -387,7 +403,7 @@ onUnmounted(() => stopPoll());
<span>فیلترها</span>
</a-space>
</template>
<a-form layout="vertical" @finish="applyFilters">
<a-form layout="vertical" @submit.prevent>
<a-row :gutter="[16, 8]">
<a-col :xs="24" :sm="12" :md="8" :lg="6">
<a-form-item label="اتصال">
@@ -402,12 +418,12 @@ onUnmounted(() => stopPoll());
</a-form-item>
</a-col>
<a-col :xs="24" :sm="12" :md="8" :lg="6">
<a-form-item label="از تاریخ" required>
<a-form-item label="از تاریخ">
<JalaliDateInput v-model="fromDate" placeholder="از تاریخ" />
</a-form-item>
</a-col>
<a-col :xs="24" :sm="12" :md="8" :lg="6">
<a-form-item label="تا تاریخ" required>
<a-form-item label="تا تاریخ">
<JalaliDateInput v-model="toDate" placeholder="تا تاریخ" />
</a-form-item>
</a-col>
@@ -472,7 +488,7 @@ onUnmounted(() => stopPoll());
<a-typography-text v-else type="secondary">
بعد از انتخاب بازه، فیلتر را اعمال کنید یا از ته‌حساب به‌روز کنید.
</a-typography-text>
<a-button type="primary" html-type="submit" :loading="loading">
<a-button type="primary" :loading="loading" @click="applyFilters">
اعمال فیلتر
</a-button>
</a-flex>