Files
CRM_Montzar/apps/web/src/components/pipeline/PipelineList.vue
T

353 lines
11 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue';
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,
Typography,
theme,
} from 'ant-design-vue';
import type { TableColumnsType } from 'ant-design-vue';
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
import type {
PipelineAccent,
PipelineDeal,
PipelineStage,
PipelineUiCopy,
} from '@/lib/pipeline-board';
import {
2026-09-15 19:13:30 +03:30
DEAL_BOARD_COPY,
formatCurrencyParts,
PIPELINE_ACCENT,
} from '@/lib/pipeline-board';
2026-09-15 19:13:30 +03:30
const props = withDefaults(
defineProps<{
stages: PipelineStage[];
copy?: PipelineUiCopy;
selectMode?: boolean;
selectedIds?: Set<string>;
2026-09-15 19:13:30 +03:30
}>(),
{ copy: () => DEAL_BOARD_COPY, selectedIds: () => new Set() },
2026-09-15 19:13:30 +03:30
);
const emit = defineEmits<{
openDeal: [dealId: string];
menuDeal: [dealId: string];
toggleSelect: [dealId: string];
bulkDelete: [];
}>();
const { Text: ATypographyText } = Typography;
const { token } = theme.useToken();
const listRoot = ref<HTMLElement | null>(null);
const useCards = ref(false);
let resizeObs: ResizeObserver | null = null;
type Row = {
key: string;
deal: PipelineDeal;
stageTitle: string;
accent: PipelineAccent;
};
function accentColors(accent: PipelineAccent) {
return PIPELINE_ACCENT[accent];
}
const rows = computed<Row[]>(() =>
props.stages.flatMap((stage) =>
stage.deals.map((deal) => ({
key: deal.id,
deal,
stageTitle: stage.title,
accent: stage.color,
})),
),
);
function money(deal: PipelineDeal) {
return formatCurrencyParts(deal.amount ?? 0, deal.currencyUnit ?? 'ریال');
}
2026-09-15 19:13:30 +03:30
const hideAmount = computed(() => Boolean(props.copy.hideAmount));
const tableKey = computed(() => (hideAmount.value ? 'pipeline.leads' : 'pipeline.deals'));
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);
},
};
}
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;
});
</script>
<template>
<div ref="listRoot" dir="rtl" :style="{ minWidth: 0 }">
<a-empty v-if="!rows.length" :description="copy.empty" />
<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
:style="{
background: accentColors(record.accent).soft,
color: accentColors(record.accent).text,
flexShrink: 0,
}"
>
{{ 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'">
<a-space :size="6">
<CalendarOutlined />
<span>{{ record.deal.date }}</span>
</a-space>
</template>
<template v-else-if="column.key === 'actions'">
<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>
</template>
</template>
</a-table>
</template>
<a-flex v-else vertical :gap="12">
<a-card
v-for="row in rows"
:key="row.deal.id"
hoverable
:data-card-id="row.deal.id"
: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,
}"
@dblclick="!selectMode && emit('openDeal', row.deal.id)"
@click="selectMode && emit('toggleSelect', row.deal.id)"
>
<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
:style="{
background: accentColors(row.accent).soft,
color: accentColors(row.accent).text,
}"
>
{{ 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>
<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>
</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">
<a-space :size="6">
<CalendarOutlined />
<a-typography-text type="secondary">{{ row.deal.date }}</a-typography-text>
</a-space>
<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>
</span>
</a-flex>
</a-flex>
</a-card>
</a-flex>
</div>
</template>