2026-09-09 13:12:13 +03:30
|
|
|
|
<script setup lang="ts">
|
2026-10-17 13:26:11 +03:30
|
|
|
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
2026-10-18 19:39:59 +03:30
|
|
|
|
import {
|
|
|
|
|
|
CalendarOutlined,
|
|
|
|
|
|
CheckOutlined,
|
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
|
MoreOutlined,
|
|
|
|
|
|
} from '@ant-design/icons-vue';
|
|
|
|
|
|
import {
|
|
|
|
|
|
Avatar as AAvatar,
|
|
|
|
|
|
Button as AButton,
|
|
|
|
|
|
Card as ACard,
|
|
|
|
|
|
Empty as AEmpty,
|
|
|
|
|
|
Flex as AFlex,
|
|
|
|
|
|
Space as ASpace,
|
|
|
|
|
|
Table as ATable,
|
|
|
|
|
|
Tag as ATag,
|
2026-11-12 16:27:32 +03:30
|
|
|
|
Tooltip as ATooltip,
|
2026-10-18 19:39:59 +03:30
|
|
|
|
Typography,
|
|
|
|
|
|
theme,
|
|
|
|
|
|
} from 'ant-design-vue';
|
|
|
|
|
|
import type { TableColumnsType } from 'ant-design-vue';
|
2026-10-05 11:56:49 +03:30
|
|
|
|
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
|
2026-11-12 16:27:32 +03:30
|
|
|
|
import { formatJalaliNumeric } from '@/lib/jalali';
|
2026-10-18 19:39:59 +03:30
|
|
|
|
import type {
|
|
|
|
|
|
PipelineAccent,
|
|
|
|
|
|
PipelineDeal,
|
|
|
|
|
|
PipelineStage,
|
|
|
|
|
|
PipelineUiCopy,
|
|
|
|
|
|
} from '@/lib/pipeline-board';
|
2026-09-09 13:12:13 +03:30
|
|
|
|
import {
|
2026-09-15 19:13:30 +03:30
|
|
|
|
DEAL_BOARD_COPY,
|
2026-09-09 13:12:13 +03:30
|
|
|
|
formatCurrencyParts,
|
|
|
|
|
|
PIPELINE_ACCENT,
|
|
|
|
|
|
} from '@/lib/pipeline-board';
|
|
|
|
|
|
|
2026-09-15 19:13:30 +03:30
|
|
|
|
const props = withDefaults(
|
|
|
|
|
|
defineProps<{
|
|
|
|
|
|
stages: PipelineStage[];
|
|
|
|
|
|
copy?: PipelineUiCopy;
|
2026-10-12 17:59:07 +03:30
|
|
|
|
selectMode?: boolean;
|
|
|
|
|
|
selectedIds?: Set<string>;
|
2026-09-15 19:13:30 +03:30
|
|
|
|
}>(),
|
2026-10-12 17:59:07 +03:30
|
|
|
|
{ copy: () => DEAL_BOARD_COPY, selectedIds: () => new Set() },
|
2026-09-15 19:13:30 +03:30
|
|
|
|
);
|
2026-09-09 13:12:13 +03:30
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
openDeal: [dealId: string];
|
|
|
|
|
|
menuDeal: [dealId: string];
|
2026-10-12 17:59:07 +03:30
|
|
|
|
toggleSelect: [dealId: string];
|
|
|
|
|
|
bulkDelete: [];
|
2026-09-09 13:12:13 +03:30
|
|
|
|
}>();
|
|
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
|
const { Text: ATypographyText } = Typography;
|
|
|
|
|
|
const { token } = theme.useToken();
|
|
|
|
|
|
|
2026-10-17 13:26:11 +03:30
|
|
|
|
const listRoot = ref<HTMLElement | null>(null);
|
|
|
|
|
|
const useCards = ref(false);
|
|
|
|
|
|
let resizeObs: ResizeObserver | null = null;
|
|
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
|
type Row = {
|
|
|
|
|
|
key: string;
|
|
|
|
|
|
deal: PipelineDeal;
|
|
|
|
|
|
stageTitle: string;
|
|
|
|
|
|
accent: PipelineAccent;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function accentColors(accent: PipelineAccent) {
|
|
|
|
|
|
return PIPELINE_ACCENT[accent];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const rows = computed<Row[]>(() =>
|
2026-09-09 13:12:13 +03:30
|
|
|
|
props.stages.flatMap((stage) =>
|
|
|
|
|
|
stage.deals.map((deal) => ({
|
2026-10-18 19:39:59 +03:30
|
|
|
|
key: deal.id,
|
2026-09-09 13:12:13 +03:30
|
|
|
|
deal,
|
|
|
|
|
|
stageTitle: stage.title,
|
|
|
|
|
|
accent: stage.color,
|
|
|
|
|
|
})),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
function money(deal: PipelineDeal) {
|
2026-10-13 14:45:29 +03:30
|
|
|
|
return formatCurrencyParts(deal.amount ?? 0, deal.currencyUnit ?? 'ریال');
|
2026-09-09 13:12:13 +03:30
|
|
|
|
}
|
2026-09-15 19:13:30 +03:30
|
|
|
|
|
2026-11-12 16:27:32 +03:30
|
|
|
|
function dateHint(deal: PipelineDeal) {
|
|
|
|
|
|
if (!deal.dateIso) return deal.date;
|
|
|
|
|
|
const d = new Date(deal.dateIso);
|
|
|
|
|
|
if (Number.isNaN(d.getTime())) return deal.date;
|
|
|
|
|
|
return formatJalaliNumeric(d);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-15 19:13:30 +03:30
|
|
|
|
const hideAmount = computed(() => Boolean(props.copy.hideAmount));
|
2026-10-05 11:56:49 +03:30
|
|
|
|
const tableKey = computed(() => (hideAmount.value ? 'pipeline.leads' : 'pipeline.deals'));
|
2026-10-17 13:26:11 +03:30
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
|
const columns = computed<TableColumnsType<Row>>(() => {
|
|
|
|
|
|
const cols: TableColumnsType<Row> = [];
|
|
|
|
|
|
if (props.selectMode) {
|
|
|
|
|
|
cols.push({ key: 'select', title: '', width: 56 });
|
|
|
|
|
|
}
|
|
|
|
|
|
cols.push(
|
|
|
|
|
|
{ key: 'title', title: props.copy.listColTitle },
|
|
|
|
|
|
{ key: 'stage', title: 'مرحله' },
|
|
|
|
|
|
);
|
|
|
|
|
|
if (!hideAmount.value) {
|
|
|
|
|
|
cols.push({ key: 'amount', title: 'مبلغ' });
|
|
|
|
|
|
}
|
|
|
|
|
|
cols.push(
|
|
|
|
|
|
{ key: 'date', title: 'تاریخ' },
|
|
|
|
|
|
{ key: 'actions', title: 'عملیات', width: 72, align: 'center' },
|
|
|
|
|
|
);
|
|
|
|
|
|
return cols;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function customRow(record: Row) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
if (props.selectMode) emit('toggleSelect', record.deal.id);
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-17 13:26:11 +03:30
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
const el = listRoot.value;
|
|
|
|
|
|
if (!el || typeof ResizeObserver === 'undefined') return;
|
|
|
|
|
|
resizeObs = new ResizeObserver((entries) => {
|
|
|
|
|
|
const width = entries[0]?.contentRect.width ?? el.clientWidth;
|
|
|
|
|
|
useCards.value = width <= 720;
|
|
|
|
|
|
});
|
|
|
|
|
|
resizeObs.observe(el);
|
|
|
|
|
|
useCards.value = el.clientWidth <= 720;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
resizeObs?.disconnect();
|
|
|
|
|
|
resizeObs = null;
|
|
|
|
|
|
});
|
2026-09-09 13:12:13 +03:30
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
<div ref="listRoot" dir="rtl" :style="{ minWidth: 0 }">
|
|
|
|
|
|
<a-empty v-if="!rows.length" :description="copy.empty" />
|
2026-09-09 13:12:13 +03:30
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
|
<template v-else-if="!useCards">
|
|
|
|
|
|
<a-flex justify="flex-end" :style="{ marginBottom: '8px' }">
|
|
|
|
|
|
<TableColumnsMenu :table-key="tableKey" align="end" />
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
<a-table
|
|
|
|
|
|
:columns="columns"
|
|
|
|
|
|
:data-source="rows"
|
|
|
|
|
|
:pagination="false"
|
|
|
|
|
|
row-key="key"
|
|
|
|
|
|
:custom-row="customRow"
|
|
|
|
|
|
:row-class-name="(record: Row) => (selectedIds.has(record.deal.id) ? 'pipeline-row-selected' : '')"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #bodyCell="{ column, record }">
|
|
|
|
|
|
<template v-if="column.key === 'select'">
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
shape="circle"
|
|
|
|
|
|
:aria-label="selectedIds.has(record.deal.id) ? 'لغو انتخاب' : 'انتخاب معامله'"
|
|
|
|
|
|
@click.stop="emit('toggleSelect', record.deal.id)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #icon>
|
|
|
|
|
|
<CheckOutlined v-if="selectedIds.has(record.deal.id)" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'title'">
|
|
|
|
|
|
<a-flex
|
|
|
|
|
|
:gap="10"
|
|
|
|
|
|
align="center"
|
|
|
|
|
|
:style="{ minWidth: 0, cursor: 'pointer' }"
|
|
|
|
|
|
@click.stop="
|
|
|
|
|
|
selectMode
|
|
|
|
|
|
? emit('toggleSelect', record.deal.id)
|
|
|
|
|
|
: emit('openDeal', record.deal.id)
|
|
|
|
|
|
"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-avatar
|
2026-09-09 13:12:13 +03:30
|
|
|
|
:style="{
|
2026-10-18 19:39:59 +03:30
|
|
|
|
background: accentColors(record.accent).soft,
|
|
|
|
|
|
color: accentColors(record.accent).text,
|
|
|
|
|
|
flexShrink: 0,
|
2026-09-09 13:12:13 +03:30
|
|
|
|
}"
|
|
|
|
|
|
>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
{{ record.deal.initials }}
|
|
|
|
|
|
</a-avatar>
|
|
|
|
|
|
<div :style="{ minWidth: 0 }">
|
|
|
|
|
|
<a-typography-text strong ellipsis :style="{ display: 'block', margin: 0 }">
|
|
|
|
|
|
{{ record.deal.title }}
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
<a-typography-text
|
|
|
|
|
|
v-if="record.deal.description"
|
|
|
|
|
|
type="secondary"
|
|
|
|
|
|
ellipsis
|
|
|
|
|
|
:style="{ display: 'block', margin: 0, fontSize: `${token.fontSizeSM}px` }"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ record.deal.description }}
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'stage'">
|
|
|
|
|
|
<a-tag
|
|
|
|
|
|
:bordered="false"
|
|
|
|
|
|
:style="{
|
|
|
|
|
|
background: accentColors(record.accent).soft,
|
|
|
|
|
|
color: accentColors(record.accent).text,
|
|
|
|
|
|
}"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ record.stageTitle }}
|
|
|
|
|
|
</a-tag>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'amount'">
|
|
|
|
|
|
<span dir="ltr">
|
|
|
|
|
|
<a-typography-text strong>{{ money(record.deal).number }}</a-typography-text>
|
|
|
|
|
|
<a-typography-text type="secondary" :style="{ marginInlineStart: '6px' }">
|
|
|
|
|
|
{{ money(record.deal).unit }}
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'date'">
|
2026-11-12 16:27:32 +03:30
|
|
|
|
<a-tooltip :title="dateHint(record.deal)">
|
|
|
|
|
|
<a-space :size="6">
|
|
|
|
|
|
<CalendarOutlined />
|
|
|
|
|
|
<span>{{ record.deal.date }}</span>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
</a-tooltip>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="column.key === 'actions'">
|
2026-10-19 11:40:25 +03:30
|
|
|
|
<span :data-card-id="record.deal.id">
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="selectMode && selectedIds.has(record.deal.id)"
|
|
|
|
|
|
class="menu"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
danger
|
|
|
|
|
|
aria-label="حذف انتخابشدهها"
|
|
|
|
|
|
@click.stop="emit('bulkDelete')"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #icon><DeleteOutlined /></template>
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-else
|
|
|
|
|
|
class="menu"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
:aria-label="copy.itemMenuAria"
|
|
|
|
|
|
@click.stop="emit('menuDeal', record.deal.id)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #icon><MoreOutlined /></template>
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</span>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
</template>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-table>
|
|
|
|
|
|
</template>
|
2026-09-09 13:12:13 +03:30
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
|
<a-flex v-else vertical :gap="12">
|
|
|
|
|
|
<a-card
|
2026-09-09 13:12:13 +03:30
|
|
|
|
v-for="row in rows"
|
|
|
|
|
|
:key="row.deal.id"
|
2026-10-18 19:39:59 +03:30
|
|
|
|
hoverable
|
2026-10-12 17:59:07 +03:30
|
|
|
|
:data-card-id="row.deal.id"
|
2026-10-18 19:39:59 +03:30
|
|
|
|
:body-style="{ padding: '14px 16px' }"
|
|
|
|
|
|
:style="{
|
|
|
|
|
|
background: selectedIds.has(row.deal.id)
|
|
|
|
|
|
? token.colorPrimaryBg
|
|
|
|
|
|
: token.colorBgContainer,
|
|
|
|
|
|
borderColor: selectedIds.has(row.deal.id)
|
|
|
|
|
|
? token.colorPrimary
|
|
|
|
|
|
: token.colorBorderSecondary,
|
|
|
|
|
|
}"
|
2026-10-12 17:59:07 +03:30
|
|
|
|
@dblclick="!selectMode && emit('openDeal', row.deal.id)"
|
|
|
|
|
|
@click="selectMode && emit('toggleSelect', row.deal.id)"
|
2026-09-09 13:12:13 +03:30
|
|
|
|
>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
<a-flex vertical :gap="12">
|
|
|
|
|
|
<a-flex align="center" :gap="10" :style="{ minWidth: 0 }">
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="selectMode"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
shape="circle"
|
|
|
|
|
|
@click.stop="emit('toggleSelect', row.deal.id)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #icon>
|
|
|
|
|
|
<CheckOutlined v-if="selectedIds.has(row.deal.id)" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-avatar
|
2026-10-12 17:59:07 +03:30
|
|
|
|
:style="{
|
2026-10-18 19:39:59 +03:30
|
|
|
|
background: accentColors(row.accent).soft,
|
|
|
|
|
|
color: accentColors(row.accent).text,
|
2026-10-12 17:59:07 +03:30
|
|
|
|
}"
|
2026-10-18 19:39:59 +03:30
|
|
|
|
>
|
|
|
|
|
|
{{ row.deal.initials }}
|
|
|
|
|
|
</a-avatar>
|
|
|
|
|
|
<div
|
|
|
|
|
|
:style="{ flex: 1, minWidth: 0, cursor: 'pointer' }"
|
|
|
|
|
|
@click.stop="
|
|
|
|
|
|
selectMode
|
|
|
|
|
|
? emit('toggleSelect', row.deal.id)
|
|
|
|
|
|
: emit('openDeal', row.deal.id)
|
|
|
|
|
|
"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-typography-text strong ellipsis :style="{ display: 'block', margin: 0 }">
|
|
|
|
|
|
{{ row.deal.title }}
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
<a-typography-text
|
|
|
|
|
|
v-if="row.deal.description"
|
|
|
|
|
|
type="secondary"
|
|
|
|
|
|
ellipsis
|
|
|
|
|
|
:style="{ display: 'block', margin: 0 }"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ row.deal.description }}
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</div>
|
2026-10-19 11:40:25 +03:30
|
|
|
|
<span :data-card-id="row.deal.id">
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="selectMode && selectedIds.has(row.deal.id)"
|
|
|
|
|
|
class="menu"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
danger
|
|
|
|
|
|
@click.stop="emit('bulkDelete')"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #icon><DeleteOutlined /></template>
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-else
|
|
|
|
|
|
class="menu"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
@click.stop="emit('menuDeal', row.deal.id)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #icon><MoreOutlined /></template>
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</span>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
</a-flex>
|
|
|
|
|
|
<a-tag
|
|
|
|
|
|
:bordered="false"
|
|
|
|
|
|
:style="{
|
|
|
|
|
|
alignSelf: 'flex-start',
|
|
|
|
|
|
background: accentColors(row.accent).soft,
|
|
|
|
|
|
color: accentColors(row.accent).text,
|
|
|
|
|
|
}"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ row.stageTitle }}
|
|
|
|
|
|
</a-tag>
|
|
|
|
|
|
<a-flex justify="space-between" align="center">
|
2026-11-12 16:27:32 +03:30
|
|
|
|
<a-tooltip :title="dateHint(row.deal)">
|
|
|
|
|
|
<a-space :size="6">
|
|
|
|
|
|
<CalendarOutlined />
|
|
|
|
|
|
<a-typography-text type="secondary">{{ row.deal.date }}</a-typography-text>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
</a-tooltip>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
<span v-if="!hideAmount" dir="ltr">
|
|
|
|
|
|
<a-typography-text strong>{{ money(row.deal).number }}</a-typography-text>
|
|
|
|
|
|
<a-typography-text type="secondary" :style="{ marginInlineStart: '6px' }">
|
|
|
|
|
|
{{ money(row.deal).unit }}
|
|
|
|
|
|
</a-typography-text>
|
2026-10-12 17:59:07 +03:30
|
|
|
|
</span>
|
2026-10-18 19:39:59 +03:30
|
|
|
|
</a-flex>
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-flex>
|
2026-09-09 13:12:13 +03:30
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|