HandoverDetailDrawer.tsx
5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { useState, type ReactNode } from 'react';
import { useQuery } from '@tanstack/react-query';
import { UAlert, UButton, UCard, UDrawer, UImage } from '@uj/ui';
import { DataTable, type DataTableColumn } from '@/components';
import { staffHandoverApi } from '@/api';
import { errorDetail } from '@/utils/error';
import './handover.css';
type Row = Record<string, unknown> & { id: string | number };
const text = (v: unknown) => (v === undefined || v === null || v === '' ? '-' : String(v));
export default function HandoverDetailDrawer({
record,
onClose,
}: {
record: Row | undefined;
onClose: () => void;
}) {
const [previewUrls, setPreviewUrls] = useState<string[]>([]);
const [previewIndex, setPreviewIndex] = useState(0);
const previewUrl = previewUrls[previewIndex];
const q = useQuery({
queryKey: ['handover-detail', record?.id],
queryFn: () =>
staffHandoverApi.getStaffHandoverDetail<Record<string, unknown>>({ id: record?.id }),
enabled: Boolean(record),
});
const data = q.data ?? {};
const assets = (data.details as Record<string, unknown>[]) ?? [];
const columns = [
['评估单号', 'evalOrderNo'],
['门店', 'sellerMerchantName'],
['车型', 'carModel'],
['车牌', 'licensePlate'],
].map(([title, dataIndex]): DataTableColumn<Record<string, unknown>> => ({
title,
dataIndex,
width: 160,
line: 1,
render: text,
}));
columns.push(
{
title: '当时协议状态',
dataIndex: 'signCustodyStatus',
width: 130,
render: (v: unknown) => (v ? '已签署' : '未签署'),
},
{
title: '凭证',
dataIndex: 'proofUrls',
width: 130,
render: (v: unknown) =>
Array.isArray(v) && v.length ? (
<UButton
type="link"
onClick={() => {
setPreviewUrls(v.map(String));
setPreviewIndex(0);
}}
>
查看凭证
</UButton>
) : (
'-'
),
},
);
return (
<UDrawer
open={Boolean(record)}
title="交接详情"
size={1000}
onClose={onClose}
styles={{
body: {
padding: 16,
background: 'var(--uj-bg)',
display: 'flex',
flexDirection: 'column',
gap: 'var(--uj-space-module)',
},
}}
>
{q.isError ? (
<UAlert type="error" showIcon title="详情加载失败" description={errorDetail(q.error)} />
) : null}
<UCard className="uc-detail-card" loading={q.isPending}>
<div className="uc-detail-dossier">
<div className="uc-detail-dossier__identity">
<div className="uc-detail-dossier__name">交接批次 {text(data.handoverBatchNo)}</div>
</div>
<div className="uc-detail-dossier__meta">
<MetaItem label="操作时间">{text(data.handoverTime)}</MetaItem>
<MetaItem label="操作人">{text(data.createdBy)}</MetaItem>
</div>
</div>
</UCard>
<UCard className="uc-detail-card">
<CardHead title="待交接资产" aux={`共 ${assets.length} 项`} />
<div className="uc-detail-card__body">
<DataTable<Record<string, unknown>>
rowKey="evalOrderNo"
columns={columns}
dataSource={assets}
loading={q.isPending || q.isFetching}
pagination={false}
/>
</div>
</UCard>
{previewUrl ? (
<div className="uc-handover-image-viewer" onClick={() => setPreviewUrls([])}>
<div
className="uc-handover-image-viewer__content"
onClick={(event) => event.stopPropagation()}
>
{previewUrls.length > 1 ? (
<UButton
className="uc-handover-image-viewer__arrow uc-handover-image-viewer__arrow--left"
disabled={previewIndex === 0}
onClick={() => setPreviewIndex((x) => x - 1)}
>
‹
</UButton>
) : null}
{previewUrl.split('?')[0].toLowerCase().endsWith('.pdf') ? (
<iframe className="uc-handover-proof-preview" src={previewUrl} title="交接凭证" />
) : (
<UImage
src={previewUrl}
preview={false}
className="uc-handover-image-viewer__image"
/>
)}
{previewUrls.length > 1 ? (
<UButton
className="uc-handover-image-viewer__arrow uc-handover-image-viewer__arrow--right"
disabled={previewIndex === previewUrls.length - 1}
onClick={() => setPreviewIndex((x) => x + 1)}
>
›
</UButton>
) : null}
</div>
</div>
) : null}
</UDrawer>
);
}
function CardHead({ title, aux }: { title: string; aux?: string }) {
return (
<div className="uc-detail-card__head">
<h2 className="uc-detail-card__title">{title}</h2>
{aux ? <span className="uc-detail-card__aux">{aux}</span> : null}
</div>
);
}
function MetaItem({ label, children }: { label: string; children: ReactNode }) {
return (
<div className="uc-detail-dossier__item">
<span className="uc-detail-dossier__label">{label}</span>
<span className="uc-detail-dossier__value">{children}</span>
</div>
);
}