From 5c866e9b7555da3681888f8980e1060b734a90fa Mon Sep 17 00:00:00 2001 From: Mahdi Date: Wed, 18 Nov 2026 19:47:17 +0330 Subject: [PATCH] Improve Leads list filters and mobile toolbar layout. Co-authored-by: Cursor --- apps/web/src/views/LeadsView.vue | 795 ++++++++++++++++--------------- 1 file changed, 422 insertions(+), 373 deletions(-) diff --git a/apps/web/src/views/LeadsView.vue b/apps/web/src/views/LeadsView.vue index de33092..aeda5dc 100644 --- a/apps/web/src/views/LeadsView.vue +++ b/apps/web/src/views/LeadsView.vue @@ -114,54 +114,13 @@ const FOLLOW_UP_OPTIONS: Array<{ value: FollowUpKey; label: string }> = [ ]; const UNASSIGNED_VALUE = '__unassigned__'; -/** ردیف آمار صفحه لیدها — ترتیب و نام‌ها مطابق طرح */ -const LEAD_STAT_DEFS: Array<{ - label: string; - /** نام وضعیت‌های متناظر در دیتابیس */ - match: string[]; - tint: StageTint; - slot: 'pair' | 'solo'; -}> = [ - { - label: 'جدید', - match: ['جدید'], - tint: 'amber', - slot: 'pair', - }, - { - label: 'در حال پیگیری', - match: ['در حال پیگیری', 'پیگیری مجدد', 'تماس اولیه', 'تماس موفق'], - tint: 'peach', - slot: 'pair', - }, - { - label: 'مذاکره', - match: ['مذاکره'], - tint: 'mint', - slot: 'solo', - }, - { - label: 'آماده خرید', - match: ['آماده خرید'], - tint: 'violet', - slot: 'solo', - }, - { - label: 'عدم پاسخ', - match: ['عدم پاسخ'], - tint: 'rose', - slot: 'solo', - }, -]; - type LeadStatCard = { key: string; label: string; tint: StageTint; count: number; - /** مرحله اصلی برای فیلتر */ + /** شناسهٔ واقعی ستون برای فیلتر */ stageId: string; - slot: 'pair' | 'solo'; }; const route = useRoute(); @@ -342,11 +301,12 @@ function toggleFilterSection(name: NonNullable) { const filterAnchor = ref(null); const filterPopoverMaxHeight = ref('min(70vh, 32rem)'); +const filterPanelPos = ref({ top: 0, inlineEnd: 8 }); const filterPanelStyle = computed(() => ({ - position: 'absolute' as const, - top: 'calc(100% + 6px)', - insetInlineStart: '0', + position: 'fixed' as const, + top: `${filterPanelPos.value.top}px`, + insetInlineEnd: `${filterPanelPos.value.inlineEnd}px`, zIndex: 1050, width: 'min(20rem, calc(100vw - 1.5rem))', maxHeight: filterPopoverMaxHeight.value, @@ -360,13 +320,19 @@ const filterPanelStyle = computed(() => ({ function placeFilterPopover() { const el = filterAnchor.value; if (!el) return; - const space = Math.floor(window.innerHeight - el.getBoundingClientRect().bottom - 12); + const rect = el.getBoundingClientRect(); + const space = Math.floor(window.innerHeight - rect.bottom - 12); filterPopoverMaxHeight.value = `${Math.max(220, space)}px`; + filterPanelPos.value = { + top: rect.bottom + 6, + inlineEnd: Math.max(8, Math.round(window.innerWidth - rect.right)), + }; } function onFilterDocPointer(event: Event) { const target = event.target; if (!(target instanceof Node)) return; + if (target instanceof Element && target.closest('[data-lead-filter]')) return; if (filterAnchor.value?.contains(target)) return; if (document.getElementById('jalali-picker')?.contains(target)) return; moreFiltersOpen.value = false; @@ -556,23 +522,15 @@ const sortLabels: Record = { last_contact: 'آخرین تماس', }; +/** چیپ‌های فیلتر = ستون‌های واقعی سازمان (نه نام‌های ثابت قدیمی) */ const stageCards = computed((): LeadStatCard[] => { - return LEAD_STAT_DEFS.map((def) => { - const matched = stages.value.filter((s) => - def.match.some((name) => s.name.trim() === name), - ); - const count = matched.reduce((sum, s) => sum + (s.leadCount ?? 0), 0); - const primary = - matched.find((s) => s.name.trim() === def.match[0]) ?? matched[0]; - return { - key: def.label, - label: def.label, - tint: def.tint, - count, - stageId: primary?.id ?? '', - slot: def.slot, - }; - }); + return stages.value.map((s) => ({ + key: s.id, + label: s.name, + tint: stageTint(s.color), + count: s.leadCount ?? 0, + stageId: s.id, + })); }); const totalLeadsCount = computed(() => { @@ -580,22 +538,24 @@ const totalLeadsCount = computed(() => { return stages.value.reduce((sum, s) => sum + (s.leadCount ?? 0), 0) || total.value; }); +/** گزینه‌های سلکت موبایل — برچسب + تعداد */ +const stageFilterOptions = computed(() => [ + { + value: '', + label: `همه لیدها (${formatCount(totalLeadsCount.value)})`, + }, + ...stageCards.value.map((card) => ({ + value: card.stageId, + label: `${card.label} (${formatCount(card.count)})`, + })), +]); + function isStatActive(card: LeadStatCard) { - if (!card.stageId || !stageId.value) return false; - if (stageId.value === card.stageId) return true; - const def = LEAD_STAT_DEFS.find((d) => d.label === card.label); - if (!def) return false; - const matchedIds = stages.value - .filter((s) => def.match.some((name) => s.name.trim() === name)) - .map((s) => s.id); - return matchedIds.includes(stageId.value); + return Boolean(card.stageId && stageId.value === card.stageId); } function selectStatCard(card: LeadStatCard) { - if (!card.stageId) { - setStageFilter(''); - return; - } + if (!card.stageId) return; setStageFilter(isStatActive(card) ? '' : card.stageId); } @@ -1586,14 +1546,36 @@ onBeforeUnmount(() => {