2026-10-12 20:55:14 +03:30
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { computed, ref, watch } from 'vue';
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
import type {
|
|
|
|
|
|
MergePipelineRequest,
|
|
|
|
|
|
MergePipelineResultDto,
|
|
|
|
|
|
PipelineMergePreviewDto,
|
|
|
|
|
|
PipelineMergePreviewStageDto,
|
|
|
|
|
|
} from '@mento/shared';
|
|
|
|
|
|
import { api } from '@/lib/api';
|
|
|
|
|
|
import { toFaDigits } from '@/lib/jalali';
|
2026-11-04 10:01:11 +03:30
|
|
|
|
import {
|
|
|
|
|
|
Alert as AAlert,
|
|
|
|
|
|
Button as AButton,
|
|
|
|
|
|
Card as ACard,
|
|
|
|
|
|
Col as ACol,
|
|
|
|
|
|
Descriptions as ADescriptions,
|
|
|
|
|
|
DescriptionsItem as ADescriptionsItem,
|
|
|
|
|
|
Flex as AFlex,
|
|
|
|
|
|
Form as AForm,
|
|
|
|
|
|
FormItem as AFormItem,
|
|
|
|
|
|
Row as ARow,
|
|
|
|
|
|
Select as ASelect,
|
|
|
|
|
|
Space as ASpace,
|
|
|
|
|
|
Spin as ASpin,
|
|
|
|
|
|
Steps as ASteps,
|
|
|
|
|
|
Step as AStep,
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
} from 'ant-design-vue';
|
|
|
|
|
|
import {
|
|
|
|
|
|
AppstoreOutlined,
|
|
|
|
|
|
AimOutlined,
|
|
|
|
|
|
CheckCircleOutlined,
|
2026-11-05 14:46:35 +03:30
|
|
|
|
} from '@/icons/ant-bridge';
|
2026-11-04 10:01:11 +03:30
|
|
|
|
|
|
|
|
|
|
const { Title: ATypographyTitle, Text: ATypographyText, Paragraph: ATypographyParagraph } = Typography;
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
|
|
|
|
|
type Step = 'target' | 'map' | 'review';
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
open: boolean;
|
|
|
|
|
|
sourceId: string | null;
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
close: [];
|
|
|
|
|
|
done: [];
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const step = ref<Step>('target');
|
|
|
|
|
|
const targetId = ref('');
|
|
|
|
|
|
const preview = ref<PipelineMergePreviewDto | null>(null);
|
|
|
|
|
|
const stageMap = ref<Record<string, string>>({});
|
|
|
|
|
|
const busy = ref(false);
|
|
|
|
|
|
const error = ref('');
|
|
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
const stepIndex = computed(() => {
|
|
|
|
|
|
if (step.value === 'target') return 0;
|
|
|
|
|
|
if (step.value === 'map') return 1;
|
|
|
|
|
|
return 2;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-12 20:55:14 +03:30
|
|
|
|
const selectedTarget = computed(
|
|
|
|
|
|
() => preview.value?.targets.find((target) => target.id === targetId.value) ?? null,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
const targetOptions = computed(() =>
|
|
|
|
|
|
(preview.value?.targets ?? []).map((target) => ({
|
|
|
|
|
|
value: target.id,
|
|
|
|
|
|
label: target.name,
|
|
|
|
|
|
})),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-10-12 20:55:14 +03:30
|
|
|
|
const canContinueTarget = computed(() => Boolean(targetId.value && selectedTarget.value));
|
|
|
|
|
|
const canContinueMap = computed(() => {
|
|
|
|
|
|
const current = preview.value;
|
|
|
|
|
|
if (!current) return false;
|
|
|
|
|
|
return current.stages.every((stage) => Boolean(stageMap.value[stage.id]));
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function apiError(e: unknown, fallback: string) {
|
|
|
|
|
|
if (axios.isAxiosError(e)) {
|
|
|
|
|
|
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
|
|
|
|
|
if (Array.isArray(msg)) return msg.join('، ');
|
|
|
|
|
|
if (msg) return msg;
|
|
|
|
|
|
if (!e.response) return 'اتصال به API برقرار نشد.';
|
|
|
|
|
|
}
|
|
|
|
|
|
return fallback;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resetState() {
|
|
|
|
|
|
step.value = 'target';
|
|
|
|
|
|
targetId.value = '';
|
|
|
|
|
|
preview.value = null;
|
|
|
|
|
|
stageMap.value = {};
|
|
|
|
|
|
busy.value = false;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function compatibleTargets(src: PipelineMergePreviewStageDto) {
|
|
|
|
|
|
const target = selectedTarget.value;
|
|
|
|
|
|
if (!target) return [];
|
|
|
|
|
|
return target.stages.filter((stage) => {
|
|
|
|
|
|
if (src.isWon) return stage.isWon;
|
|
|
|
|
|
if (src.isLost) return stage.isLost;
|
|
|
|
|
|
return !stage.isWon && !stage.isLost;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
function compatibleOptions(src: PipelineMergePreviewStageDto) {
|
|
|
|
|
|
return compatibleTargets(src).map((stage) => ({
|
|
|
|
|
|
value: stage.id,
|
|
|
|
|
|
label: stage.name,
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-12 20:55:14 +03:30
|
|
|
|
function statusLabel(stage: Pick<PipelineMergePreviewStageDto, 'isWon' | 'isLost'>) {
|
|
|
|
|
|
if (stage.isWon) return 'برد';
|
|
|
|
|
|
if (stage.isLost) return 'باخت';
|
|
|
|
|
|
return 'باز';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function syncStageMap() {
|
|
|
|
|
|
const current = preview.value;
|
|
|
|
|
|
if (!current || !targetId.value) {
|
|
|
|
|
|
stageMap.value = {};
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const next: Record<string, string> = {};
|
|
|
|
|
|
for (const sourceStage of current.stages) {
|
|
|
|
|
|
const compatible = compatibleTargets(sourceStage);
|
|
|
|
|
|
const currentTargetId = stageMap.value[sourceStage.id];
|
|
|
|
|
|
if (compatible.some((stage) => stage.id === currentTargetId)) {
|
|
|
|
|
|
next[sourceStage.id] = currentTargetId;
|
|
|
|
|
|
} else if (compatible.length === 1) {
|
|
|
|
|
|
next[sourceStage.id] = compatible[0].id;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
next[sourceStage.id] = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
stageMap.value = next;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function loadPreview(id: string) {
|
|
|
|
|
|
busy.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { data } = await api.get<PipelineMergePreviewDto>(`/pipelines/${id}/merge-preview`);
|
|
|
|
|
|
preview.value = data;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
error.value = apiError(e, 'پیشنمایش ادغام ناموفق بود.');
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
busy.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function nextFromTarget() {
|
|
|
|
|
|
if (!canContinueTarget.value) {
|
|
|
|
|
|
error.value = 'کاریز مقصد را انتخاب کنید.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
syncStageMap();
|
|
|
|
|
|
step.value = 'map';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function nextFromMap() {
|
|
|
|
|
|
if (!canContinueMap.value) {
|
|
|
|
|
|
error.value = 'برای همه مرحلهها مقصد سازگار انتخاب کنید.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
step.value = 'review';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function submitMerge() {
|
|
|
|
|
|
if (!props.sourceId || !preview.value || !canContinueMap.value || busy.value) return;
|
|
|
|
|
|
|
|
|
|
|
|
busy.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
const body: MergePipelineRequest = {
|
|
|
|
|
|
targetPipelineId: targetId.value,
|
|
|
|
|
|
stageMap: stageMap.value,
|
|
|
|
|
|
leadFormMode: 'retarget_all',
|
|
|
|
|
|
};
|
|
|
|
|
|
await api.post<MergePipelineResultDto>(`/pipelines/${props.sourceId}/merge`, body);
|
|
|
|
|
|
emit('done');
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
error.value = apiError(e, 'ادغام کاریز ناموفق بود.');
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
busy.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => [props.open, props.sourceId] as const,
|
|
|
|
|
|
async ([open, id]) => {
|
2026-10-12 21:59:46 +03:30
|
|
|
|
if (!open || !id) {
|
|
|
|
|
|
resetState();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-10-12 20:55:14 +03:30
|
|
|
|
resetState();
|
|
|
|
|
|
await loadPreview(id);
|
|
|
|
|
|
},
|
2026-10-12 21:59:46 +03:30
|
|
|
|
{ immediate: true },
|
2026-10-12 20:55:14 +03:30
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
watch(targetId, () => {
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
syncStageMap();
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-flex vertical :gap="16">
|
|
|
|
|
|
<a-steps :current="stepIndex">
|
|
|
|
|
|
<a-step title="مقصد" />
|
|
|
|
|
|
<a-step title="نگاشت" />
|
|
|
|
|
|
<a-step title="بازبینی" />
|
|
|
|
|
|
</a-steps>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-spin :spinning="busy && !preview">
|
|
|
|
|
|
<template v-if="preview">
|
|
|
|
|
|
<a-flex v-if="step === 'target'" vertical :gap="16">
|
|
|
|
|
|
<a-flex :gap="8" align="flex-start">
|
|
|
|
|
|
<AppstoreOutlined />
|
|
|
|
|
|
<a-flex vertical :gap="4">
|
|
|
|
|
|
<a-typography-title :level="5" :style="{ margin: 0 }">
|
|
|
|
|
|
کاریز مقصد را انتخاب کنید
|
|
|
|
|
|
</a-typography-title>
|
|
|
|
|
|
<a-typography-text type="secondary">
|
|
|
|
|
|
معاملات و فرمهای سرنخ از «{{ preview.source.name }}» به کاریز مقصد منتقل میشوند.
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
</a-flex>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-form layout="vertical">
|
|
|
|
|
|
<a-form-item label="کاریز مقصد" required>
|
|
|
|
|
|
<a-select
|
|
|
|
|
|
v-model:value="targetId"
|
|
|
|
|
|
:options="targetOptions"
|
|
|
|
|
|
placeholder="انتخاب کنید"
|
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-form>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-row :gutter="[16, 16]">
|
|
|
|
|
|
<a-col :xs="24" :md="8">
|
|
|
|
|
|
<a-card :bordered="true">
|
|
|
|
|
|
<a-typography-text strong>{{ toFaDigits(preview.dealCount) }}</a-typography-text>
|
|
|
|
|
|
<br />
|
|
|
|
|
|
<a-typography-text type="secondary">معامله منتقل میشود</a-typography-text>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
<a-col :xs="24" :md="8">
|
|
|
|
|
|
<a-card :bordered="true">
|
|
|
|
|
|
<a-typography-text strong>{{ toFaDigits(preview.leadForms.length) }}</a-typography-text>
|
|
|
|
|
|
<br />
|
|
|
|
|
|
<a-typography-text type="secondary">فرم سرنخ به مقصد وصل میشود</a-typography-text>
|
|
|
|
|
|
</a-card>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
<a-col v-if="preview.source.isDefault" :xs="24" :md="8">
|
|
|
|
|
|
<a-alert
|
|
|
|
|
|
type="warning"
|
|
|
|
|
|
show-icon
|
|
|
|
|
|
message="هشدار"
|
|
|
|
|
|
description="کاریز مبدا پیشفرض است و بعد از ادغام حذف میشود."
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
</a-row>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-alert
|
|
|
|
|
|
v-if="selectedTarget?.isDefault"
|
|
|
|
|
|
type="info"
|
|
|
|
|
|
show-icon
|
|
|
|
|
|
message="مقصد انتخابشده کاریز پیشفرض است."
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-flex>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-flex v-else-if="step === 'map'" vertical :gap="16">
|
|
|
|
|
|
<a-flex :gap="8" align="flex-start">
|
|
|
|
|
|
<AimOutlined />
|
|
|
|
|
|
<a-flex vertical :gap="4">
|
|
|
|
|
|
<a-typography-title :level="5" :style="{ margin: 0 }">
|
|
|
|
|
|
مرحلههای مبدا را نگاشت کنید
|
|
|
|
|
|
</a-typography-title>
|
|
|
|
|
|
<a-typography-text type="secondary">
|
|
|
|
|
|
هر مرحله فقط به مرحلهای با وضعیت سازگار در مقصد وصل میشود.
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
</a-flex>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-form layout="vertical">
|
|
|
|
|
|
<a-row
|
|
|
|
|
|
v-for="sourceStage in preview.stages"
|
|
|
|
|
|
:key="sourceStage.id"
|
|
|
|
|
|
:gutter="[16, 0]"
|
|
|
|
|
|
align="middle"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-col :xs="24" :md="12">
|
|
|
|
|
|
<a-form-item :style="{ marginBottom: '12px' }">
|
|
|
|
|
|
<a-typography-text strong>{{ sourceStage.name }}</a-typography-text>
|
|
|
|
|
|
<br />
|
|
|
|
|
|
<a-typography-text type="secondary">
|
|
|
|
|
|
{{ statusLabel(sourceStage) }} · {{ toFaDigits(sourceStage.dealCount) }} معامله
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
<a-col :xs="24" :md="12">
|
|
|
|
|
|
<a-form-item
|
|
|
|
|
|
label="مرحله مقصد"
|
|
|
|
|
|
required
|
|
|
|
|
|
:validate-status="stageMap[sourceStage.id] ? undefined : 'error'"
|
|
|
|
|
|
:style="{ marginBottom: '12px' }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-select
|
|
|
|
|
|
v-model:value="stageMap[sourceStage.id]"
|
|
|
|
|
|
:options="compatibleOptions(sourceStage)"
|
|
|
|
|
|
placeholder="مرحله مقصد"
|
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-col>
|
|
|
|
|
|
</a-row>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</a-flex>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-flex v-else vertical :gap="16">
|
|
|
|
|
|
<a-flex :gap="8" align="flex-start">
|
|
|
|
|
|
<CheckCircleOutlined />
|
|
|
|
|
|
<a-flex vertical :gap="4">
|
|
|
|
|
|
<a-typography-title :level="5" :style="{ margin: 0 }">بازبینی نهایی</a-typography-title>
|
|
|
|
|
|
<a-typography-paragraph type="secondary" :style="{ margin: 0 }">
|
|
|
|
|
|
«{{ toFaDigits(preview.dealCount) }}» معامله منتقل میشود.
|
|
|
|
|
|
{{ toFaDigits(preview.leadForms.length) }} فرم سرنخ به مقصد وصل میشود.
|
|
|
|
|
|
کاریز «{{ preview.source.name }}» حذف میشود.
|
|
|
|
|
|
</a-typography-paragraph>
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
</a-flex>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-descriptions :column="1" size="small" bordered>
|
|
|
|
|
|
<a-descriptions-item label="مبدا">{{ preview.source.name }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="مقصد">{{ selectedTarget?.name }}</a-descriptions-item>
|
|
|
|
|
|
<a-descriptions-item label="روش فرمها">
|
|
|
|
|
|
همه فرمهای سرنخ به مقصد وصل میشوند.
|
|
|
|
|
|
</a-descriptions-item>
|
|
|
|
|
|
</a-descriptions>
|
|
|
|
|
|
</a-flex>
|
|
|
|
|
|
</template>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-typography-text v-else-if="!busy && !error" type="secondary">
|
|
|
|
|
|
<template v-if="sourceId">در حال بارگذاری پیشنمایش ادغام…</template>
|
|
|
|
|
|
<template v-else>برای شروع ادغام، از فهرست کاریزها دکمهٔ «ادغام» را بزنید.</template>
|
|
|
|
|
|
</a-typography-text>
|
|
|
|
|
|
</a-spin>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-alert v-if="error" type="error" show-icon :message="error" />
|
2026-10-12 20:55:14 +03:30
|
|
|
|
|
2026-11-04 10:01:11 +03:30
|
|
|
|
<a-space wrap>
|
|
|
|
|
|
<a-button :disabled="busy" @click="emit('close')">بستن</a-button>
|
|
|
|
|
|
<a-button v-if="step === 'map'" :disabled="busy" @click="step = 'target'">قبلی</a-button>
|
|
|
|
|
|
<a-button v-else-if="step === 'review'" :disabled="busy" @click="step = 'map'">قبلی</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-if="step === 'target'"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:disabled="!preview || !canContinueTarget"
|
|
|
|
|
|
@click="nextFromTarget"
|
|
|
|
|
|
>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
ادامه
|
2026-11-04 10:01:11 +03:30
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-else-if="step === 'map'"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:disabled="!canContinueMap"
|
|
|
|
|
|
@click="nextFromMap"
|
|
|
|
|
|
>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
بازبینی
|
2026-11-04 10:01:11 +03:30
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
v-else
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
danger
|
|
|
|
|
|
:loading="busy"
|
|
|
|
|
|
:disabled="!canContinueMap"
|
|
|
|
|
|
@click="submitMerge"
|
|
|
|
|
|
>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
ادغام و حذف مبدا
|
2026-11-04 10:01:11 +03:30
|
|
|
|
</a-button>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
</a-flex>
|
2026-10-12 20:55:14 +03:30
|
|
|
|
</template>
|