HandoverDetailModal.tsx
4.26 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
import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { UAlert, UButton, UImage, UModal } from '@uj/ui';
import { CombiForm, DataTable, type DataTableColumn, type FieldSchema } 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));
const detailFields = (items: Array<[string, string]>): FieldSchema<Record<string, unknown>>[] =>
items.map(([name, label]) => ({ name, label, type: 'input', render: text }));
export default function HandoverDetailModal({
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 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 (
<UModal open={Boolean(record)} title="详情" width={1080} footer={null} onCancel={onClose}>
<CombiForm
mode="detail"
detailColumns={3}
labelWidth={128}
fields={detailFields([
['handoverBatchNo', '交接批次号'],
['handoverTime', '操作时间'],
['createdBy', '操作人'],
])}
initialValues={data}
/>
<h3>待交接资产列表</h3>
{q.isError ? (
<UAlert type="error" showIcon title="详情加载失败" description={errorDetail(q.error)} />
) : (
<DataTable<Record<string, unknown>>
rowKey="evalOrderNo"
columns={columns}
dataSource={(data.details as Record<string, unknown>[]) ?? []}
pagination={false}
/>
)}
{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}
</UModal>
);
}