Adding registration date and multiple addresses for contacts and leads.
This commit is contained in:
@@ -4,12 +4,14 @@ import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import {
|
||||
formatJalaliNumeric,
|
||||
formatRelativeContact,
|
||||
toFaDigits,
|
||||
} from '@/lib/jalali';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { canManageSettings } from '@/lib/roles';
|
||||
import {
|
||||
UiBusyOverlay,
|
||||
UiButton,
|
||||
UiDropdownMenu,
|
||||
UiEmptyState,
|
||||
@@ -102,6 +104,8 @@ const isAdmin = computed(() => canManageSettings(auth.user?.role));
|
||||
const q = ref(typeof route.query.q === 'string' ? route.query.q : '');
|
||||
const loading = ref(false);
|
||||
const busy = ref(false);
|
||||
const pageBusy = ref(false);
|
||||
const busyMessage = ref('لطفاً صبر کنید…');
|
||||
const error = ref('');
|
||||
const okMsg = ref('');
|
||||
const data = ref<PaginatedResponse<LeadDto> | null>(null);
|
||||
@@ -134,6 +138,8 @@ const createForm = ref({
|
||||
city: '',
|
||||
region: '',
|
||||
source: '',
|
||||
instagram: '',
|
||||
addresses: [''] as string[],
|
||||
stageId: '',
|
||||
assigneeId: '',
|
||||
});
|
||||
@@ -638,6 +644,8 @@ function openCreate() {
|
||||
city: '',
|
||||
region: '',
|
||||
source: '',
|
||||
instagram: '',
|
||||
addresses: [''],
|
||||
stageId: stages.value[0]?.id ?? '',
|
||||
assigneeId: '',
|
||||
};
|
||||
@@ -646,6 +654,18 @@ function openCreate() {
|
||||
createOpen.value = true;
|
||||
}
|
||||
|
||||
function addCreateAddress() {
|
||||
createForm.value.addresses.push('');
|
||||
}
|
||||
|
||||
function removeCreateAddress(index: number) {
|
||||
if (createForm.value.addresses.length <= 1) {
|
||||
createForm.value.addresses[0] = '';
|
||||
return;
|
||||
}
|
||||
createForm.value.addresses.splice(index, 1);
|
||||
}
|
||||
|
||||
function openEdit(lead: LeadDto) {
|
||||
rowMenuId.value = null;
|
||||
editingLeadId.value = lead.id;
|
||||
@@ -657,6 +677,8 @@ function openEdit(lead: LeadDto) {
|
||||
city: lead.city ?? '',
|
||||
region: lead.region ?? '',
|
||||
source: lead.source ?? '',
|
||||
instagram: lead.instagram ?? '',
|
||||
addresses: lead.addresses?.length ? [...lead.addresses] : [''],
|
||||
stageId: lead.stageId,
|
||||
assigneeId: lead.assigneeId ?? '',
|
||||
};
|
||||
@@ -803,6 +825,8 @@ async function submitCreate() {
|
||||
city: createForm.value.city.trim() || null,
|
||||
region: createForm.value.region.trim() || null,
|
||||
source: createForm.value.source.trim() || null,
|
||||
instagram: createForm.value.instagram.trim() || null,
|
||||
addresses: createForm.value.addresses.map((a) => a.trim()).filter(Boolean),
|
||||
stageId: createForm.value.stageId || undefined,
|
||||
assigneeId: createForm.value.assigneeId || null,
|
||||
};
|
||||
@@ -890,6 +914,8 @@ async function archiveSelected() {
|
||||
|
||||
async function exportExcel() {
|
||||
busy.value = true;
|
||||
pageBusy.value = true;
|
||||
busyMessage.value = 'در حال تهیه خروجی اکسل…';
|
||||
error.value = '';
|
||||
try {
|
||||
const { data: blob } = await api.get<Blob>('/leads/export', {
|
||||
@@ -905,6 +931,7 @@ async function exportExcel() {
|
||||
error.value = 'خروجی اکسل ناموفق بود.';
|
||||
} finally {
|
||||
busy.value = false;
|
||||
pageBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -919,13 +946,19 @@ async function pollImport(jobId: string) {
|
||||
try {
|
||||
const { data: job } = await api.get<LeadImportJobDto>(`/leads/imports/${jobId}`);
|
||||
importJob.value = job;
|
||||
if (job.status === 'pending' || job.status === 'processing') {
|
||||
pageBusy.value = true;
|
||||
busyMessage.value = `در حال ورود لیدها… ${toFaDigits(job.processedCount)} از ${toFaDigits(job.totalCount || 0)}`;
|
||||
}
|
||||
if (job.status === 'done' || job.status === 'failed' || job.status === 'completed') {
|
||||
stopImportPoll();
|
||||
pageBusy.value = false;
|
||||
okMsg.value = `ورود: موفق ${toFaDigits(job.successCount)} · تکراری ${toFaDigits(job.duplicateCount)} · خطا ${toFaDigits(job.errorCount)}`;
|
||||
await load();
|
||||
}
|
||||
} catch {
|
||||
stopImportPoll();
|
||||
pageBusy.value = false;
|
||||
error.value = 'پیگیری وضعیت ورود ناموفق بود.';
|
||||
}
|
||||
}
|
||||
@@ -938,6 +971,7 @@ function startImportPoll(jobId: string) {
|
||||
|
||||
function onExcelImportStart() {
|
||||
busy.value = true;
|
||||
pageBusy.value = false;
|
||||
okMsg.value = '';
|
||||
error.value = '';
|
||||
}
|
||||
@@ -949,6 +983,8 @@ function onExcelImportDone(result: ImportContactsResult) {
|
||||
return;
|
||||
}
|
||||
importJob.value = job;
|
||||
pageBusy.value = true;
|
||||
busyMessage.value = 'در حال ورود لیدها…';
|
||||
startImportPoll(job.id);
|
||||
}
|
||||
|
||||
@@ -962,6 +998,8 @@ function onExcelImportSettled() {
|
||||
|
||||
function onPhoneImportStart() {
|
||||
busy.value = true;
|
||||
pageBusy.value = true;
|
||||
busyMessage.value = 'در حال ورود مخاطبین گوشی…';
|
||||
okMsg.value = '';
|
||||
error.value = '';
|
||||
}
|
||||
@@ -983,6 +1021,7 @@ function onPhoneImportFail(message: string) {
|
||||
|
||||
function onPhoneImportSettled() {
|
||||
busy.value = false;
|
||||
pageBusy.value = false;
|
||||
}
|
||||
|
||||
function goDetail(id: string) {
|
||||
@@ -1027,12 +1066,13 @@ onBeforeUnmount(() => {
|
||||
|
||||
<template>
|
||||
<section class="page" @click="closePopups">
|
||||
<UiBusyOverlay :open="pageBusy" :message="busyMessage" />
|
||||
<UiPageHeader
|
||||
title="لیدها"
|
||||
lead="مدیریت و پیگیری تمام لیدهای ورودی"
|
||||
>
|
||||
<template #actions>
|
||||
<UiButton variant="ghost" size="sm" :disabled="busy" @click.stop="exportExcel">
|
||||
<UiButton variant="ghost" size="sm" :disabled="busy" :loading="pageBusy && busyMessage.includes('خروجی')" @click.stop="exportExcel">
|
||||
<span class="btn-full">خروجی اکسل</span>
|
||||
<span class="btn-short">خروجی</span>
|
||||
</UiButton>
|
||||
@@ -1045,10 +1085,12 @@ onBeforeUnmount(() => {
|
||||
@fail="onExcelImportFail"
|
||||
@settled="onExcelImportSettled"
|
||||
>
|
||||
<UiButton variant="ghost" size="sm" :disabled="busy">
|
||||
<span class="btn-full">ورود از اکسل</span>
|
||||
<span class="btn-short">ورود</span>
|
||||
</UiButton>
|
||||
<template #default="{ loading }">
|
||||
<UiButton variant="ghost" size="sm" :disabled="busy" :loading="loading">
|
||||
<span class="btn-full">ورود از اکسل</span>
|
||||
<span class="btn-short">ورود</span>
|
||||
</UiButton>
|
||||
</template>
|
||||
</ExcelImportFlow>
|
||||
<input
|
||||
ref="logoFileInput"
|
||||
@@ -1383,6 +1425,7 @@ onBeforeUnmount(() => {
|
||||
<th>شماره تماس</th>
|
||||
<th>شهر / منطقه</th>
|
||||
<th>منبع لید</th>
|
||||
<th>تاریخ ثبت</th>
|
||||
<th>وضعیت</th>
|
||||
<th>مسئول</th>
|
||||
<th>آخرین فعالیت</th>
|
||||
@@ -1454,6 +1497,7 @@ onBeforeUnmount(() => {
|
||||
<span v-if="lead.source" class="source-pill">{{ lead.source }}</span>
|
||||
<span v-else class="muted-dash">—</span>
|
||||
</td>
|
||||
<td class="date-col">{{ formatJalaliNumeric(new Date(lead.createdAt)) }}</td>
|
||||
<td>
|
||||
<span class="stage-pill" :data-tint="stageTintForLead(lead)">
|
||||
{{ lead.stageName }}
|
||||
@@ -1575,7 +1619,9 @@ onBeforeUnmount(() => {
|
||||
@fail="onExcelImportFail"
|
||||
@settled="onExcelImportSettled"
|
||||
>
|
||||
<UiButton variant="ghost" :disabled="busy">ورود از فایل</UiButton>
|
||||
<template #default="{ loading }">
|
||||
<UiButton variant="ghost" :disabled="busy" :loading="loading">ورود از فایل</UiButton>
|
||||
</template>
|
||||
</ExcelImportFlow>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1633,6 +1679,35 @@ onBeforeUnmount(() => {
|
||||
منبع
|
||||
<input v-model="createForm.source" placeholder="سایت، نمایشگاه…" />
|
||||
</label>
|
||||
<label>
|
||||
پیج اینستاگرام
|
||||
<input
|
||||
v-model="createForm.instagram"
|
||||
class="ltr"
|
||||
dir="ltr"
|
||||
placeholder="@username یا لینک"
|
||||
/>
|
||||
</label>
|
||||
<div class="addresses">
|
||||
<div class="addresses-head">
|
||||
<span>آدرسها</span>
|
||||
<button type="button" class="add-addr" @click="addCreateAddress">+ افزودن آدرس</button>
|
||||
</div>
|
||||
<div v-for="(_, idx) in createForm.addresses" :key="idx" class="addr-row">
|
||||
<input
|
||||
v-model="createForm.addresses[idx]"
|
||||
:placeholder="idx === 0 ? 'آدرس اصلی' : `آدرس ${idx + 1}`"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="rm-addr"
|
||||
aria-label="حذف آدرس"
|
||||
@click="removeCreateAddress(idx)"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="create-grid">
|
||||
<label>
|
||||
وضعیت
|
||||
@@ -2814,6 +2889,50 @@ button.m-line {
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.create-form .addresses {
|
||||
display: grid;
|
||||
gap: 0.45rem;
|
||||
}
|
||||
|
||||
.create-form .addresses-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 0.86rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.create-form .add-addr {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--accent-deep, var(--accent));
|
||||
font: inherit;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.create-form .addr-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
gap: 0.45rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.create-form .rm-addr {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
background: #fff;
|
||||
color: var(--muted);
|
||||
font: inherit;
|
||||
font-size: 1.1rem;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.create-form label {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
|
||||
Reference in New Issue
Block a user