oa_front/src/views/meterials-inventory/columns.tsx

128 lines
3.0 KiB
TypeScript
Raw Normal View History

2024-03-04 09:59:48 +08:00
import type { TableColumn } from '@/components/core/dynamic-table';
import { ContractStatusEnum } from '@/enums/contractEnum';
import { formatToDate } from '@/utils/dateUtil';
import { Tag, Button } from 'ant-design-vue';
export type TableListItem = API.ContractEntity;
export type TableColumnItem = TableColumn<TableListItem>;
export const baseColumns = (ctx: {
contractTypes: API.DictItemEntity[];
dynamicTableInstance;
}): TableColumnItem[] => {
const { contractTypes } = ctx;
return [
{
title: '编号',
width: 100,
maxWidth: 100,
fixed: 'left',
dataIndex: 'contractNumber',
},
{
title: '标题',
width: 180,
dataIndex: 'title',
},
{
title: '类型',
width: 80,
formItemProps: {
component: 'Select',
componentProps: {
options: contractTypes.map(({ label, id }) => ({ value: id, label })),
},
},
dataIndex: 'type',
customRender: ({ record }) => {
return contractTypes?.length
? contractTypes.find((item) => item.id === record.type)?.label || ''
: '';
},
},
{
title: '甲方',
width: 120,
dataIndex: 'partyA',
},
{
title: '乙方',
width: 120,
dataIndex: 'partyB',
},
{
title: '签订时间',
width: 60,
maxWidth: 60,
hideInSearch: true,
dataIndex: 'signingDate',
customRender: ({ record }) => {
return formatToDate(record.signingDate);
},
},
{
title: '交付期限',
width: 60,
maxWidth: 60,
hideInSearch: true,
dataIndex: 'deliveryDeadline',
customRender: ({ record }) => {
return formatToDate(record.deliveryDeadline);
},
},
{
title: '审核结果',
dataIndex: 'status',
maxWidth: 60,
width: 60,
fixed:'right',
formItemProps: {
component: 'Select',
componentProps: {
options: Object.values(ContractStatusEnum)
.filter((value) => typeof value === 'number')
.map((item) => formatStatus(item as ContractStatusEnum)),
},
},
customRender: ({ record }) => {
const { color, label } = formatStatus(record.status);
return <Tag color={color}>{label}</Tag>;
},
},
];
};
export function formatStatus(status: ContractStatusEnum): {
color: string;
label: string;
value: number;
} {
switch (status) {
case ContractStatusEnum.Pending:
return {
color: '#ccc',
label: '待审核',
value: ContractStatusEnum.Pending,
};
case ContractStatusEnum.Approved:
return {
color: 'green',
label: '已通过',
value: ContractStatusEnum.Approved,
};
case ContractStatusEnum.Rejected:
return {
color: 'red',
label: '已拒绝',
value: ContractStatusEnum.Rejected,
};
default:
return {
color: '#ccc',
label: '待审核',
value: ContractStatusEnum.Pending,
};
}
}