186 lines
4.3 KiB
Vue
186 lines
4.3 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from 'vue';
|
|
import { RouterLink } from 'vue-router';
|
|
import { toFaDigits } from '@/lib/jalali';
|
|
import type { PipelineBoardDto } from '@mento/shared';
|
|
import HomePanelEmpty from '@/components/dashboard/HomePanelEmpty.vue';
|
|
|
|
const props = defineProps<{
|
|
board: PipelineBoardDto | null;
|
|
formatMoney: (amount: number, currency: string) => string;
|
|
}>();
|
|
|
|
type Card = { id: string; name: string; amount: string; when: string };
|
|
type Col = { id: string; name: string; count: number; cards: Card[] };
|
|
|
|
function relativeWhen(iso: string | null | undefined) {
|
|
if (!iso) return '';
|
|
const diff = Date.now() - new Date(iso).getTime();
|
|
const days = Math.floor(diff / 86400000);
|
|
if (days <= 0) return 'امروز';
|
|
if (days === 1) return 'دیروز';
|
|
return `${toFaDigits(days)} روز پیش`;
|
|
}
|
|
|
|
const cols = computed<Col[]>(() => {
|
|
const stages = props.board?.stages ?? [];
|
|
const hasDeals = stages.some((s) => s.deals.length);
|
|
if (!hasDeals) return [];
|
|
return stages.slice(0, 3).map((stage) => ({
|
|
id: stage.id,
|
|
name: stage.name,
|
|
count: stage.deals.length,
|
|
cards: stage.deals.slice(0, 2).map((deal) => ({
|
|
id: deal.id,
|
|
name: deal.company?.name || deal.person?.fullName || deal.title,
|
|
amount: deal.amount ? props.formatMoney(deal.amount, deal.currency) : '',
|
|
when: relativeWhen(deal.updatedAt || deal.createdAt),
|
|
})),
|
|
}));
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<article class="panel">
|
|
<header class="panel-head">
|
|
<h2>جریان فروش</h2>
|
|
<RouterLink :to="{ name: 'pipeline' }">نمایش همه</RouterLink>
|
|
</header>
|
|
|
|
<HomePanelEmpty
|
|
v-if="!cols.length"
|
|
title="هنوز معاملهای در مسیر فروش نیست"
|
|
description="اولین معامله را بسازید تا جریان فروش اینجا دیده شود."
|
|
action-label="معامله جدید"
|
|
:action-to="{ name: 'deal-new' }"
|
|
/>
|
|
<div v-else class="mini-pipeline">
|
|
<div v-for="col in cols" :key="col.id" class="pipe-col">
|
|
<header>
|
|
<strong>{{ col.name }} ({{ toFaDigits(col.count) }})</strong>
|
|
</header>
|
|
<div class="pipe-cards">
|
|
<RouterLink
|
|
v-for="card in col.cards"
|
|
:key="card.id"
|
|
class="pipe-card"
|
|
:to="{ name: 'deal-detail', params: { id: card.id } }"
|
|
>
|
|
<span class="deal-mark">{{ card.name.slice(0, 1) }}</span>
|
|
<div>
|
|
<strong>{{ card.name }}</strong>
|
|
<span v-if="card.amount">{{ card.amount }}</span>
|
|
<em>{{ card.when }}</em>
|
|
</div>
|
|
</RouterLink>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</article>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.panel {
|
|
background: #fff;
|
|
border-radius: var(--radius);
|
|
padding: 1rem 1.05rem;
|
|
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
|
|
border: 1px solid #eef2f7;
|
|
min-width: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.panel-head {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 0.75rem;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
h2 {
|
|
margin: 0;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
a {
|
|
color: #14b8a6;
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.mini-pipeline {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, minmax(120px, 1fr));
|
|
gap: 0.65rem;
|
|
overflow-x: auto;
|
|
}
|
|
|
|
.pipe-col > header {
|
|
margin-bottom: 0.5rem;
|
|
font-size: 0.78rem;
|
|
color: #64748b;
|
|
}
|
|
|
|
.pipe-cards {
|
|
display: grid;
|
|
gap: 0.4rem;
|
|
}
|
|
|
|
.pipe-card {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
padding: 0.55rem 0.6rem;
|
|
border-radius: var(--radius);
|
|
background: #f8fafc;
|
|
border: 1px solid #eef2f7;
|
|
color: inherit;
|
|
font-size: 0.78rem;
|
|
}
|
|
|
|
.pipe-card div {
|
|
display: grid;
|
|
gap: 0.1rem;
|
|
min-width: 0;
|
|
}
|
|
|
|
.pipe-card strong {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
font-size: 0.78rem;
|
|
}
|
|
|
|
.pipe-card span {
|
|
color: #94a3b8;
|
|
font-size: 0.68rem;
|
|
}
|
|
|
|
.pipe-card em {
|
|
color: #cbd5e1;
|
|
font-size: 0.66rem;
|
|
font-style: normal;
|
|
}
|
|
|
|
.deal-mark {
|
|
width: 28px;
|
|
height: 28px;
|
|
border-radius: var(--radius);
|
|
background: #ecfdf8;
|
|
color: #0f766e;
|
|
display: grid;
|
|
place-items: center;
|
|
font-weight: 600;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
@media (max-width: 700px) {
|
|
.mini-pipeline {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|