Require a stage-move reason and record it on the lead timeline.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -63,6 +63,8 @@ export class UpdateLeadDto {
|
|||||||
@IsOptional() @IsString() notes?: string | null;
|
@IsOptional() @IsString() notes?: string | null;
|
||||||
@IsOptional() @IsNumber() estimatedValue?: number | null;
|
@IsOptional() @IsNumber() estimatedValue?: number | null;
|
||||||
@IsOptional() @IsString() stageId?: string;
|
@IsOptional() @IsString() stageId?: string;
|
||||||
|
/** الزامی هنگام تغییر ستون؛ در جدول زمانی لید ثبت میشود */
|
||||||
|
@IsOptional() @IsString() @MaxLength(1000) reason?: string | null;
|
||||||
@IsOptional() @IsString() assigneeId?: string | null;
|
@IsOptional() @IsString() assigneeId?: string | null;
|
||||||
@IsOptional() @IsString() nextFollowUpAt?: string | null;
|
@IsOptional() @IsString() nextFollowUpAt?: string | null;
|
||||||
@IsOptional() @IsString() lastContactAt?: string | null;
|
@IsOptional() @IsString() lastContactAt?: string | null;
|
||||||
@@ -71,6 +73,7 @@ export class UpdateLeadDto {
|
|||||||
export class MoveLeadDto {
|
export class MoveLeadDto {
|
||||||
@IsString() stageId!: string;
|
@IsString() stageId!: string;
|
||||||
@IsOptional() @IsNumber() position?: number;
|
@IsOptional() @IsNumber() position?: number;
|
||||||
|
@IsOptional() @IsString() @MaxLength(1000) reason?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AssignLeadsDto {
|
export class AssignLeadsDto {
|
||||||
@@ -81,6 +84,7 @@ export class AssignLeadsDto {
|
|||||||
export class BulkLeadStageDto {
|
export class BulkLeadStageDto {
|
||||||
@IsArray() @IsString({ each: true }) leadIds!: string[];
|
@IsArray() @IsString({ each: true }) leadIds!: string[];
|
||||||
@IsString() stageId!: string;
|
@IsString() stageId!: string;
|
||||||
|
@IsOptional() @IsString() @MaxLength(1000) reason?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AutoAssignLeadsDto {
|
export class AutoAssignLeadsDto {
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ export class LeadsController {
|
|||||||
@Roles('owner', 'admin')
|
@Roles('owner', 'admin')
|
||||||
bulkStage(@CurrentUser() user: Actor, @Body() dto: BulkLeadStageDto) {
|
bulkStage(@CurrentUser() user: Actor, @Body() dto: BulkLeadStageDto) {
|
||||||
return this.leads
|
return this.leads
|
||||||
.bulkStage(user, dto.leadIds, dto.stageId)
|
.bulkStage(user, dto.leadIds, dto.stageId, dto.reason)
|
||||||
.then((count) => ({ count }));
|
.then((count) => ({ count }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ export class LeadsController {
|
|||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@Body() dto: MoveLeadDto,
|
@Body() dto: MoveLeadDto,
|
||||||
) {
|
) {
|
||||||
return this.leads.move(user, id, dto.stageId, dto.position);
|
return this.leads.move(user, id, dto.stageId, dto.position, dto.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/sms-history')
|
@Get(':id/sms-history')
|
||||||
|
|||||||
@@ -673,17 +673,21 @@ export class LeadsService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (typeof dto.stageId === 'string' && dto.stageId !== existing.stageId) {
|
if (typeof dto.stageId === 'string' && dto.stageId !== existing.stageId) {
|
||||||
|
const reason = this.requireStageReason(
|
||||||
|
typeof dto.reason === 'string' ? dto.reason : null,
|
||||||
|
);
|
||||||
await this.addEvent(
|
await this.addEvent(
|
||||||
actor,
|
actor,
|
||||||
id,
|
id,
|
||||||
'stage_changed',
|
'stage_changed',
|
||||||
`وضعیت به «${row.stage.name}» تغییر کرد`,
|
`وضعیت به «${row.stage.name}» تغییر کرد`,
|
||||||
null,
|
reason,
|
||||||
{
|
{
|
||||||
fromStageId: existing.stageId,
|
fromStageId: existing.stageId,
|
||||||
fromStageName: existing.stage?.name ?? null,
|
fromStageName: existing.stage?.name ?? null,
|
||||||
toStageId: row.stageId,
|
toStageId: row.stageId,
|
||||||
toStageName: row.stage.name,
|
toStageName: row.stage.name,
|
||||||
|
reason,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
this.gameEvent(actor, 'LEAD_STAGE_CHANGED', row, {
|
this.gameEvent(actor, 'LEAD_STAGE_CHANGED', row, {
|
||||||
@@ -699,6 +703,7 @@ export class LeadsService {
|
|||||||
id: string,
|
id: string,
|
||||||
stageId: string,
|
stageId: string,
|
||||||
position?: number,
|
position?: number,
|
||||||
|
reasonRaw?: string | null,
|
||||||
): Promise<LeadDto> {
|
): Promise<LeadDto> {
|
||||||
const before = await this.findAccessible(actor, id);
|
const before = await this.findAccessible(actor, id);
|
||||||
const stage = await this.prisma.leadStage.findFirst({
|
const stage = await this.prisma.leadStage.findFirst({
|
||||||
@@ -706,6 +711,9 @@ export class LeadsService {
|
|||||||
});
|
});
|
||||||
if (!stage) throw new NotFoundException('مرحله پیدا نشد');
|
if (!stage) throw new NotFoundException('مرحله پیدا نشد');
|
||||||
|
|
||||||
|
const stageChanged = before.stageId !== stageId;
|
||||||
|
const reason = stageChanged ? this.requireStageReason(reasonRaw) : null;
|
||||||
|
|
||||||
let placedIds: string[] | null = null;
|
let placedIds: string[] | null = null;
|
||||||
let nextPosition = position ?? 0;
|
let nextPosition = position ?? 0;
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
@@ -736,18 +744,19 @@ export class LeadsService {
|
|||||||
this.prisma.lead.update({ where: { id: leadId }, data: { position: leadPosition } }),
|
this.prisma.lead.update({ where: { id: leadId }, data: { position: leadPosition } }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (before.stageId !== stageId) {
|
if (stageChanged && reason) {
|
||||||
await this.addEvent(
|
await this.addEvent(
|
||||||
actor,
|
actor,
|
||||||
id,
|
id,
|
||||||
'stage_changed',
|
'stage_changed',
|
||||||
`به مرحله «${stage.name}» منتقل شد`,
|
`به مرحله «${stage.name}» منتقل شد`,
|
||||||
null,
|
reason,
|
||||||
{
|
{
|
||||||
fromStageId: before.stageId,
|
fromStageId: before.stageId,
|
||||||
fromStageName: before.stage?.name ?? null,
|
fromStageName: before.stage?.name ?? null,
|
||||||
toStageId: stageId,
|
toStageId: stageId,
|
||||||
toStageName: stage.name,
|
toStageName: stage.name,
|
||||||
|
reason,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
this.gameEvent(actor, 'LEAD_STAGE_CHANGED', row, {
|
this.gameEvent(actor, 'LEAD_STAGE_CHANGED', row, {
|
||||||
@@ -799,7 +808,9 @@ export class LeadsService {
|
|||||||
actor: Actor,
|
actor: Actor,
|
||||||
leadIds: string[],
|
leadIds: string[],
|
||||||
stageId: string,
|
stageId: string,
|
||||||
|
reasonRaw?: string | null,
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
|
const reason = this.requireStageReason(reasonRaw);
|
||||||
if (!elevated(actor.role)) {
|
if (!elevated(actor.role)) {
|
||||||
throw new BadRequestException('فقط مدیر میتواند وضعیت گروهی تغییر دهد');
|
throw new BadRequestException('فقط مدیر میتواند وضعیت گروهی تغییر دهد');
|
||||||
}
|
}
|
||||||
@@ -834,12 +845,13 @@ export class LeadsService {
|
|||||||
lead.id,
|
lead.id,
|
||||||
'stage_changed',
|
'stage_changed',
|
||||||
`وضعیت گروهی به «${stage.name}»`,
|
`وضعیت گروهی به «${stage.name}»`,
|
||||||
null,
|
reason,
|
||||||
{
|
{
|
||||||
fromStageId: lead.stageId,
|
fromStageId: lead.stageId,
|
||||||
fromStageName: lead.stage.name,
|
fromStageName: lead.stage.name,
|
||||||
toStageId: stageId,
|
toStageId: stageId,
|
||||||
toStageName: stage.name,
|
toStageName: stage.name,
|
||||||
|
reason,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1500,6 +1512,17 @@ export class LeadsService {
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private requireStageReason(raw: string | null | undefined): string {
|
||||||
|
const reason = String(raw ?? '').trim();
|
||||||
|
if (!reason) {
|
||||||
|
throw new BadRequestException('دلیل تغییر ستون الزامی است.');
|
||||||
|
}
|
||||||
|
if (reason.length > 1000) {
|
||||||
|
throw new BadRequestException('دلیل تغییر ستون نباید بیش از ۱۰۰۰ کاراکتر باشد.');
|
||||||
|
}
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
private async addEvent(
|
private async addEvent(
|
||||||
actor: Actor,
|
actor: Actor,
|
||||||
leadId: string,
|
leadId: string,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
Space as ASpace,
|
Space as ASpace,
|
||||||
Spin as ASpin,
|
Spin as ASpin,
|
||||||
Tag as ATag,
|
Tag as ATag,
|
||||||
|
Textarea as ATextarea,
|
||||||
Typography,
|
Typography,
|
||||||
theme,
|
theme,
|
||||||
} from 'ant-design-vue';
|
} from 'ant-design-vue';
|
||||||
@@ -61,6 +62,17 @@ const addLost = ref(false);
|
|||||||
const addUnqualified = ref(false);
|
const addUnqualified = ref(false);
|
||||||
const deleteTarget = ref<LeadStageDto | null>(null);
|
const deleteTarget = ref<LeadStageDto | null>(null);
|
||||||
const moveConfirm = ref<{ stageIds: string[]; message: string } | null>(null);
|
const moveConfirm = ref<{ stageIds: string[]; message: string } | null>(null);
|
||||||
|
const pendingLeadMove = ref<{
|
||||||
|
leadId: string;
|
||||||
|
stageId: string;
|
||||||
|
position: number;
|
||||||
|
fromStageName: string;
|
||||||
|
toStageName: string;
|
||||||
|
prev: LeadBoardColumnDto[];
|
||||||
|
nextColumns: LeadBoardColumnDto[];
|
||||||
|
} | null>(null);
|
||||||
|
const stageMoveReason = ref('');
|
||||||
|
const stageMoveError = ref('');
|
||||||
const draggingId = ref<string | null>(null);
|
const draggingId = ref<string | null>(null);
|
||||||
const insertAt = ref<number | null>(null);
|
const insertAt = ref<number | null>(null);
|
||||||
const bodyEls = new Map<string, HTMLElement>();
|
const bodyEls = new Map<string, HTMLElement>();
|
||||||
@@ -520,7 +532,7 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
|
|||||||
draggingId.value = null;
|
draggingId.value = null;
|
||||||
dropStageId.value = null;
|
dropStageId.value = null;
|
||||||
clearDragUi();
|
clearDragUi();
|
||||||
if (!leadId || moving.value) return;
|
if (!leadId || moving.value || pendingLeadMove.value) return;
|
||||||
|
|
||||||
const fromCol = columns.value.find((c) =>
|
const fromCol = columns.value.find((c) =>
|
||||||
c.leads.some((l) => l.id === leadId),
|
c.leads.some((l) => l.id === leadId),
|
||||||
@@ -546,7 +558,7 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
|
|||||||
leads: [...c.leads],
|
leads: [...c.leads],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
columns.value = columns.value.map((c) => {
|
const nextColumns = columns.value.map((c) => {
|
||||||
if (same && c.stage.id === stageId) return { ...c, leads: nextLeads };
|
if (same && c.stage.id === stageId) return { ...c, leads: nextLeads };
|
||||||
if (c.stage.id === fromCol.stage.id) {
|
if (c.stage.id === fromCol.stage.id) {
|
||||||
return {
|
return {
|
||||||
@@ -561,6 +573,9 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
|
|||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// جابهجایی داخل همان ستون: بدون دلیل
|
||||||
|
if (same) {
|
||||||
|
columns.value = nextColumns;
|
||||||
moving.value = true;
|
moving.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
try {
|
try {
|
||||||
@@ -571,6 +586,56 @@ async function onDrop(stageId: string, event: DragEvent, index?: number) {
|
|||||||
} finally {
|
} finally {
|
||||||
moving.value = false;
|
moving.value = false;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// تغییر ستون: اول دلیل، بعد اعمال
|
||||||
|
stageMoveReason.value = '';
|
||||||
|
stageMoveError.value = '';
|
||||||
|
pendingLeadMove.value = {
|
||||||
|
leadId,
|
||||||
|
stageId,
|
||||||
|
position: insertIndex,
|
||||||
|
fromStageName: fromCol.stage.name,
|
||||||
|
toStageName: target.stage.name,
|
||||||
|
prev,
|
||||||
|
nextColumns,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelPendingLeadMove() {
|
||||||
|
pendingLeadMove.value = null;
|
||||||
|
stageMoveReason.value = '';
|
||||||
|
stageMoveError.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmPendingLeadMove() {
|
||||||
|
const pending = pendingLeadMove.value;
|
||||||
|
if (!pending || moving.value) return Promise.reject();
|
||||||
|
const reason = stageMoveReason.value.trim();
|
||||||
|
if (!reason) {
|
||||||
|
stageMoveError.value = 'دلیل تغییر ستون را بنویسید.';
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
columns.value = pending.nextColumns;
|
||||||
|
moving.value = true;
|
||||||
|
error.value = '';
|
||||||
|
stageMoveError.value = '';
|
||||||
|
try {
|
||||||
|
await api.patch(`/leads/${pending.leadId}/move`, {
|
||||||
|
stageId: pending.stageId,
|
||||||
|
position: pending.position,
|
||||||
|
reason,
|
||||||
|
});
|
||||||
|
cancelPendingLeadMove();
|
||||||
|
} catch (e) {
|
||||||
|
columns.value = pending.prev;
|
||||||
|
stageMoveError.value = apiMessage(e, 'جابهجایی لید ناموفق بود.');
|
||||||
|
error.value = stageMoveError.value;
|
||||||
|
return Promise.reject(e);
|
||||||
|
} finally {
|
||||||
|
moving.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(load);
|
onMounted(load);
|
||||||
@@ -969,6 +1034,31 @@ onMounted(load);
|
|||||||
>
|
>
|
||||||
<a-alert v-if="moveConfirm" type="warning" show-icon :message="moveConfirm.message" />
|
<a-alert v-if="moveConfirm" type="warning" show-icon :message="moveConfirm.message" />
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|
||||||
|
<a-modal
|
||||||
|
:open="!!pendingLeadMove"
|
||||||
|
title="دلیل تغییر ستون"
|
||||||
|
ok-text="ثبت و انتقال"
|
||||||
|
cancel-text="انصراف"
|
||||||
|
:confirm-loading="moving"
|
||||||
|
:ok-button-props="{ disabled: !stageMoveReason.trim() }"
|
||||||
|
@ok="confirmPendingLeadMove"
|
||||||
|
@cancel="cancelPendingLeadMove"
|
||||||
|
>
|
||||||
|
<a-flex vertical :gap="12">
|
||||||
|
<a-typography-text v-if="pendingLeadMove" type="secondary">
|
||||||
|
انتقال از «{{ pendingLeadMove.fromStageName }}» به «{{ pendingLeadMove.toStageName }}»
|
||||||
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ const users = ref<OrgUserDto[]>([]);
|
|||||||
const activities = ref<ActivityDto[]>([]);
|
const activities = ref<ActivityDto[]>([]);
|
||||||
|
|
||||||
const stageId = ref('');
|
const stageId = ref('');
|
||||||
|
const stageMoveOpen = ref(false);
|
||||||
|
const stageMoveReason = ref('');
|
||||||
|
const stageMoveError = ref('');
|
||||||
const assigneeId = ref('');
|
const assigneeId = ref('');
|
||||||
const callOutcome = ref('');
|
const callOutcome = ref('');
|
||||||
const callBody = 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;
|
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;
|
busy.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
|
stageMoveError.value = '';
|
||||||
try {
|
try {
|
||||||
await api.patch(`/leads/${id.value}/move`, { stageId: stageId.value });
|
await api.patch(`/leads/${id.value}/move`, {
|
||||||
|
stageId: stageId.value,
|
||||||
|
reason,
|
||||||
|
});
|
||||||
okMsg.value = 'وضعیت بهروز شد.';
|
okMsg.value = 'وضعیت بهروز شد.';
|
||||||
message.success(okMsg.value);
|
message.success(okMsg.value);
|
||||||
moreOpen.value = false;
|
moreOpen.value = false;
|
||||||
|
stageMoveOpen.value = false;
|
||||||
|
stageMoveReason.value = '';
|
||||||
await load();
|
await load();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = apiError(e, 'تغییر وضعیت ناموفق بود.');
|
const msg = apiError(e, 'تغییر وضعیت ناموفق بود.');
|
||||||
|
stageMoveError.value = msg;
|
||||||
|
error.value = msg;
|
||||||
|
return Promise.reject(e);
|
||||||
} finally {
|
} finally {
|
||||||
busy.value = false;
|
busy.value = false;
|
||||||
}
|
}
|
||||||
@@ -438,10 +471,15 @@ function openTel() {
|
|||||||
const feed = computed(() => {
|
const feed = computed(() => {
|
||||||
const rows: Array<{ key: string; title: string; by: string; at: string }> = [];
|
const rows: Array<{ key: string; title: string; by: string; at: string }> = [];
|
||||||
for (const ev of lead.value?.events ?? []) {
|
for (const ev of lead.value?.events ?? []) {
|
||||||
|
const body = ev.body?.trim();
|
||||||
rows.push({
|
rows.push({
|
||||||
key: `ev-${ev.id}`,
|
key: `ev-${ev.id}`,
|
||||||
title: ev.title,
|
title: ev.title,
|
||||||
by: ev.body?.trim() || 'توسط سیستم',
|
by: body
|
||||||
|
? ev.type === 'stage_changed'
|
||||||
|
? `دلیل: ${body}`
|
||||||
|
: body
|
||||||
|
: 'توسط سیستم',
|
||||||
at: ev.createdAt,
|
at: ev.createdAt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -866,7 +904,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
|||||||
</a-typography-text>
|
</a-typography-text>
|
||||||
</div>
|
</div>
|
||||||
<a-typography-paragraph v-if="ev.body" type="secondary">
|
<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-typography-paragraph>
|
||||||
</a-timeline-item>
|
</a-timeline-item>
|
||||||
</a-timeline>
|
</a-timeline>
|
||||||
@@ -936,7 +974,12 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
|||||||
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</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>
|
</a-button>
|
||||||
|
|
||||||
@@ -1082,7 +1125,13 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
|||||||
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</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">
|
<template v-if="canAssignOthers">
|
||||||
<a-divider orientation="right">تخصیص کارشناس</a-divider>
|
<a-divider orientation="right">تخصیص کارشناس</a-divider>
|
||||||
@@ -1171,6 +1220,31 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
|||||||
</a-form>
|
</a-form>
|
||||||
</a-drawer>
|
</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
|
<SmsComposeModal
|
||||||
:open="smsOpen"
|
:open="smsOpen"
|
||||||
title="ارسال پیامک"
|
title="ارسال پیامک"
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
Spin as ASpin,
|
Spin as ASpin,
|
||||||
Table as ATable,
|
Table as ATable,
|
||||||
Tag as ATag,
|
Tag as ATag,
|
||||||
|
Textarea as ATextarea,
|
||||||
Typography,
|
Typography,
|
||||||
Upload as AUpload,
|
Upload as AUpload,
|
||||||
message,
|
message,
|
||||||
@@ -208,6 +209,9 @@ const assignOpen = ref(false);
|
|||||||
const stageOpen = ref(false);
|
const stageOpen = ref(false);
|
||||||
const assignUserId = ref('');
|
const assignUserId = ref('');
|
||||||
const bulkStageId = ref('');
|
const bulkStageId = ref('');
|
||||||
|
const bulkStageReasonOpen = ref(false);
|
||||||
|
const bulkStageReason = ref('');
|
||||||
|
const bulkStageReasonError = ref('');
|
||||||
const importJob = ref<LeadImportJobDto | null>(null);
|
const importJob = ref<LeadImportJobDto | null>(null);
|
||||||
const createOpen = ref(false);
|
const createOpen = ref(false);
|
||||||
const createBusy = ref(false);
|
const createBusy = ref(false);
|
||||||
@@ -1306,21 +1310,44 @@ async function assignSelected() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bulkStageSelected() {
|
function openBulkStageReason() {
|
||||||
if (!bulkStageId.value || !selectedIds.value.length) return;
|
if (!bulkStageId.value || !selectedIds.value.length) return;
|
||||||
|
bulkStageReason.value = '';
|
||||||
|
bulkStageReasonError.value = '';
|
||||||
|
bulkStageReasonOpen.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelBulkStageReason() {
|
||||||
|
bulkStageReasonOpen.value = false;
|
||||||
|
bulkStageReason.value = '';
|
||||||
|
bulkStageReasonError.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bulkStageSelected() {
|
||||||
|
if (!bulkStageId.value || !selectedIds.value.length) return Promise.reject();
|
||||||
|
const reason = bulkStageReason.value.trim();
|
||||||
|
if (!reason) {
|
||||||
|
bulkStageReasonError.value = 'دلیل تغییر ستون را بنویسید.';
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
busy.value = true;
|
busy.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
|
bulkStageReasonError.value = '';
|
||||||
try {
|
try {
|
||||||
await api.post('/leads/bulk-stage', {
|
await api.post('/leads/bulk-stage', {
|
||||||
leadIds: selectedIds.value,
|
leadIds: selectedIds.value,
|
||||||
stageId: bulkStageId.value,
|
stageId: bulkStageId.value,
|
||||||
|
reason,
|
||||||
});
|
});
|
||||||
okMsg.value = `وضعیت ${toFaDigits(selectedIds.value.length)} لید بهروز شد.`;
|
okMsg.value = `وضعیت ${toFaDigits(selectedIds.value.length)} لید بهروز شد.`;
|
||||||
selected.value = new Set();
|
selected.value = new Set();
|
||||||
stageOpen.value = false;
|
stageOpen.value = false;
|
||||||
|
cancelBulkStageReason();
|
||||||
await load();
|
await load();
|
||||||
} catch {
|
} catch (e) {
|
||||||
error.value = 'تغییر وضعیت گروهی ناموفق بود.';
|
bulkStageReasonError.value = 'تغییر وضعیت گروهی ناموفق بود.';
|
||||||
|
error.value = bulkStageReasonError.value;
|
||||||
|
return Promise.reject(e);
|
||||||
} finally {
|
} finally {
|
||||||
busy.value = false;
|
busy.value = false;
|
||||||
}
|
}
|
||||||
@@ -1974,7 +2001,7 @@ onBeforeUnmount(() => {
|
|||||||
allow-clear
|
allow-clear
|
||||||
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
:options="stages.map((s) => ({ value: s.id, label: s.name }))"
|
||||||
/>
|
/>
|
||||||
<a-button :disabled="!bulkStageId || busy" @click="bulkStageSelected">اعمال وضعیت</a-button>
|
<a-button :disabled="!bulkStageId || busy" @click="openBulkStageReason">اعمال وضعیت</a-button>
|
||||||
</template>
|
</template>
|
||||||
<a-button danger :disabled="busy" @click="archiveSelected">بایگانی</a-button>
|
<a-button danger :disabled="busy" @click="archiveSelected">بایگانی</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
@@ -2450,5 +2477,36 @@ onBeforeUnmount(() => {
|
|||||||
</a-button>
|
</a-button>
|
||||||
</template>
|
</template>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|
||||||
|
<a-modal
|
||||||
|
v-model:open="bulkStageReasonOpen"
|
||||||
|
title="دلیل تغییر ستون"
|
||||||
|
ok-text="ثبت و انتقال"
|
||||||
|
cancel-text="انصراف"
|
||||||
|
:confirm-loading="busy"
|
||||||
|
:ok-button-props="{ disabled: !bulkStageReason.trim() }"
|
||||||
|
@ok="bulkStageSelected"
|
||||||
|
@cancel="cancelBulkStageReason"
|
||||||
|
>
|
||||||
|
<a-flex vertical :gap="12">
|
||||||
|
<a-typography-text type="secondary">
|
||||||
|
انتقال {{ toFaDigits(selectedIds.length) }} لید به
|
||||||
|
«{{ stages.find((s) => s.id === bulkStageId)?.name || '—' }}»
|
||||||
|
</a-typography-text>
|
||||||
|
<a-textarea
|
||||||
|
v-model:value="bulkStageReason"
|
||||||
|
:rows="4"
|
||||||
|
:maxlength="1000"
|
||||||
|
show-count
|
||||||
|
placeholder="دلیل تغییر ستون را بنویسید…"
|
||||||
|
/>
|
||||||
|
<a-alert
|
||||||
|
v-if="bulkStageReasonError"
|
||||||
|
type="error"
|
||||||
|
show-icon
|
||||||
|
:message="bulkStageReasonError"
|
||||||
|
/>
|
||||||
|
</a-flex>
|
||||||
|
</a-modal>
|
||||||
</a-row>
|
</a-row>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -6356,6 +6356,8 @@ export interface UpdateLeadRequest {
|
|||||||
notes?: string | null;
|
notes?: string | null;
|
||||||
estimatedValue?: number | null;
|
estimatedValue?: number | null;
|
||||||
stageId?: string;
|
stageId?: string;
|
||||||
|
/** الزامی هنگام تغییر ستون؛ در جدول زمانی لید ثبت میشود */
|
||||||
|
reason?: string | null;
|
||||||
assigneeId?: string | null;
|
assigneeId?: string | null;
|
||||||
nextFollowUpAt?: string | null;
|
nextFollowUpAt?: string | null;
|
||||||
lastContactAt?: string | null;
|
lastContactAt?: string | null;
|
||||||
@@ -6364,6 +6366,8 @@ export interface UpdateLeadRequest {
|
|||||||
export interface MoveLeadRequest {
|
export interface MoveLeadRequest {
|
||||||
stageId: string;
|
stageId: string;
|
||||||
position?: number;
|
position?: number;
|
||||||
|
/** الزامی هنگام تغییر ستون؛ در جدول زمانی لید ثبت میشود */
|
||||||
|
reason?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AssignLeadsRequest {
|
export interface AssignLeadsRequest {
|
||||||
@@ -6374,6 +6378,8 @@ export interface AssignLeadsRequest {
|
|||||||
export interface BulkLeadStageRequest {
|
export interface BulkLeadStageRequest {
|
||||||
leadIds: string[];
|
leadIds: string[];
|
||||||
stageId: string;
|
stageId: string;
|
||||||
|
/** الزامی؛ در جدول زمانی هر لید ثبت میشود */
|
||||||
|
reason?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AutoAssignLeadsRequest {
|
export interface AutoAssignLeadsRequest {
|
||||||
|
|||||||
Reference in New Issue
Block a user