Commit 0290019e by chenwq

新增线索详情页面及相关 API,优化线索管理功能

1 parent f1bacc72
...@@ -4,6 +4,7 @@ import { SubAppProvider, readInitialPage, shortName, subappBus } from '@uj/platf ...@@ -4,6 +4,7 @@ import { SubAppProvider, readInitialPage, shortName, subappBus } from '@uj/platf
import { UEmpty } from '@uj/ui'; import { UEmpty } from '@uj/ui';
import Dashboard from './pages/Dashboard'; import Dashboard from './pages/Dashboard';
import Leads from './pages/Leads'; import Leads from './pages/Leads';
import LeadDetail from './pages/Leads/LeadDetail';
import Assessment from './pages/Assessment'; import Assessment from './pages/Assessment';
import Operation from './pages/Operation'; import Operation from './pages/Operation';
import Vehicles from './pages/Vehicles'; import Vehicles from './pages/Vehicles';
...@@ -25,6 +26,7 @@ import { matchRoute } from './routes'; ...@@ -25,6 +26,7 @@ import { matchRoute } from './routes';
const ROUTES: RouteDef[] = [ const ROUTES: RouteDef[] = [
{ path: 'dashboard', Page: Dashboard }, { path: 'dashboard', Page: Dashboard },
{ path: 'leads', Page: Leads }, { path: 'leads', Page: Leads },
{ path: 'leads/:id', Page: LeadDetail },
{ path: 'assessment', Page: Assessment }, { path: 'assessment', Page: Assessment },
{ path: 'operation', Page: Operation }, { path: 'operation', Page: Operation },
{ path: 'vehicles', Page: Vehicles }, { path: 'vehicles', Page: Vehicles },
......
...@@ -6,3 +6,4 @@ ...@@ -6,3 +6,4 @@
* 后续接入接口时,按 system / store / points 的写法把模块挂到这里即可。 * 后续接入接口时,按 system / store / points 的写法把模块挂到这里即可。
*/ */
export * from './modules/dashboard'; export * from './modules/dashboard';
export * from './modules/leads';
import { ApiClient } from '../core/client';
export interface LeadRow { id: string | number; cluesNo?: string; enterTime?: string; sellerMerchantName?: string; sellerName?: string; carOwnerName?: string; carOwnerPhone?: string; carBrand?: string; carChildsBrandName?: string; carSeriesName?: string; carTypeName?: string; customerIntentLevel?: string; cluesStatus?: number; followTimeStatus?: number; followRecordList?: Array<Record<string, unknown>>; latestFollowTime?: string; nextFollowTime?: string; enterType?: number | string; conversionName?: string; }
export interface LeadPage { records: LeadRow[]; total: number; currentPage?: number; pageSize?: number; }
export interface LeadSearchParams extends Record<string, unknown> { currentPage: number; pageSize: number; }
export interface LeadPageRequest extends Record<string, unknown> { currentPage: number; pageSize: number; t: Record<string, unknown>; }
export interface Merchant { sellerMerchantId: string; sellerMerchantName: string; }
export interface LeadDetail extends LeadRow { remark?: string; evaluateBrandModel?: string; }
export interface FollowRecord extends Record<string, unknown> { createdDate?: string; followRecordType?: number; followUserName?: string; followStyle?: number; followResult?: number; }
export interface OperationLog { opTime?: string; opUserName?: string; opType?: number; opContent?: string; }
class LeadsApi extends ApiClient {
page(params: LeadPageRequest) { return this.post<LeadPage>('/clues/page', params); }
merchants(params: Record<string, unknown>) { return this.post<{ records: Merchant[] }>('/clues/merchantPage', params); }
statusCount(params: Record<string, unknown>) { return this.post<Record<string, number>>('/clues/statusCount', params); }
followTimeStatusCount() { return this.post<{ nearlyExpiredCount?: number; expiredCount?: number }>('/clues/followTimeStatusCount'); }
detail(id: string) { return this.post<LeadDetail>('/clues/detail', { id }); }
followRecords(id: string) { return this.post<FollowRecord[]>('/clues/followRecord/list', { cluesId: id }); }
operationLogs(id: string) { return this.post<OperationLog[]>('/clues/operationLog/list', { cluesId: id }); }
exportAsync(params: LeadSearchParams) { return this.post<unknown>('/clues/exportAsync', params); }
}
export const leadsApi = new LeadsApi();
import { useQuery } from '@tanstack/react-query';
import { UAlert, UButton, UCard, UDescriptions, UEmpty, UResult, UTable, UTag } from '@uj/ui';
import { PageShell } from '@/components';
import { useAccess } from '@/access';
import { leadsApi, type FollowRecord, type LeadDetail, type OperationLog } from '@/api';
import { UC } from '@/permissions/codes';
import type { PageParams } from '@/routes';
import { goLeads } from './navigate';
import './leads.css';
const levelDescription: Record<string, string> = { O: '客情回复,确认交车时间', H: '1日内跟进', A: '2日内跟进', B: '5天内跟进', C: '10天跟进', D: '20天跟进' };
const followStyle: Record<number, string> = { 1: '电话', 2: '微信', 3: '到店', 4: '上门', 5: '短信', 6: '其他' };
const followResult: Record<number, string> = { 1: '邀约验车', 2: '客户考虑中', 3: '不卖旧车', 4: '还在考虑收购价', 5: '还没定新车', 6: '成功收车', 7: '其他' };
const displacement: Record<number, string> = { 1: '收车置换', 2: '不收车置换', 3: '未确定' };
const detection: Record<number, string> = { 1: '到店', 2: '远程', 3: '第三方', 4: '上门' };
const failReason: Record<number, string> = { 1: '客户自行处理', 2: '家人不同意', 3: '客户决定增购', 4: '旧车已处置', 5: '其他' };
const operationType: Record<number, string> = { 1: '创建线索', 2: '新增跟进', 3: '状态变更', 4: '意向等级变更' };
const statusText: Record<string, string> = { '1': '待跟进', '2': '跟进中', '3': '暂败', '4': '成功收车' };
function display(value: unknown): string { return value === undefined || value === null || value === '' ? '-' : String(value); }
function model(detail: LeadDetail): string { return [detail.carBrand, detail.carChildsBrandName, detail.carSeriesName, detail.carTypeName].filter(Boolean).join('-') || '-'; }
function FollowItem({ item }: { item: FollowRecord }) {
const result = Number(item.followResult);
const rows: Array<[string, unknown]> = [
['跟进人', item.followUserName], ['跟进方式', followStyle[Number(item.followStyle)]], ['跟进结果', followResult[result]],
...(result === 1 ? [['置换类型', displacement[Number(item.displacementType)]], ['检测方式', detection[Number(item.detectionMode)]]] as Array<[string, unknown]> : []),
...(result === 3 ? [['暂败原因', failReason[Number(item.failReason)]]] as Array<[string, unknown]> : []),
['意向等级', item.customerIntentLevelChange], ['下一次跟进时间', item.nextFollowTime], ['跟进内容', item.followRemark],
];
return <div className="uc-lead-follow__item"><div className="uc-lead-follow__head"><b>{Number(item.followRecordType) === 2 ? '24小时内跟进线索' : '跟进线索'}</b><span>{display(item.createdDate)}</span></div><div className="uc-lead-follow__body">{rows.map(([label, value]) => <span key={label}>{label}:<b>{display(value)}</b></span>)}</div></div>;
}
/** 线索详情为独立路由页面:/usedcar/leads/:id。 */
export default function LeadDetail({ params }: { params: PageParams }) {
const { canPoint } = useAccess();
const allowed = canPoint(UC.LEAD_DETAIL);
const id = params.id;
const detail = useQuery({ queryKey: ['usedcar', 'lead', id], queryFn: () => leadsApi.detail(id), enabled: allowed && Boolean(id) });
const follows = useQuery({ queryKey: ['usedcar', 'lead', id, 'follows'], queryFn: () => leadsApi.followRecords(id), enabled: allowed && Boolean(id) });
const logs = useQuery({ queryKey: ['usedcar', 'lead', id, 'logs'], queryFn: () => leadsApi.operationLogs(id), enabled: allowed && Boolean(id) });
if (!allowed) return <UResult status="403" title="无查看线索详情的权限" subTitle="请联系管理员开通“查看详情”权限。" />;
if (!id) return <UResult status="404" title="未找到线索" subTitle="详情地址缺少线索编号。" />;
const data: LeadDetail = detail.data ?? { id };
const status = String(data.cluesStatus ?? '');
const followStatus = Number(data.followTimeStatus);
return <PageShell title="线索详情" description="查看线索基础信息、跟进记录和操作日志。" onBack={goLeads}>
{detail.isError ? <UAlert type="error" showIcon title="线索详情加载失败" action={<UButton type="link" onClick={() => void detail.refetch()}>重试</UButton>} /> : null}
<div className="uc-lead-detail">
<div className="uc-lead-detail__top">
<UCard><h3 className="uc-lead-detail__title">基础信息 {status ? <UTag color={status === '2' ? 'green' : status === '3' ? 'red' : status === '4' ? 'purple' : 'blue'}>{statusText[status]}</UTag> : null} {followStatus ? <UTag color={followStatus === 1 ? 'orange' : 'red'}>{followStatus === 1 ? '临期' : '已超期'}</UTag> : null}</h3>
<UDescriptions column={2} size="small">
<UDescriptions.Item label="线索 ID">{display(data.cluesNo)}</UDescriptions.Item><UDescriptions.Item label="录入时间">{display(data.enterTime)}</UDescriptions.Item>
<UDescriptions.Item label="线索门店">{display(data.sellerMerchantName)}</UDescriptions.Item><UDescriptions.Item label="推荐销售顾问">{display(data.sellerName)}</UDescriptions.Item>
<UDescriptions.Item label="车主姓名">{display(data.carOwnerName)}</UDescriptions.Item><UDescriptions.Item label="车主电话">{display(data.carOwnerPhone)}</UDescriptions.Item>
<UDescriptions.Item label="评估品牌车型" span={2}>{model(data)}</UDescriptions.Item><UDescriptions.Item label="最近跟进时间">{display(data.latestFollowTime)}</UDescriptions.Item><UDescriptions.Item label="下一次跟进时间">{display(data.nextFollowTime)}</UDescriptions.Item>
</UDescriptions>
</UCard>
<div><UCard><h3 className="uc-lead-detail__title">客户意向等级</h3><p><strong>{display(data.customerIntentLevel)}级</strong>{' '}{levelDescription[String(data.customerIntentLevel)] ?? '-'}</p><p>下一次跟进时间:{display(data.nextFollowTime)}</p></UCard><UCard style={{ marginTop: 16 }}><h3 className="uc-lead-detail__title">备注说明</h3><p>{display(data.remark === undefined ? '暂无备注' : data.remark)}</p></UCard></div>
</div>
<UCard><h3 className="uc-lead-detail__title">跟进记录(共 {follows.data?.length ?? 0} 条,时间倒序)</h3>{follows.isError ? <UAlert type="error" showIcon title="跟进记录加载失败" /> : follows.data?.length ? <div className="uc-lead-follow">{follows.data.map((item, index) => <FollowItem item={item} key={`${item.createdDate ?? ''}-${index}`} />)}</div> : <UEmpty description="暂无跟进记录" />}</UCard>
<UCard><h3 className="uc-lead-detail__title">操作日志</h3>{logs.isError ? <UAlert type="error" showIcon title="操作日志加载失败" /> : <UTable<OperationLog> rowKey={(_, index) => String(index)} pagination={false} dataSource={logs.data ?? []} columns={[{ title: '操作时间', dataIndex: 'opTime', render: display }, { title: '操作人', dataIndex: 'opUserName', render: display }, { title: '操作类型', dataIndex: 'opType', render: (value) => operationType[Number(value)] ?? '-' }, { title: '操作内容', dataIndex: 'opContent', render: display }]} />}</UCard>
</div>
</PageShell>;
}
.uc-lead-reminder { margin: 0 0 12px; color: #d48806; }
.uc-lead-reminder strong { color: #cf1322; font-weight: 500; }
.uc-lead-level { display: inline-flex; align-items: center; gap: 7px; }
.uc-lead-level b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; background: #8c8c8c; }
.uc-lead-level--o b { background: #c04dff; }.uc-lead-level--h b { background: #f7a900; }.uc-lead-level--a b { background: #55b896; }.uc-lead-level--b b { background: #5fbdff; }.uc-lead-level--c b { background: #54dfff; }
.uc-lead-detail { display: grid; gap: 16px; }.uc-lead-detail__top { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }.uc-lead-detail__title { margin: 0 0 14px; font-size: 15px; }.uc-lead-detail__empty { padding: 28px; text-align: center; color: var(--uj-text-3); }.uc-lead-follow { display: grid; gap: 12px; }.uc-lead-follow__item { border-left: 2px solid #1677ff; padding-left: 14px; }.uc-lead-follow__head { display: flex; justify-content: space-between; margin-bottom: 8px; }.uc-lead-follow__body { background: #f5f7fa; padding: 12px; border-radius: 6px; display: grid; gap: 6px; }.uc-lead-follow__body span { color: var(--uj-text-2); }.uc-lead-follow__body b { color: var(--uj-text-1); font-weight: 400; }
@media (max-width: 900px) { .uc-lead-detail__top { grid-template-columns: 1fr; } }
import { shortName, subAppProps } from '@uj/platform-sdk';
export function goTo(path: string): void {
subAppProps().navigate(`/${shortName()}/${path.replace(/^\/+|\/+$/g, '')}`);
}
export function goLeads(): void {
goTo('leads');
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!