Require a stage-move reason and record it on the lead timeline.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -97,6 +97,9 @@ const users = ref<OrgUserDto[]>([]);
|
||||
const activities = ref<ActivityDto[]>([]);
|
||||
|
||||
const stageId = ref('');
|
||||
const stageMoveOpen = ref(false);
|
||||
const stageMoveReason = ref('');
|
||||
const stageMoveError = ref('');
|
||||
const assigneeId = ref('');
|
||||
const callOutcome = ref('');
|
||||
const callBody = ref('');
|
||||
@@ -270,18 +273,48 @@ async function saveEdit() {
|
||||
}
|
||||
}
|
||||
|
||||
async function changeStage() {
|
||||
function openStageMove() {
|
||||
if (!stageId.value || stageId.value === lead.value?.stageId) return;
|
||||
stageMoveReason.value = '';
|
||||
stageMoveError.value = '';
|
||||
stageMoveOpen.value = true;
|
||||
}
|
||||
|
||||
function cancelStageMove() {
|
||||
stageMoveOpen.value = false;
|
||||
stageMoveReason.value = '';
|
||||
stageMoveError.value = '';
|
||||
if (lead.value) stageId.value = lead.value.stageId;
|
||||
}
|
||||
|
||||
async function changeStage() {
|
||||
if (!stageId.value || stageId.value === lead.value?.stageId) {
|
||||
return Promise.reject();
|
||||
}
|
||||
const reason = stageMoveReason.value.trim();
|
||||
if (!reason) {
|
||||
stageMoveError.value = 'دلیل تغییر ستون را بنویسید.';
|
||||
return Promise.reject();
|
||||
}
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
stageMoveError.value = '';
|
||||
try {
|
||||
await api.patch(`/leads/${id.value}/move`, { stageId: stageId.value });
|
||||
await api.patch(`/leads/${id.value}/move`, {
|
||||
stageId: stageId.value,
|
||||
reason,
|
||||
});
|
||||
okMsg.value = 'وضعیت بهروز شد.';
|
||||
message.success(okMsg.value);
|
||||
moreOpen.value = false;
|
||||
stageMoveOpen.value = false;
|
||||
stageMoveReason.value = '';
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'تغییر وضعیت ناموفق بود.');
|
||||
const msg = apiError(e, 'تغییر وضعیت ناموفق بود.');
|
||||
stageMoveError.value = msg;
|
||||
error.value = msg;
|
||||
return Promise.reject(e);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
@@ -438,10 +471,15 @@ function openTel() {
|
||||
const feed = computed(() => {
|
||||
const rows: Array<{ key: string; title: string; by: string; at: string }> = [];
|
||||
for (const ev of lead.value?.events ?? []) {
|
||||
const body = ev.body?.trim();
|
||||
rows.push({
|
||||
key: `ev-${ev.id}`,
|
||||
title: ev.title,
|
||||
by: ev.body?.trim() || 'توسط سیستم',
|
||||
by: body
|
||||
? ev.type === 'stage_changed'
|
||||
? `دلیل: ${body}`
|
||||
: body
|
||||
: 'توسط سیستم',
|
||||
at: ev.createdAt,
|
||||
});
|
||||
}
|
||||
@@ -866,7 +904,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
</a-typography-text>
|
||||
</div>
|
||||
<a-typography-paragraph v-if="ev.body" type="secondary">
|
||||
{{ ev.body }}
|
||||
<template v-if="ev.type === 'stage_changed'">دلیل: </template>{{ ev.body }}
|
||||
</a-typography-paragraph>
|
||||
</a-timeline-item>
|
||||
</a-timeline>
|
||||
@@ -936,7 +974,12 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-button block :disabled="busy" :loading="busy" @click="changeStage">
|
||||
<a-button
|
||||
block
|
||||
:disabled="busy || stageId === lead.stageId"
|
||||
:loading="busy"
|
||||
@click="openStageMove"
|
||||
>
|
||||
اعمال وضعیت
|
||||
</a-button>
|
||||
|
||||
@@ -1082,7 +1125,13 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-button block :disabled="busy" @click="changeStage">اعمال وضعیت</a-button>
|
||||
<a-button
|
||||
block
|
||||
:disabled="busy || stageId === lead.stageId"
|
||||
@click="openStageMove"
|
||||
>
|
||||
اعمال وضعیت
|
||||
</a-button>
|
||||
|
||||
<template v-if="canAssignOthers">
|
||||
<a-divider orientation="right">تخصیص کارشناس</a-divider>
|
||||
@@ -1171,6 +1220,31 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
</a-form>
|
||||
</a-drawer>
|
||||
|
||||
<a-modal
|
||||
v-model:open="stageMoveOpen"
|
||||
title="دلیل تغییر ستون"
|
||||
ok-text="ثبت و انتقال"
|
||||
cancel-text="انصراف"
|
||||
:confirm-loading="busy"
|
||||
:ok-button-props="{ disabled: !stageMoveReason.trim() }"
|
||||
@ok="changeStage"
|
||||
@cancel="cancelStageMove"
|
||||
>
|
||||
<a-flex vertical :gap="12">
|
||||
<a-typography-text type="secondary">
|
||||
انتقال به «{{ stages.find((s) => s.id === stageId)?.name || '—' }}»
|
||||
</a-typography-text>
|
||||
<a-textarea
|
||||
v-model:value="stageMoveReason"
|
||||
:rows="4"
|
||||
:maxlength="1000"
|
||||
show-count
|
||||
placeholder="دلیل تغییر ستون را بنویسید…"
|
||||
/>
|
||||
<a-alert v-if="stageMoveError" type="error" show-icon :message="stageMoveError" />
|
||||
</a-flex>
|
||||
</a-modal>
|
||||
|
||||
<SmsComposeModal
|
||||
:open="smsOpen"
|
||||
title="ارسال پیامک"
|
||||
|
||||
Reference in New Issue
Block a user