Files
CRM_Montzar/apps/web/src/views/ContactsView.vue
T

2279 lines
66 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { RouterLink, useRoute, useRouter } from 'vue-router';
import { useQuery } from '@tanstack/vue-query';
import axios from 'axios';
import {
Alert as AAlert,
Button as AButton,
Card as ACard,
Checkbox as ACheckbox,
Dropdown as ADropdown,
Empty as AEmpty,
Flex as AFlex,
Grid,
List as AList,
ListItem as AListItem,
Menu as AMenu,
MenuItem as AMenuItem,
Modal as AModal,
Pagination as APagination,
Select as ASelect,
Space as ASpace,
Spin as ASpin,
Table as ATable,
Tag as ATag,
Typography,
theme,
} from 'ant-design-vue';
import type { TableColumnsType } from 'ant-design-vue';
import {
BankOutlined,
DeleteOutlined,
EditOutlined,
FileExcelOutlined,
IdcardOutlined,
MailOutlined,
MoreOutlined,
PhoneOutlined,
TeamOutlined,
} from '@/icons/ant-bridge';
import { api } from '@/lib/api';
import { useAuthStore } from '@/stores/auth';
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
import CustomerMoodFace from '@/components/CustomerMoodFace.vue';
2026-09-19 15:30:31 +03:30
import ExcelImportFlow from '@/components/ExcelImportFlow.vue';
import PhoneContactsImport from '@/components/PhoneContactsImport.vue';
import { FilterChips, PageHeader } from '@/components/page';
import type {
PageHeaderActiveFilter,
PageHeaderMenuItem,
PageHeaderTab,
} from '@/components/page';
import { CrmSkeleton, CrmSkeletonTable } from '@/components/skeleton';
import PersonFormView from '@/views/PersonFormView.vue';
import CompanyFormView from '@/views/CompanyFormView.vue';
import SavedFiltersBar from '@/components/SavedFiltersBar.vue';
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
import { registerTableColumns, useTableColumns } from '@/lib/tableColumns';
import type {
CompanyDto,
ImportContactsResult,
PersonDto,
PersonImportSource,
PersonMood,
} from '@mento/shared';
import {
brand,
PERSON_IMPORT_SOURCE_LABELS,
PERSON_IMPORT_SOURCES,
} from '@mento/shared';
import { PERSON_MOOD_LABELS, PERSON_MOODS } from '@/lib/person-mood';
import { canUseBehavior } from '@/lib/behavior-access';
import DiscBadge from '@/components/behavior/DiscBadge.vue';
import { PAGE_SIZE_OPTIONS, usePageSize } from '@/lib/pageSize';
import { useCustomerGroups } from '@/lib/customer-groups';
import { type ContactsFilterValue } from '@/components/ContactsFilterPanel.vue';
import { canManageSettings } from '@/lib/roles';
import { contactKeys } from '@/queries/keys';
import {
fetchCompanies,
fetchCompanyGroupStats,
fetchPeople,
fetchPeopleGroupStats,
fetchPeopleSourceStats,
invalidateContactQueries,
} from '@/queries/contacts';
const { Link: ATypographyLink, Text: ATypographyText } = Typography;
const { token } = theme.useToken();
const screens = Grid.useBreakpoint();
type Tab = 'people' | 'companies';
type SortKey = 'name' | 'newest';
const pageSize = usePageSize('contacts', 10);
const route = useRoute();
const router = useRouter();
const tab = computed<Tab>(() =>
route.query.tab === 'companies' ? 'companies' : 'people',
);
const page = computed(() => {
const raw = Number(route.query.page);
return Number.isFinite(raw) && raw > 0 ? raw : 1;
});
const sort = computed<SortKey>(() => (route.query.sort === 'newest' ? 'newest' : 'name'));
function queryList(key: string): string[] {
const raw = route.query[key];
if (typeof raw !== 'string') return [];
return [...new Set(raw.split(',').map((v) => v.trim()).filter(Boolean))];
}
function csv(list: string[]): string | undefined {
return list.length ? list.join(',') : undefined;
}
const moodFilters = computed(() =>
queryList('mood').filter((m): m is PersonMood => PERSON_MOODS.includes(m as PersonMood)),
);
const auth = useAuthStore();
const canBehavior = computed(() => canUseBehavior(auth.user));
const discFilter = computed(() => {
const value = typeof route.query.disc === 'string' ? route.query.disc.toUpperCase() : '';
return /^[DISC](\/[DISC]){0,3}$/.test(value) ? value : '';
});
const sourceFilters = computed(() => queryList('source'));
const activityExperienceFilters = computed(() => queryList('activityExperience'));
const groupFilters = computed(() => queryList('group'));
const { groups: customerGroups } = useCustomerGroups();
const canManageGroups = computed(() => canManageSettings(auth.user?.role));
const groupsManagerOpen = ref(false);
const filterValue = computed<ContactsFilterValue>(() => ({
groups: groupFilters.value,
sources: sourceFilters.value,
moods: moodFilters.value,
disc: discFilter.value,
activityExperiences: activityExperienceFilters.value,
}));
type FilterTag = {
kind: 'group' | 'source' | 'mood' | 'disc' | 'activityExperience';
value: string;
label: string;
color?: string;
};
const activeTags = computed<FilterTag[]>(() => {
const tags: FilterTag[] = groupFilters.value.map((id) => {
const g =
filterGroups.value.find((x) => x.id === id) ??
customerGroups.value.find((x) => x.id === id);
return { kind: 'group', value: id, label: g?.name ?? 'گروه حذف‌شده', color: g?.color };
});
if (tab.value !== 'people') return tags;
for (const s of sourceFilters.value) {
tags.push({ kind: 'source', value: s, label: `منبع: ${sourceLabel(s)}` });
}
for (const m of moodFilters.value) {
tags.push({ kind: 'mood', value: m, label: moodLabel(m) });
}
for (const exp of activityExperienceFilters.value) {
tags.push({ kind: 'activityExperience', value: exp, label: `سابقه: ${exp}` });
}
if (discFilter.value) tags.push({ kind: 'disc', value: discFilter.value, label: `DISC: ${discFilter.value}` });
return tags;
});
const q = ref(typeof route.query.q === 'string' ? route.query.q : '');
const busy = ref(false);
const pageBusy = ref(false);
const busyMessage = ref('لطفاً صبر کنید…');
const error = ref('');
const importMsg = ref('');
const menuId = ref<string | null>(null);
const sortOpen = ref(false);
const filterOpen = ref(false);
const moreOpen = ref(false);
const savedSheetOpen = ref(false);
const contactModal = ref<'person' | 'company' | null>(null);
/** هم‌راستا با بریک‌پوینت CSS صفحه (۹۰۰px) */
const mobileMq =
typeof window !== 'undefined' ? window.matchMedia('(max-width: 900px)') : null;
const isMobile = ref(mobileMq?.matches ?? false);
function onMobileChange(e: MediaQueryListEvent) {
isMobile.value = e.matches;
filterOpen.value = false;
sortOpen.value = false;
savedSheetOpen.value = false;
}
onMounted(() => mobileMq?.addEventListener('change', onMobileChange));
onBeforeUnmount(() => mobileMq?.removeEventListener('change', onMobileChange));
const SORT_OPTIONS = [
{ value: 'name', label: 'نام' },
{ value: 'newest', label: 'جدیدترین' },
];
const peopleParams = computed(() => ({
q: q.value || undefined,
page: page.value,
limit: pageSize.value,
sort: sort.value,
mood: csv(moodFilters.value),
importSource: csv(sourceFilters.value),
activityExperience: csv(activityExperienceFilters.value),
disc: discFilter.value || undefined,
groupId: csv(groupFilters.value),
}));
const companyParams = computed(() => ({
q: q.value || undefined,
page: page.value,
limit: pageSize.value,
groupId: csv(groupFilters.value),
}));
const peopleQuery = useQuery({
queryKey: computed(() => contactKeys.people({ ...peopleParams.value })),
queryFn: () => fetchPeople({ ...peopleParams.value }),
enabled: computed(() => tab.value === 'people'),
placeholderData: (prev) => prev,
});
const companiesQuery = useQuery({
queryKey: computed(() => contactKeys.companies({ ...companyParams.value })),
queryFn: () => fetchCompanies({ ...companyParams.value }),
enabled: computed(() => tab.value === 'companies'),
placeholderData: (prev) => prev,
});
const peopleSourceStatsQuery = useQuery({
queryKey: computed(() => contactKeys.peopleSourceStats({ ...peopleParams.value })),
queryFn: () => fetchPeopleSourceStats({ ...peopleParams.value }),
enabled: computed(() => tab.value === 'people'),
staleTime: 60_000,
placeholderData: (prev) => prev,
});
const peopleGroupStatsQuery = useQuery({
queryKey: computed(() => contactKeys.peopleGroupStats({ ...peopleParams.value })),
queryFn: () => fetchPeopleGroupStats({ ...peopleParams.value }),
enabled: computed(() => tab.value === 'people'),
staleTime: 60_000,
placeholderData: (prev) => prev,
});
const companyGroupStatsQuery = useQuery({
queryKey: computed(() => contactKeys.companyGroupStats({ ...companyParams.value })),
queryFn: () => fetchCompanyGroupStats({ ...companyParams.value }),
enabled: computed(() => tab.value === 'companies'),
staleTime: 60_000,
placeholderData: (prev) => prev,
});
const people = computed(() => peopleQuery.data.value ?? null);
const companies = computed(() => companiesQuery.data.value ?? null);
const sourceStats = computed(() => peopleSourceStatsQuery.data.value ?? []);
const filterGroups = computed(() =>
tab.value === 'people'
? (peopleGroupStatsQuery.data.value ?? [])
: (companyGroupStatsQuery.data.value ?? []),
);
const loading = computed(() => {
if (tab.value === 'people') {
return peopleQuery.isFetching.value && peopleQuery.data.value == null;
}
return companiesQuery.isFetching.value && companiesQuery.data.value == null;
});
watch(
() => (tab.value === 'people' ? peopleQuery.error.value : companiesQuery.error.value),
(err) => {
if (!err) return;
if (axios.isAxiosError(err) && !err.response) {
error.value = 'اتصال به API برقرار نشد.';
} else {
error.value = 'بارگذاری مخاطبین ناموفق بود.';
}
},
);
const total = computed(() =>
tab.value === 'people' ? people.value?.total ?? 0 : companies.value?.total ?? 0,
);
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)));
const rowOffset = computed(() => (page.value - 1) * pageSize.value);
const selectedIds = ref<string[]>([]);
const pageIds = computed(() => people.value?.items.map((p) => p.id) ?? []);
watch(
() => people.value?.items.map((p) => p.id) ?? [],
(ids) => {
const visible = new Set(ids);
selectedIds.value = selectedIds.value.filter((id) => visible.has(id));
},
);
const allSelected = computed(
() => pageIds.value.length > 0 && pageIds.value.every((id) => selectedIds.value.includes(id)),
);
const someSelected = computed(() => selectedIds.value.length > 0 && !allSelected.value);
function toggleAll() {
selectedIds.value = allSelected.value ? [] : [...pageIds.value];
}
function toggleOne(id: string) {
selectedIds.value = selectedIds.value.includes(id)
? selectedIds.value.filter((x) => x !== id)
: [...selectedIds.value, id];
}
async function deleteSelected() {
const ids = [...selectedIds.value];
if (!ids.length) return;
if (!confirm(`${toFaDigits(ids.length)} شخص انتخاب‌شده حذف شوند؟ این کار قابل بازگشت نیست.`)) {
return;
}
busy.value = true;
pageBusy.value = true;
busyMessage.value = 'در حال حذف اشخاص…';
try {
const { data } = await api.post<{ deleted: number }>('/people/bulk-delete', { ids });
importMsg.value = `${toFaDigits(data.deleted)} شخص حذف شد.`;
selectedIds.value = [];
if (data.deleted >= pageIds.value.length && page.value > 1) setPage(page.value - 1);
else await load();
} catch {
error.value = 'حذف اشخاص ناموفق بود.';
} finally {
busy.value = false;
pageBusy.value = false;
}
}
function onPageSize(size: number) {
pageSize.value = size;
/* peopleParams/companyParams include limit → query key refetch */
}
const peopleSavedFilters = computed(() => {
const out: Record<string, string> = {};
const nextQ = q.value.trim();
if (nextQ) out.q = nextQ;
if (sort.value !== 'name') out.sort = sort.value;
const mood = csv(moodFilters.value);
if (mood) out.mood = mood;
const source = csv(sourceFilters.value);
if (source) out.source = source;
const activityExperience = csv(activityExperienceFilters.value);
if (activityExperience) out.activityExperience = activityExperience;
if (discFilter.value) out.disc = discFilter.value;
const group = csv(groupFilters.value);
if (group) out.group = group;
return out;
});
/** مقدار ذخیره‌شده: رشته یا آرایه → رشتهٔ کاما‌جدا برای URL */
function savedCsv(raw: unknown): string | undefined {
if (Array.isArray(raw)) {
const list = raw.map((v) => String(v).trim()).filter(Boolean);
return list.length ? list.join(',') : undefined;
}
if (typeof raw === 'string' && raw.trim()) return raw.trim();
return undefined;
}
function applyPeopleSavedFilters(filters: Record<string, unknown>) {
const nextQ = typeof filters.q === 'string' ? filters.q : '';
q.value = nextQ;
// کلیدهای فیلتر را از نو می‌سازیم تا فیلتر قبلی روی صفحه نماند
const query: Record<string, string | string[]> = {};
for (const [key, value] of Object.entries(route.query)) {
if (['q', 'sort', 'mood', 'source', 'activityExperience', 'disc', 'group', 'page', 'tab'].includes(key)) continue;
if (value == null || value === '') continue;
if (Array.isArray(value)) {
const list = value.filter((v): v is string => typeof v === 'string' && v !== '');
if (list.length) query[key] = list;
} else if (typeof value === 'string') {
query[key] = value;
}
}
if (nextQ.trim()) query.q = nextQ.trim();
if (filters.sort === 'newest') query.sort = 'newest';
const mood = savedCsv(filters.mood);
if (mood) query.mood = mood;
const source = savedCsv(filters.source);
if (source) query.source = source;
const activityExperience = savedCsv(filters.activityExperience);
if (activityExperience) query.activityExperience = activityExperience;
const disc = savedCsv(filters.disc);
if (disc) query.disc = disc;
const group = savedCsv(filters.group);
if (group) query.group = group;
void router.replace({ name: 'contacts', query }).then(() => {
void load();
});
}
function sourceLabel(source: string) {
if (source in PERSON_IMPORT_SOURCE_LABELS) {
return PERSON_IMPORT_SOURCE_LABELS[source as PersonImportSource];
}
return source || 'دستی';
}
function moodOf(person: PersonDto): PersonMood {
return person.mood || 'newcomer';
}
function moodLabel(mood: PersonMood) {
return PERSON_MOOD_LABELS[mood];
}
/** کد شخص در نرم‌افزار مبدأ (دیدار و مشابه) */
function externalCode(person: PersonDto): string {
if (person.sourceRef?.trim()) return person.sourceRef.trim();
const fields = person.customFields ?? {};
for (const key of ['didarId', 'customerCode'] as const) {
const raw = fields[key];
if (typeof raw === 'string' && raw.trim()) return raw.trim();
if (typeof raw === 'number' && Number.isFinite(raw)) return String(raw);
}
return '';
}
function externalCodeLabel(person: PersonDto): string {
const code = externalCode(person);
return code ? toFaDigits(code) : '—';
}
function formatDate(value: string) {
try {
return formatJalaliNumeric(new Date(value));
} catch {
return value;
}
}
function closePopups() {
menuId.value = null;
sortOpen.value = false;
filterOpen.value = false;
moreOpen.value = false;
}
async function load() {
error.value = '';
closePopups();
await invalidateContactQueries();
if (tab.value === 'people') {
await Promise.all([
peopleQuery.refetch(),
peopleSourceStatsQuery.refetch(),
peopleGroupStatsQuery.refetch(),
]);
} else {
await Promise.all([companiesQuery.refetch(), companyGroupStatsQuery.refetch()]);
}
}
function patchQuery(next: Record<string, string | undefined>) {
const query = { ...route.query, ...next };
for (const key of Object.keys(query)) {
if (query[key] == null || query[key] === '') delete query[key];
}
void router.replace({ name: 'contacts', query });
}
function setTab(next: Tab) {
patchQuery({
tab: next === 'people' ? undefined : next,
page: undefined,
});
}
function onSearch() {
patchQuery({ q: q.value.trim() || undefined, page: undefined });
}
function setSort(next: SortKey) {
sortOpen.value = false;
patchQuery({ sort: next === 'name' ? undefined : next, page: undefined });
}
function applyFilters(next: ContactsFilterValue, nextSort?: string) {
filterOpen.value = false;
const people = tab.value === 'people';
patchQuery({
group: csv(next.groups),
...(people
? {
source: csv(next.sources),
mood: csv(next.moods),
activityExperience: csv(next.activityExperiences),
disc: next.disc || undefined,
}
: {}),
// در موبایل مرتب‌سازی داخل همان شیت فیلتر است؛ یک patch تا query قبلی overwrite نشود
...(nextSort !== undefined
? { sort: nextSort === 'newest' ? 'newest' : undefined }
: {}),
page: undefined,
});
}
/** شمارنده روی دکمه فیلتر موبایل (فیلترها + مرتب‌سازی غیرپیش‌فرض) */
const mobileFilterCount = computed(
() => activeTags.value.length + (sort.value !== 'name' ? 1 : 0),
);
function openSavedSheet() {
moreOpen.value = false;
savedSheetOpen.value = true;
}
function applySavedFromSheet(filters: Record<string, unknown>) {
savedSheetOpen.value = false;
applyPeopleSavedFilters(filters);
}
function removeTag(tag: FilterTag) {
const without = (list: string[]) => csv(list.filter((v) => v !== tag.value));
if (tag.kind === 'group') patchQuery({ group: without(groupFilters.value), page: undefined });
else if (tag.kind === 'source') patchQuery({ source: without(sourceFilters.value), page: undefined });
else if (tag.kind === 'mood') patchQuery({ mood: without(moodFilters.value), page: undefined });
else if (tag.kind === 'activityExperience') {
patchQuery({
activityExperience: without(activityExperienceFilters.value),
page: undefined,
});
} else patchQuery({ disc: undefined, page: undefined });
}
function clearFilters() {
patchQuery({
group: undefined,
...(tab.value === 'people'
? {
source: undefined,
mood: undefined,
activityExperience: undefined,
disc: undefined,
}
: {}),
page: undefined,
});
}
async function onGroupsChanged() {
await load();
}
function setPage(next: number) {
if (next < 1 || next > pageCount.value) return;
patchQuery({ page: next === 1 ? undefined : String(next) });
}
async function setMoodFor(person: PersonDto, mood: PersonMood) {
menuId.value = null;
try {
await api.patch(`/people/${person.id}`, { mood });
await load();
} catch {
error.value = 'تغییر وضعیت مشتری ناموفق بود.';
}
}
async function exportExcel() {
busy.value = true;
pageBusy.value = true;
busyMessage.value = 'در حال تهیه خروجی اکسل…';
importMsg.value = '';
error.value = '';
try {
const path = tab.value === 'people' ? '/people/export' : '/companies/export';
const { data } = await api.get<Blob>(path, {
params: { q: q.value || undefined },
responseType: 'blob',
});
const url = URL.createObjectURL(data);
const a = document.createElement('a');
a.href = url;
a.download =
tab.value === 'people' ? `${brand.filePrefix}-people.xlsx` : `${brand.filePrefix}-companies.xlsx`;
a.click();
URL.revokeObjectURL(url);
} catch {
error.value = 'خروجی اکسل ناموفق بود.';
} finally {
busy.value = false;
pageBusy.value = false;
}
}
2026-09-19 15:30:31 +03:30
const importPreviewPath = computed(() =>
tab.value === 'people' ? '/people/import/preview' : '/companies/import/preview',
);
const importPath = computed(() =>
tab.value === 'people' ? '/people/import' : '/companies/import',
);
2026-09-19 15:30:31 +03:30
function onImportStart() {
busy.value = true;
pageBusy.value = false;
importMsg.value = '';
error.value = '';
2026-09-19 15:30:31 +03:30
}
async function onImportDone(data: ImportContactsResult) {
importMsg.value = `وارد شد: ${data.created} · تکراری رد شد: ${data.skipped}${
data.errors.length ? ` · خطا: ${data.errors.length}` : ''
}`;
if (data.errors.length) {
error.value = data.errors
.slice(0, 3)
.map((e) => `ردیف ${e.row}: ${e.message}`)
.join(' | ');
}
2026-09-19 15:30:31 +03:30
await load();
}
function onPhoneImportStart() {
busy.value = true;
pageBusy.value = true;
busyMessage.value = 'در حال ورود مخاطبین گوشی…';
importMsg.value = '';
error.value = '';
}
async function onPhoneImportDone(data: {
created: number;
skipped: number;
failed: number;
}) {
importMsg.value = `از گوشی وارد شد: ${toFaDigits(data.created)} · تکراری: ${toFaDigits(data.skipped)}${
data.failed ? ` · ناموفق: ${toFaDigits(data.failed)}` : ''
}`;
await load();
}
function onPhoneImportFail(message: string) {
error.value = message;
}
function onPhoneImportSettled() {
busy.value = false;
pageBusy.value = false;
}
2026-09-19 15:30:31 +03:30
function onImportFail(message: string) {
error.value = message;
}
function onImportSettled() {
busy.value = false;
pageBusy.value = false;
}
watch(
() => route.query.q,
() => {
q.value = typeof route.query.q === 'string' ? route.query.q : '';
},
);
const isCompact = computed(() => !screens.value.lg);
const excelImportTrigger = ref<HTMLElement | null>(null);
const phoneImportTrigger = ref<HTMLElement | null>(null);
const contactModalOpen = computed({
get: () => contactModal.value !== null,
set: (open: boolean) => {
if (!open) contactModal.value = null;
},
});
/** سلکت سریع هدر — تک‌مقدار روی query چندمقداری */
const moodFilter = computed<PersonMood | 'all'>(() => moodFilters.value[0] ?? 'all');
const sourceFilter = computed<PersonImportSource | 'all'>(() => {
const value = sourceFilters.value[0];
return value && PERSON_IMPORT_SOURCES.includes(value as PersonImportSource)
? (value as PersonImportSource)
: 'all';
});
const headerTabs: PageHeaderTab[] = [
{ key: 'people', label: 'اشخاص' },
{ key: 'companies', label: 'شرکت‌ها' },
];
const headerMenuItems = computed<PageHeaderMenuItem[]>(() => {
const items: PageHeaderMenuItem[] = [
{ key: 'export', label: 'خروجی اکسل', icon: FileExcelOutlined },
{ key: 'import', label: 'ورود از اکسل', icon: FileExcelOutlined },
];
if (tab.value === 'people') {
items.push({ key: 'phone', label: 'از مخاطبین گوشی', icon: PhoneOutlined });
}
if (canManageGroups.value) {
items.push({
key: 'groups',
label: 'مدیریت گروه‌ها',
dividerBefore: true,
});
}
return items;
});
const KIND_LABEL: Record<FilterTag['kind'], string> = {
group: 'گروه',
source: 'منبع',
mood: 'وضعیت',
disc: 'DISC',
activityExperience: 'سابقه',
};
const activeFilterChips = computed<PageHeaderActiveFilter[]>(() =>
activeTags.value.map((tag) => ({
key: `${tag.kind}:${tag.value}`,
label: KIND_LABEL[tag.kind],
value: tag.label,
})),
);
function onHeaderMenu(key: string) {
if (key === 'export') void exportExcel();
else if (key === 'import') excelImportTrigger.value?.click();
else if (key === 'phone') phoneImportTrigger.value?.click();
else if (key === 'groups') groupsManagerOpen.value = true;
}
function onHeaderTab(key: string | number) {
setTab(String(key) === 'companies' ? 'companies' : 'people');
}
function onSearchInput(value: string) {
q.value = value;
}
function onRemoveFilter(key: string) {
const sep = key.indexOf(':');
if (sep < 0) return;
const kind = key.slice(0, sep) as FilterTag['kind'];
const value = key.slice(sep + 1);
const tag = activeTags.value.find((t) => t.kind === kind && t.value === value);
if (tag) removeTag(tag);
}
function clearPeopleFilters() {
clearFilters();
}
const PEOPLE_COL_LABELS = [
'#',
'وضعیت',
'نام شخص',
'منبع',
'کد مبدأ',
'سمت',
'شرکت',
'تلفن',
'ایمیل',
'تاریخ ثبت',
];
const COMPANY_COL_LABELS = [
'#',
'نام شرکت',
'کد دیدار شرکت',
'کد شرکت',
'منبع',
'گروه بندی',
'استان',
'شهرستان',
'تلفن شرکت',
'ایمیل شرکت',
'شناسه ملی',
'شماره اقتصادی',
'مسئول شرکت',
'تاریخ ثبت',
'افراد',
];
registerTableColumns('contacts.people', PEOPLE_COL_LABELS);
registerTableColumns('contacts.companies', COMPANY_COL_LABELS);
const peopleCols = useTableColumns(() => 'contacts.people');
const companyCols = useTableColumns(() => 'contacts.companies');
function shownColumns<T>(cols: TableColumnsType<T>, visible: (label: string) => boolean) {
return cols.filter((col) => {
const title = typeof col.title === 'string' ? col.title : '';
if (!title || col.key === 'select' || col.key === 'actions') return true;
return visible(title);
});
}
const peopleColumns = computed<TableColumnsType<PersonDto>>(() =>
shownColumns(
[
{ title: '', key: 'select', width: 48 },
{ title: '#', key: 'row', width: 72 },
{ title: 'وضعیت', key: 'mood', width: 88 },
{ title: 'نام شخص', key: 'name' },
{ title: 'منبع', key: 'source' },
{ title: 'کد مبدأ', key: 'code', width: 120 },
{ title: 'سمت', key: 'position' },
{ title: 'شرکت', key: 'company' },
{ title: 'تلفن', key: 'phone' },
{ title: 'ایمیل', key: 'email' },
{ title: 'تاریخ ثبت', key: 'createdAt', width: 130 },
{ title: '', key: 'actions', width: 56 },
],
(label) => peopleCols.isVisible(label),
),
);
const companyColumns = computed<TableColumnsType<CompanyDto>>(() =>
shownColumns(
[
{ title: '#', key: 'row', width: 72 },
{ title: 'نام شرکت', key: 'name' },
{ title: 'کد دیدار شرکت', key: 'sourceRef' },
{ title: 'کد شرکت', key: 'code' },
{ title: 'منبع', key: 'source' },
{ title: 'گروه بندی', key: 'group' },
{ title: 'استان', key: 'province' },
{ title: 'شهرستان', key: 'city' },
{ title: 'تلفن شرکت', key: 'phone' },
{ title: 'ایمیل شرکت', key: 'email' },
{ title: 'شناسه ملی', key: 'nationalId' },
{ title: 'شماره اقتصادی', key: 'economicCode' },
{ title: 'مسئول شرکت', key: 'owner' },
{ title: 'تاریخ ثبت', key: 'createdAt', width: 130 },
{ title: 'افراد', key: 'peopleCount', width: 80 },
],
(label) => companyCols.isVisible(label),
),
);
const sortOptions: Array<{ value: SortKey; label: string }> = [
{ value: 'name', label: 'نام' },
{ value: 'newest', label: 'جدیدترین' },
];
const moodOptions = computed(() => [
{ value: 'all', label: 'همه' },
...PERSON_MOODS.map((mood) => ({ value: mood, label: moodLabel(mood) })),
]);
const sourceOptions = computed(() => [
{ value: 'all', label: 'همه منابع' },
...sourceStats.value.map((row) => ({
value: row.source,
label: `${row.label} (${toFaDigits(row.count)})`,
})),
]);
const discOptions = [
{ value: 'D', label: 'D' },
{ value: 'I', label: 'I' },
{ value: 'S', label: 'S' },
{ value: 'C', label: 'C' },
];
const discSelected = computed(() =>
discFilter.value ? discFilter.value.split('/').filter(Boolean) : [],
);
function onDiscChange(next: string[]) {
const cleaned = discOptions.map((o) => o.value).filter((v) => next.includes(v));
patchQuery({ disc: cleaned.length ? cleaned.join('/') : undefined, page: undefined });
}
function moodTagColor(mood: PersonMood) {
if (mood === 'happy') return 'purple';
if (mood === 'unhappy') return 'error';
if (mood === 'special') return 'warning';
return 'success';
}
function onSortChange(value: unknown) {
if (Array.isArray(value)) {
setSort(value[0] === 'newest' ? 'newest' : 'name');
return;
}
setSort(value === 'newest' ? 'newest' : 'name');
}
function onMoodChange(value: unknown) {
const next =
typeof value === 'string' && PERSON_MOODS.includes(value as PersonMood)
? (value as PersonMood)
: undefined;
patchQuery({ mood: next, page: undefined });
}
function onSourceChange(value: unknown) {
const next =
typeof value === 'string' && PERSON_IMPORT_SOURCES.includes(value as PersonImportSource)
? value
: undefined;
patchQuery({ source: next, page: undefined });
}
function onPersonMenu(id: string, prefix: 't' | 'm', open: boolean) {
menuId.value = open ? `${prefix}:${id}` : null;
}
function onTablePage(nextPage: number, nextSize: number) {
const size = Number(nextSize);
if (size !== pageSize.value) onPageSize(size);
if (nextPage !== page.value) setPage(nextPage);
}
function pageTotalText(totalCount: number, range: [number, number]) {
return `نمایش ${toFaDigits(range[0])} تا ${toFaDigits(range[1])} از ${toFaDigits(totalCount)}`;
}
function peopleCustomRow(record: PersonDto) {
return {
style: selectedIds.value.includes(record.id)
? { background: token.value.colorPrimaryBg }
: undefined,
};
}
</script>
<template>
<a-flex vertical :gap="16" @click="closePopups">
<PageHeader
title="مخاطبین"
:icon="TeamOutlined"
:primary-label="tab === 'companies' ? 'شرکت جدید' : 'شخص جدید'"
:menu-items="headerMenuItems"
:tabs="headerTabs"
:active-tab="tab"
searchable
:search="q"
:search-placeholder="tab === 'people' ? 'جستجو در اشخاص…' : 'جستجو در شرکت‌ها…'"
:active-filters="activeFilterChips"
:result-count="activeFilterChips.length ? total : undefined"
@primary="contactModal = tab === 'companies' ? 'company' : 'person'"
@menu="onHeaderMenu"
@update:active-tab="onHeaderTab"
@update:search="onSearchInput"
@search-submit="onSearch"
@remove-filter="onRemoveFilter"
@clear-filters="clearPeopleFilters"
>
<template #quick-filters>
<template v-if="tab === 'people'">
<a-select
:value="moodFilter"
:options="moodOptions"
:style="{ width: '150px' }"
@update:value="onMoodChange"
/>
<a-select
v-if="sourceStats.length"
:value="sourceFilter"
:options="sourceOptions"
:style="{ width: '170px' }"
@update:value="onSourceChange"
/>
</template>
</template>
<template v-if="tab === 'people'" #saved-filters>
<div :style="{ width: '280px', maxWidth: '100%' }">
<SavedFiltersBar
scope="people"
compact
:current-filters="peopleSavedFilters"
@apply="applyPeopleSavedFilters"
/>
</div>
</template>
<template #toolbar-end>
<TableColumnsMenu
icon-only
align="end"
:table-key="tab === 'people' ? 'contacts.people' : 'contacts.companies'"
/>
</template>
<template v-if="tab === 'people' && canBehavior" #chips>
<FilterChips
label="DISC"
:options="discOptions"
:model-value="discSelected"
@update:model-value="onDiscChange"
/>
</template>
<!-- مرتب‌سازی فقط روی لیست اشخاص اثر دارد -->
<template v-if="tab === 'people'" #chips-end>
<FilterChips
label="مرتب‌سازی"
:options="sortOptions"
:multiple="false"
:show-all="false"
:model-value="[sort]"
@update:model-value="onSortChange"
/>
</template>
</PageHeader>
<!-- تریگرهای ورود داده؛ از منوی «⋯» هدر کلیک می‌شوند (مودال‌هایشان به body تلپورت می‌شوند) -->
<div hidden>
<ExcelImportFlow
:preview-path="importPreviewPath"
:import-path="importPath"
:disabled="busy"
@start="onImportStart"
@done="onImportDone"
@fail="onImportFail"
@settled="onImportSettled"
>
<span ref="excelImportTrigger"></span>
</ExcelImportFlow>
<PhoneContactsImport
v-if="tab === 'people'"
:disabled="busy"
@start="onPhoneImportStart"
@done="onPhoneImportDone"
@fail="onPhoneImportFail"
@settled="onPhoneImportSettled"
>
<span ref="phoneImportTrigger"></span>
</PhoneContactsImport>
</div>
<a-spin :spinning="pageBusy" :tip="busyMessage">
<a-card :bordered="false">
<a-flex vertical :gap="16">
<a-alert v-if="importMsg" type="success" show-icon :message="importMsg" />
<a-alert v-if="error" type="error" show-icon :message="error" />
<CrmSkeleton v-if="!error" :loading="loading">
<CrmSkeletonTable :rows="8" :columns="10" :card="false">
<template v-if="tab === 'people'">
<template v-if="people?.items.length">
<a-alert v-if="selectedIds.length" type="info" show-icon>
<template #message>
<a-flex justify="space-between" align="center" wrap="wrap" :gap="8">
<span>{{ toFaDigits(selectedIds.length) }} شخص انتخاب شده</span>
<a-space>
<a-button type="link" @click="selectedIds = []">لغو انتخاب</a-button>
<a-button danger :disabled="busy" @click="deleteSelected">
<template #icon><DeleteOutlined /></template>
حذف انتخاب‌شده‌ها
</a-button>
</a-space>
</a-flex>
</template>
</a-alert>
<a-list v-if="isCompact" :data-source="people.items" :row-key="(item: PersonDto) => item.id">
<template #renderItem="{ item }">
<a-list-item>
<a-flex align="flex-start" :gap="12" style="width: 100%">
<CustomerMoodFace :mood="moodOf(item)" :size="48" />
<div style="min-width: 0; flex: 1">
<a-flex justify="space-between" align="flex-start" :gap="8">
<a-space wrap :size="8">
<RouterLink
v-slot="{ href, navigate }"
custom
:to="{ name: 'person-detail', params: { id: item.id } }"
>
<a-typography-link :href="href" @click="navigate">{{ item.fullName }}</a-typography-link>
</RouterLink>
<DiscBadge v-if="canBehavior" :label="item.discLabel" />
</a-space>
<a-dropdown
:trigger="['click']"
:open="menuId === `m:${item.id}`"
@click.stop
@update:open="(open: boolean) => onPersonMenu(item.id, 'm', open)"
>
<a-button type="text" aria-label="عملیات" @click.stop>
<template #icon><MoreOutlined /></template>
</a-button>
<template #overlay>
<a-menu>
<a-menu-item
key="detail"
@click="
router.push({
name: 'person-detail',
params: { id: item.id },
})
"
>
<template #icon><IdcardOutlined /></template>
پرونده
</a-menu-item>
<a-menu-item
key="edit"
@click="
router.push({
name: 'person-edit',
params: { id: item.id },
})
"
>
<template #icon><EditOutlined /></template>
ویرایش
</a-menu-item>
<a-menu-item
v-for="mood in PERSON_MOODS"
:key="mood"
@click="setMoodFor(item, mood)"
>
<template #icon>
<CustomerMoodFace :mood="mood" :size="18" />
</template>
{{ moodLabel(mood) }}
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-flex>
<div>
<a-typography-text type="secondary">
{{ [item.position, item.company?.name].filter(Boolean).join(' • ') || 'بدون سمت' }}
</a-typography-text>
</div>
<div>
<a-typography-text type="secondary">
منبع: {{ sourceLabel(item.importSource || 'manual') }}
<template v-if="externalCode(item)"> · کد: {{ externalCodeLabel(item) }}</template>
</a-typography-text>
</div>
<div v-if="item.previousFullName">
<a-typography-text type="secondary">نام قبلی: {{ item.previousFullName }}</a-typography-text>
</div>
<div v-if="item.mobile || item.phone" dir="ltr">
<a-space :size="4">
<PhoneOutlined />
<span>{{ item.mobile || item.phone }}</span>
</a-space>
</div>
<div v-if="item.email" dir="ltr">
<a-space :size="4">
<MailOutlined />
<span>{{ item.email }}</span>
</a-space>
</div>
<a-tag :color="moodTagColor(moodOf(item))">{{ moodLabel(moodOf(item)) }}</a-tag>
</div>
</a-flex>
</a-list-item>
</template>
</a-list>
<a-table
v-else
:columns="peopleColumns"
:data-source="people.items"
:pagination="false"
:row-key="(row: PersonDto) => row.id"
:scroll="{ x: 1100 }"
:custom-row="peopleCustomRow"
>
<template #headerCell="{ column }">
<a-checkbox
v-if="column.key === 'select'"
:checked="allSelected"
:indeterminate="someSelected"
aria-label="انتخاب همه"
@change="toggleAll"
/>
<template v-else>{{ column.title }}</template>
</template>
<template #bodyCell="{ column, record, index }">
<template v-if="column.key === 'select'">
<a-checkbox
:checked="selectedIds.includes(record.id)"
:aria-label="`انتخاب ${record.fullName}`"
@click.stop
@change="toggleOne(record.id)"
/>
</template>
<template v-else-if="column.key === 'row'">
{{ toFaDigits(rowOffset + Number(index) + 1) }}
</template>
<template v-else-if="column.key === 'mood'">
<CustomerMoodFace :mood="moodOf(record as PersonDto)" :size="34" />
</template>
<template v-else-if="column.key === 'name'">
<RouterLink
v-slot="{ href, navigate }"
custom
:to="{ name: 'person-detail', params: { id: record.id } }"
>
<a-typography-link :href="href" @click="navigate">{{ record.fullName }}</a-typography-link>
</RouterLink>
<DiscBadge v-if="canBehavior" :label="record.discLabel" />
<div v-if="record.previousFullName">
<a-typography-text type="secondary">قبلی: {{ record.previousFullName }}</a-typography-text>
</div>
</template>
<template v-else-if="column.key === 'source'">
{{ sourceLabel(record.importSource || 'manual') }}
<div v-if="record.previousImportSource">
<a-typography-text type="secondary">
قبلاً: {{ sourceLabel(record.previousImportSource) }}
<bdi v-if="record.previousSourceRef">{{ toFaDigits(record.previousSourceRef) }}</bdi>
</a-typography-text>
</div>
</template>
<template v-else-if="column.key === 'code'">
<span dir="ltr">{{ externalCodeLabel(record as PersonDto) }}</span>
</template>
<template v-else-if="column.key === 'position'">
{{ record.position || '—' }}
</template>
<template v-else-if="column.key === 'company'">
<RouterLink
v-if="record.company"
v-slot="{ href, navigate }"
custom
:to="{ name: 'company-detail', params: { id: record.company.id } }"
>
<a-typography-link :href="href" @click="navigate">{{ record.company.name }}</a-typography-link>
</RouterLink>
<a-typography-text v-else type="secondary">—</a-typography-text>
</template>
<template v-else-if="column.key === 'phone'">
<span dir="ltr">{{ record.mobile || record.phone || '—' }}</span>
</template>
<template v-else-if="column.key === 'email'">
<a-space v-if="record.email" :size="4">
<span dir="ltr">{{ record.email }}</span>
<MailOutlined />
</a-space>
<template v-else>—</template>
</template>
<template v-else-if="column.key === 'createdAt'">
{{ formatDate(record.createdAt) }}
</template>
<template v-else-if="column.key === 'actions'">
<a-dropdown
:trigger="['click']"
:open="menuId === `t:${record.id}`"
@click.stop
@update:open="(open: boolean) => onPersonMenu(record.id, 't', open)"
>
<a-button type="text" aria-label="عملیات" @click.stop>
<template #icon><MoreOutlined /></template>
</a-button>
<template #overlay>
<a-menu>
<a-menu-item
key="detail"
@click="
router.push({
name: 'person-detail',
params: { id: record.id },
})
"
>
<template #icon><IdcardOutlined /></template>
پرونده
</a-menu-item>
<a-menu-item
key="edit"
@click="
router.push({
name: 'person-edit',
params: { id: record.id },
})
"
>
<template #icon><EditOutlined /></template>
ویرایش
</a-menu-item>
<a-menu-item
v-for="mood in PERSON_MOODS"
:key="mood"
@click="setMoodFor(record as PersonDto, mood)"
>
<template #icon>
<CustomerMoodFace :mood="mood" :size="18" />
</template>
{{ moodLabel(mood) }}
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
</template>
</a-table>
</template>
<a-empty
v-else-if="!loading"
description="شخصی ثبت نشده است. اولین مخاطب یا مشتری را اضافه کنید."
/>
</template>
<template v-else>
<template v-if="companies?.items.length">
<a-list v-if="isCompact" :data-source="companies.items" :row-key="(item: CompanyDto) => item.id">
<template #renderItem="{ item }">
<a-list-item>
<a-flex align="flex-start" :gap="12">
<BankOutlined />
<div>
<RouterLink
v-slot="{ href, navigate }"
custom
:to="{ name: 'company-detail', params: { id: item.id } }"
>
<a-typography-link :href="href" @click="navigate">{{ item.name }}</a-typography-link>
</RouterLink>
<div v-if="item.phone" dir="ltr">
<a-space :size="4">
<PhoneOutlined />
<span>{{ item.phone }}</span>
</a-space>
</div>
<div v-if="item.email" dir="ltr">
<a-space :size="4">
<MailOutlined />
<span>{{ item.email }}</span>
</a-space>
</div>
<div v-if="item.sourceRef || item.code">
<a-typography-text type="secondary">
{{ item.sourceRef ? `کد دیدار: ${toFaDigits(item.sourceRef)}` : '' }}
{{ item.sourceRef && item.code ? ' • ' : '' }}
{{ item.code ? `کد: ${toFaDigits(item.code)}` : '' }}
</a-typography-text>
</div>
<div>
<a-typography-text type="secondary">
{{ [item.city, item.owner?.fullName].filter(Boolean).join(' • ') }}
{{ item.city || item.owner ? ' • ' : '' }}افراد: {{ toFaDigits(item.peopleCount) }}
</a-typography-text>
</div>
</div>
</a-flex>
</a-list-item>
</template>
</a-list>
<a-table
v-else
:columns="companyColumns"
:data-source="companies.items"
:pagination="false"
:row-key="(row: CompanyDto) => row.id"
:scroll="{ x: 1600 }"
>
<template #bodyCell="{ column, record, index }">
<template v-if="column.key === 'row'">
{{ toFaDigits(rowOffset + Number(index) + 1) }}
</template>
<template v-else-if="column.key === 'name'">
<RouterLink
v-slot="{ href, navigate }"
custom
:to="{ name: 'company-detail', params: { id: record.id } }"
>
<a-typography-link :href="href" @click="navigate">{{ record.name }}</a-typography-link>
</RouterLink>
</template>
<template v-else-if="column.key === 'sourceRef'">
<span dir="ltr">{{ record.sourceRef ? toFaDigits(record.sourceRef) : '—' }}</span>
</template>
<template v-else-if="column.key === 'code'">
<span dir="ltr">{{ record.code ? toFaDigits(record.code) : '—' }}</span>
</template>
<template v-else-if="column.key === 'source'">
{{ sourceLabel(record.importSource || 'manual') }}
</template>
<template v-else-if="column.key === 'group'">
{{ record.groupName || '—' }}
</template>
<template v-else-if="column.key === 'province'">
{{ record.province || '—' }}
</template>
<template v-else-if="column.key === 'city'">
{{ record.city || '—' }}
</template>
<template v-else-if="column.key === 'phone'">
<span dir="ltr">{{ record.phone || '—' }}</span>
</template>
<template v-else-if="column.key === 'email'">
<span dir="ltr">{{ record.email || '—' }}</span>
</template>
<template v-else-if="column.key === 'nationalId'">
<span dir="ltr">{{ record.nationalId || '—' }}</span>
</template>
<template v-else-if="column.key === 'economicCode'">
<span dir="ltr">{{ record.economicCode || '—' }}</span>
</template>
<template v-else-if="column.key === 'owner'">
{{ record.owner?.fullName || '—' }}
</template>
<template v-else-if="column.key === 'createdAt'">
{{ formatDate(record.registeredAt || record.createdAt) }}
</template>
<template v-else-if="column.key === 'peopleCount'">
{{ toFaDigits(record.peopleCount) }}
</template>
</template>
</a-table>
</template>
<a-empty
v-else-if="!loading"
description="شرکتی ثبت نشده است. اولین شرکت یا سازمان را اضافه کنید."
/>
</template>
</CrmSkeletonTable>
</CrmSkeleton>
<a-flex v-if="total" justify="flex-start">
<a-pagination
:current="page"
:page-size="pageSize"
:total="total"
:page-size-options="PAGE_SIZE_OPTIONS.map(String)"
show-size-changer
:show-total="pageTotalText"
@change="onTablePage"
/>
</a-flex>
</a-flex>
</a-card>
</a-spin>
</a-flex>
<a-modal
v-model:open="contactModalOpen"
:title="contactModal === 'company' ? 'شرکت جدید' : 'شخص جدید'"
:footer="null"
:width="960"
>
<PersonFormView
v-if="contactModal === 'person'"
embedded
@saved="contactModal = null; void load()"
@cancel="contactModal = null"
/>
<CompanyFormView
v-else-if="contactModal === 'company'"
embedded
@saved="contactModal = null; void load()"
@cancel="contactModal = null"
/>
</a-modal>
</template>
<style scoped>
.page {
display: grid;
/* بدون این، ردیف‌های grid ارتفاع اضافهٔ صفحه را بین خودشان پخش می‌کنند */
align-content: start;
gap: 0.5rem;
width: 100%;
min-width: 0;
max-width: 100%;
overflow-x: clip;
box-sizing: border-box;
}
.page > * {
min-width: 0;
max-width: 100%;
}
.page-head {
display: flex;
justify-content: space-between;
gap: 0.45rem 0.75rem;
align-items: center;
flex-wrap: nowrap;
}
.head-start {
display: flex;
align-items: center;
gap: 0.55rem;
min-width: 0;
flex: 1 1 auto;
}
h1 {
margin: 0;
font-size: 1.1rem;
font-weight: 700;
line-height: 1.25;
}
.muted {
color: #64748b;
overflow-wrap: anywhere;
word-break: break-word;
}
.actions {
display: flex;
gap: 0.3rem;
align-items: center;
flex-wrap: nowrap;
justify-content: flex-end;
flex: 0 0 auto;
min-width: 0;
}
.actions-desktop {
display: flex;
gap: 0.3rem;
align-items: center;
flex-wrap: nowrap;
}
.actions-more {
display: none;
}
.btn-short {
display: none;
}
/* از عرض متوسط لیبل کوتاه تا اکشن‌ها به ردیف دوم نروند */
@media (max-width: 1280px) {
.actions .btn-full {
display: none;
}
.actions .btn-short {
display: inline;
}
}
.chrome {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.4rem;
min-width: 0;
}
.tabs {
display: inline-flex;
gap: 0.15rem;
padding: 0.15rem;
background: #f1f5f9;
border-radius: var(--radius);
flex-shrink: 0;
}
.tabs button {
border: 0;
background: transparent;
padding: 0.35rem 0.65rem;
font: inherit;
font-size: var(--fs-sm);
color: #64748b;
display: inline-flex;
align-items: center;
gap: 0.3rem;
cursor: pointer;
white-space: nowrap;
border-radius: calc(var(--radius) - 2px);
line-height: 1.2;
}
.tabs .on {
color: #0f766e;
font-weight: 600;
background: #fff;
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.tabs em {
font-style: normal;
font-size: 0.72rem;
color: #94a3b8;
}
.filter-tags {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.3rem;
}
.filter-tag {
display: inline-flex;
align-items: center;
gap: 0.2rem;
padding: 0.1rem 0.25rem 0.1rem 0.5rem;
border-radius: 999px;
background: #f0fdfa;
color: #0f766e;
font-size: 0.75rem;
font-weight: 600;
}
.filter-tag button {
display: inline-grid;
place-items: center;
width: 1rem;
height: 1rem;
border: 0;
border-radius: 50%;
background: rgba(15, 23, 42, 0.08);
color: inherit;
cursor: pointer;
padding: 0;
}
.filter-clear {
border: 0;
background: none;
color: #64748b;
font: inherit;
font-size: 0.75rem;
text-decoration: underline;
cursor: pointer;
}
.tool.active {
border-color: #14b8a6;
color: #0f766e;
background: #f0fdfa;
}
.tool-count {
min-width: 1.05rem;
height: 1.05rem;
border-radius: 999px;
background: #14b8a6;
color: #fff;
font-size: 0.68rem;
display: inline-grid;
place-items: center;
padding: 0 0.2rem;
}
.tiny {
font-size: 0.72rem;
margin-top: 0.1rem;
}
.toolbar-tools {
display: flex;
gap: 0.3rem;
align-items: center;
flex-shrink: 0;
}
/* دسکتاپ: wrapper شفاف تا جستجو مثل قبل آیتم مستقیم flex بماند */
.search-row {
display: contents;
}
.search-filter {
flex-shrink: 0;
display: inline-flex;
align-items: center;
gap: 0.2rem;
height: 28px;
padding: 0 0.4rem;
margin-inline-end: -0.3rem;
border: 0;
border-radius: calc(var(--radius) - 2px);
background: transparent;
color: var(--ink-secondary);
cursor: pointer;
}
.search-filter.active {
color: #0f766e;
background: #f0fdfa;
}
.saved-slot {
/* فقط عرض؛ در ستون موبایل flex-basis نباید ارتفاع بسازد */
flex: 1 1 auto;
width: min(20rem, 100%);
min-width: 11rem;
max-width: 20rem;
margin-inline-start: auto;
height: auto;
min-height: 0;
overflow: visible;
}
.saved-slot :deep(.ant-space-compact) {
width: 100%;
max-height: var(--control-h, 36px);
}
.search {
flex: 1 1 12rem;
min-width: 10rem;
max-width: 22rem;
display: flex;
align-items: center;
gap: 0.35rem;
background: #fff;
border: 1px solid var(--line);
border-radius: var(--radius);
padding: 0 0.6rem;
min-height: var(--control-h);
height: var(--control-h);
color: var(--muted);
box-sizing: border-box;
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.search:focus-within {
border-color: var(--accent);
box-shadow: 0 0 0 2px var(--accent-soft);
}
.search input {
flex: 1;
min-width: 0;
border: 0;
outline: none;
background: transparent;
font: inherit;
font-size: var(--fs-sm);
color: var(--ink);
padding: 0;
}
.tool {
min-height: var(--control-h);
height: var(--control-h);
border: 1px solid var(--line);
background: #fff;
border-radius: var(--radius);
padding: 0 0.55rem;
box-sizing: border-box;
display: inline-flex;
align-items: center;
gap: 0.3rem;
font: inherit;
font-size: var(--fs-sm);
color: var(--ink-secondary);
cursor: pointer;
white-space: nowrap;
transition: background var(--transition-fast), border-color var(--transition-fast);
}
.tool:hover {
background: var(--surface-subtle);
border-color: var(--line-strong);
}
.pop {
position: relative;
}
.menu {
position: absolute;
inset-inline-start: 0;
top: calc(100% + 4px);
z-index: 8;
margin: 0;
padding: 0.25rem;
list-style: none;
background: #fff;
border-radius: var(--radius);
box-shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
min-width: min(12rem, calc(100vw - 2rem));
max-width: calc(100vw - 1.5rem);
}
.menu button,
.menu a {
width: 100%;
display: block;
border: 0;
background: none;
padding: 0.4rem 0.55rem;
border-radius: var(--radius);
font: inherit;
text-align: start;
color: inherit;
cursor: pointer;
}
.menu .on,
.menu button:hover,
.menu a:hover {
background: #f0fdfa;
color: #0f766e;
}
.ok {
margin: 0;
font-size: var(--fs-sm);
color: #0f766e;
}
.error {
margin: 0;
font-size: var(--fs-sm);
color: #b91c1c;
}
.table-wrap {
background: #fff;
border-radius: var(--radius);
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
overflow: auto;
-webkit-overflow-scrolling: touch;
}
.data-table {
width: 100%;
border-collapse: collapse;
min-width: 640px;
}
th,
td {
text-align: start;
padding: 0.35rem 0.5rem;
border-bottom: 1px solid #f1f5f9;
white-space: nowrap;
font-size: 0.8125rem;
line-height: 1.35;
}
th {
font-size: 0.72rem;
font-weight: 600;
color: #94a3b8;
background: #f8fafc;
padding-block: 0.4rem;
}
.status {
display: flex;
align-items: center;
gap: 0.4rem;
}
.status strong {
font-size: 0.8rem;
}
.check-col {
width: 2rem;
padding-inline: 0.5rem 0.2rem;
}
.check-col input {
width: 0.95rem;
height: 0.95rem;
margin: 0;
accent-color: #0d9488;
cursor: pointer;
}
.num-col {
width: 2.2rem;
color: #94a3b8;
font-size: 0.75rem;
font-variant-numeric: tabular-nums;
padding-inline: 0.2rem;
}
tr.picked td {
background: #f0fdfa;
}
.bulk-bar {
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
padding: 0.4rem 0.65rem;
border: 1px solid #99f6e4;
background: #f0fdfa;
border-radius: var(--radius);
font-size: var(--fs-sm);
color: #0f766e;
font-weight: 600;
}
.bulk-bar > :last-child {
margin-inline-start: auto;
}
.bulk-clear {
border: 0;
background: none;
padding: 0;
font: inherit;
font-size: var(--fs-xs);
color: #64748b;
text-decoration: underline;
cursor: pointer;
}
.name {
color: #0f766e;
font-weight: 600;
min-width: 0;
overflow-wrap: anywhere;
}
.mail {
display: inline-flex;
align-items: center;
gap: 0.3rem;
}
.ops {
position: relative;
}
.more {
border: 0;
background: none;
color: #94a3b8;
cursor: pointer;
display: grid;
place-items: center;
flex-shrink: 0;
width: 32px;
height: 32px;
border-radius: var(--radius);
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #22c55e;
flex-shrink: 0;
}
.dot.happy,
strong.happy {
color: #7c3aed;
}
.dot.happy {
background: #8b5cf6;
}
.dot.unhappy,
strong.unhappy {
color: #e11d48;
}
.dot.unhappy {
background: #fb7185;
}
.dot.special,
strong.special {
color: #d97706;
}
.dot.special {
background: #f59e0b;
}
.dot.newcomer,
strong.newcomer {
color: #0f766e;
}
.cards {
display: none;
gap: 0.5rem;
}
/* کارت موبایل: هدر (آواتار + نام + وضعیت) | منو، سپس ردیف تماس/منبع، سپس جزئیات اختیاری */
.m-card {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
grid-template-areas:
'main menu'
'meta meta'
'extra extra';
column-gap: 0.25rem;
background: #fff;
border: 1px solid #eef2f6;
border-radius: var(--radius);
padding: 0.55rem 0.6rem 0.5rem;
min-width: 0;
}
.m-card.no-menu {
grid-template-areas:
'main main'
'meta meta'
'extra extra';
}
.m-main {
grid-area: main;
display: flex;
align-items: center;
gap: 0.55rem;
min-width: 0;
color: inherit;
text-decoration: none;
}
.m-card > :deep(.ui-dd-anchor) {
grid-area: menu;
align-self: start;
margin-inline-end: -0.35rem;
margin-top: -0.2rem;
}
.m-id {
min-width: 0;
flex: 1 1 auto;
display: grid;
gap: 0.2rem;
}
.m-title {
display: flex;
align-items: center;
gap: 0.35rem;
min-width: 0;
}
.m-title .name {
min-width: 0;
font-size: 0.92rem;
line-height: 1.3;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.m-title .name.unnamed {
color: #94a3b8;
font-weight: 500;
}
.m-sub {
display: flex;
align-items: center;
gap: 0.35rem;
min-width: 0;
}
.m-sub-text {
min-width: 0;
font-size: 0.75rem;
color: #64748b;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.m-meta {
grid-area: meta;
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
margin-top: 0.5rem;
padding-top: 0.45rem;
border-top: 1px dashed #e2e8f0;
font-size: 0.78rem;
min-width: 0;
}
.m-phone {
display: inline-flex;
align-items: center;
gap: 0.3rem;
padding: 0.2rem 0.5rem;
border-radius: 999px;
background: #f0fdfa;
color: #0f766e;
font-weight: 600;
font-variant-numeric: tabular-nums;
text-decoration: none;
white-space: nowrap;
}
.m-src {
min-width: 0;
color: #64748b;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.m-muted {
color: #94a3b8;
}
.m-extra {
grid-area: extra;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.3rem 0.6rem;
margin-top: 0.4rem;
font-size: 0.75rem;
min-width: 0;
}
.m-line {
display: inline-flex;
align-items: center;
gap: 0.25rem;
min-width: 0;
max-width: 100%;
color: #64748b;
}
.m-line > span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.badge {
flex-shrink: 0;
border-radius: 999px;
padding: 0.05rem 0.45rem;
font-size: 0.68rem;
font-weight: 600;
line-height: 1.5;
white-space: nowrap;
}
.badge.newcomer {
background: #ecfdf5;
color: #0f766e;
}
.badge.happy {
background: #f3e8ff;
color: #7c3aed;
}
.badge.unhappy {
background: #ffe4e6;
color: #e11d48;
}
.badge.special {
background: #fef3c7;
color: #d97706;
}
.co-ico {
width: 36px;
height: 36px;
border-radius: 50%;
display: grid;
place-items: center;
background: #ecfdf5;
color: #0f766e;
flex-shrink: 0;
}
:deep(.ui-pagination) {
padding-top: 0.35rem;
}
@media (max-width: 900px) {
.page {
gap: 0.45rem;
}
.page-head {
flex-wrap: wrap;
align-items: stretch;
}
.head-start {
width: 100%;
flex-wrap: wrap;
}
.actions {
width: 100%;
flex-wrap: nowrap;
justify-content: flex-end;
gap: 0.35rem;
}
.actions-desktop {
display: none;
}
.actions-more {
display: inline-flex;
}
.tabs {
flex: 1 1 auto;
}
.tabs button {
flex: 1 1 auto;
justify-content: center;
}
.chrome {
flex-direction: column;
align-items: stretch;
gap: 0.35rem;
}
/* جستجو + گروه‌ها در یک ردیف، فاصله ۸px */
.search-row {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
}
.search {
flex: 1 1 auto;
width: auto;
min-width: 0;
max-width: none;
}
.groups-tool {
flex-shrink: 0;
}
.toolbar-tools {
width: 100%;
flex-wrap: nowrap;
}
.toolbar-tools .pop {
flex: 1 1 auto;
}
.toolbar-tools .tool {
width: 100%;
justify-content: center;
}
.saved-slot {
flex: 0 0 auto;
width: 100%;
max-width: none;
min-width: 0;
margin-inline-start: 0;
height: auto;
}
.table-wrap {
display: none;
}
.cards {
display: grid;
}
}
@media (max-width: 520px) {
.tool-label {
display: none;
}
.toolbar-tools .tool {
width: auto;
flex: 1 1 auto;
min-width: 44px;
justify-content: center;
padding-inline: 0.5rem;
}
}
</style>