Replace the inline SVG icon set with the vuesax linear pack, add skeleton primitives for loading states, and keep page scroll inside the app shell. Co-authored-by: Cursor <cursoragent@cursor.com>
395 lines
12 KiB
Vue
395 lines
12 KiB
Vue
<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';
|
||
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,
|
||
} from '@/icons/ant-bridge';
|
||
|
||
const { Title: ATypographyTitle, Text: ATypographyText, Paragraph: ATypographyParagraph } = Typography;
|
||
|
||
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('');
|
||
|
||
const stepIndex = computed(() => {
|
||
if (step.value === 'target') return 0;
|
||
if (step.value === 'map') return 1;
|
||
return 2;
|
||
});
|
||
|
||
const selectedTarget = computed(
|
||
() => preview.value?.targets.find((target) => target.id === targetId.value) ?? null,
|
||
);
|
||
|
||
const targetOptions = computed(() =>
|
||
(preview.value?.targets ?? []).map((target) => ({
|
||
value: target.id,
|
||
label: target.name,
|
||
})),
|
||
);
|
||
|
||
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;
|
||
});
|
||
}
|
||
|
||
function compatibleOptions(src: PipelineMergePreviewStageDto) {
|
||
return compatibleTargets(src).map((stage) => ({
|
||
value: stage.id,
|
||
label: stage.name,
|
||
}));
|
||
}
|
||
|
||
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]) => {
|
||
if (!open || !id) {
|
||
resetState();
|
||
return;
|
||
}
|
||
resetState();
|
||
await loadPreview(id);
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
watch(targetId, () => {
|
||
error.value = '';
|
||
syncStageMap();
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<a-flex vertical :gap="16">
|
||
<a-steps :current="stepIndex">
|
||
<a-step title="مقصد" />
|
||
<a-step title="نگاشت" />
|
||
<a-step title="بازبینی" />
|
||
</a-steps>
|
||
|
||
<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>
|
||
|
||
<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>
|
||
|
||
<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>
|
||
|
||
<a-alert
|
||
v-if="selectedTarget?.isDefault"
|
||
type="info"
|
||
show-icon
|
||
message="مقصد انتخابشده کاریز پیشفرض است."
|
||
/>
|
||
</a-flex>
|
||
|
||
<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>
|
||
|
||
<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>
|
||
|
||
<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>
|
||
|
||
<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>
|
||
|
||
<a-typography-text v-else-if="!busy && !error" type="secondary">
|
||
<template v-if="sourceId">در حال بارگذاری پیشنمایش ادغام…</template>
|
||
<template v-else>برای شروع ادغام، از فهرست کاریزها دکمهٔ «ادغام» را بزنید.</template>
|
||
</a-typography-text>
|
||
</a-spin>
|
||
|
||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||
|
||
<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"
|
||
>
|
||
ادامه
|
||
</a-button>
|
||
<a-button
|
||
v-else-if="step === 'map'"
|
||
type="primary"
|
||
:disabled="!canContinueMap"
|
||
@click="nextFromMap"
|
||
>
|
||
بازبینی
|
||
</a-button>
|
||
<a-button
|
||
v-else
|
||
type="primary"
|
||
danger
|
||
:loading="busy"
|
||
:disabled="!canContinueMap"
|
||
@click="submitMerge"
|
||
>
|
||
ادغام و حذف مبدا
|
||
</a-button>
|
||
</a-space>
|
||
</a-flex>
|
||
</template>
|