Commit d62b975c by chenwq

优化合同详情页面,重构字段展示方式,增加字段前后缀处理,调整样式以适应不同屏幕

1 parent 0be59775
import { useState, type ReactNode } from 'react';
import { useMutation, useQuery } from '@tanstack/react-query';
import {
UAlert,
UButton,
UCard,
UDescriptions,
UEmpty,
UInput,
UResult,
UTable,
UTag,
useUMessage,
} from '@uj/ui';
import { PageShell } from '@/components';
import { UAlert, UButton, UCard, UEmpty, UInput, UResult, UTable, UTag, useUMessage } from '@uj/ui';
import { CombiForm, PageShell, type FieldSchema } from '@/components';
import { downloadCenter } from '@uj/platform-sdk';
import { useAccess } from '@/access';
import { contractApi, type ContractDetail as Detail, type ContractOaAudit } from '@/api';
......@@ -80,6 +69,22 @@ export default function ContractDetail({ params }: { params: PageParams }) {
const oaAudits = Array.isArray(data.oaAudits) ? data.oaAudits : [];
const fieldItems = Array.isArray(data.fieldItems) ? data.fieldItems : [];
const logs = Array.isArray(data.logs) ? data.logs : [];
const contractInfoFields: FieldSchema<Detail>[] = [
{
name: 'electronicContractType',
label: '合同类型',
type: 'input',
render: (value) => dictValue(DICT.contractType, value),
},
{ name: 'carTypeName', label: '合同车型', type: 'input', render: () => contractModel(data) },
{ name: 'docTemplateName', label: '合同模板', type: 'input', render: display },
{
name: 'contractPrice',
label: '合同金额',
type: 'input',
detailPrefix: '¥',
},
];
const payColumns = [
{
......@@ -96,10 +101,7 @@ export default function ContractDetail({ params }: { params: PageParams }) {
},
{
title: '支付金额',
render: (row: ContractOaAudit) =>
row.paymentAmount === undefined || row.paymentAmount === ''
? '-'
: `¥${String(row.paymentAmount)}`,
render: (row: ContractOaAudit) => displayAmount(row.paymentAmount),
},
{ title: '企微审批单号', dataIndex: 'oaFlowCode', render: display },
{
......@@ -157,11 +159,7 @@ export default function ContractDetail({ params }: { params: PageParams }) {
<MetaItem label="付款方式">
{dictValue(DICT.paymentMethod, data.paymentMethod)}
</MetaItem>
<MetaItem label="合同金额">
{data.contractPrice === undefined || data.contractPrice === ''
? '-'
: `¥${String(data.contractPrice)}`}
</MetaItem>
<MetaItem label="合同金额">{displayAmount(data.contractPrice)}</MetaItem>
</div>
</div>
</UCard>
......@@ -191,27 +189,12 @@ export default function ContractDetail({ params }: { params: PageParams }) {
<UCard className="uc-detail-card" loading={detail.isPending}>
<CardHead title="合同信息" />
<div className="uc-detail-card__body">
<UDescriptions
className="uc-detail-descriptions"
column={{ xs: 1, sm: 2 }}
styles={{ label: { width: 112, whiteSpace: 'nowrap' } }}
items={[
{
key: 'type',
label: '合同类型',
children: dictValue(DICT.contractType, data.electronicContractType),
},
{ key: 'model', label: '合同车型', children: contractModel(data) },
{ key: 'template', label: '合同模板', children: display(data.docTemplateName) },
{
key: 'price',
label: '合同金额',
children:
data.contractPrice === undefined || data.contractPrice === ''
? '-'
: `¥${String(data.contractPrice)}`,
},
]}
<CombiForm
mode="detail"
fields={contractInfoFields}
initialValues={data}
detailColumns={2}
labelWidth={112}
/>
<div className="uc-contract-desc">
<span className="uc-contract-desc__label">合同描述</span>
......@@ -315,21 +298,28 @@ export default function ContractDetail({ params }: { params: PageParams }) {
{side === 1 ? '甲方' : '乙方'}
<span className="uc-contract-signer__type">{signerTypeName(data, side)}</span>
</div>
<UDescriptions
className="uc-detail-descriptions"
column={1}
styles={{ label: { width: 110, whiteSpace: 'nowrap' } }}
items={SIGNER_FIELDS.map((field) => {
let value: string;
if (field.kind === 'side') value = side === 1 ? '甲方' : '乙方';
else if (field.kind === 'type') value = signerTypeName(data, side);
else if (field.kind === 'idType') value = '身份证/营业执照';
else {
const key = side === 1 ? field.keyA : field.keyB;
value = display(key ? signers[key] : undefined);
}
return { key: field.title, label: field.title, children: value };
})}
<CombiForm
mode="detail"
detailColumns={1}
labelWidth={110}
initialValues={Object.fromEntries(
SIGNER_FIELDS.map((field) => {
let value: string;
if (field.kind === 'side') value = side === 1 ? '甲方' : '乙方';
else if (field.kind === 'type') value = signerTypeName(data, side);
else if (field.kind === 'idType') value = '身份证/营业执照';
else {
const key = side === 1 ? field.keyA : field.keyB;
value = display(key ? signers[key] : undefined);
}
return [field.title, value];
}),
)}
fields={SIGNER_FIELDS.map((field) => ({
name: field.title,
label: field.title,
type: 'input',
}))}
/>
</div>
))}
......@@ -392,3 +382,7 @@ function MetaItem({ label, children }: { label: string; children: ReactNode }) {
</div>
);
}
function displayAmount(value: unknown): string {
return value === undefined || value === null || value === '' ? '-' : `¥${String(value)}`;
}
......@@ -24,6 +24,7 @@
}
.uc-contract-fields {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.uc-contract-field {
......@@ -89,6 +90,9 @@
border-radius: var(--uj-radius-sm);
}
@media (max-width: 900px) {
.uc-contract-fields {
grid-template-columns: 1fr;
}
.uc-contract-signers {
grid-template-columns: 1fr;
}
......
......@@ -62,7 +62,12 @@ export function CombiForm<T extends Record<string, unknown>>({
label: field.label,
children: field.render
? field.render(data[field.name], data)
: String(data[field.name] ?? '—'),
: formatDetailValue(
data[field.name],
field.detailPrefix,
field.detailSuffix,
field.emptyValueAsDash,
),
}))}
/>
);
......@@ -147,6 +152,24 @@ export function CombiForm<T extends Record<string, unknown>>({
);
}
function formatDetailValue(
value: unknown,
prefix?: ReactNode,
suffix?: ReactNode,
emptyValueAsDash = true,
): ReactNode {
if (value === undefined || value === null || value === '') {
return emptyValueAsDash ? '-' : String(value ?? '—');
}
return (
<>
{prefix}
{String(value)}
{suffix}
</>
);
}
function inputPlaceholder<T extends Record<string, unknown>>(field: FieldSchema<T>): string {
if (field.placeholder) return field.placeholder;
return `请输入${typeof field.label === 'string' ? field.label : '内容'}`;
......
......@@ -61,6 +61,11 @@ export interface FieldSchema<T extends Record<string, unknown> = Record<string,
*/
countsAsFilter?: boolean;
itemStyle?: CSSProperties;
/** 详情模式值的前缀与后缀;值为空时统一显示“-”。 */
detailPrefix?: ReactNode;
detailSuffix?: ReactNode;
/** 空值是否显示“-”;默认开启,设为 false 时保留原来的空值展示。 */
emptyValueAsDash?: boolean;
/** input 类型的扩展属性,如最大长度、数字键盘等。 */
inputProps?: InputProps;
/** textarea 类型的扩展属性。 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!