import type { SampleFreight } from '@/api/sample-freight' export type SampleFreightFlatRow = { rowKey: string freightId: string /** 当前列表内批次序号(从 0 起,用于斑马纹) */ batchIndex: number /** 运费批次号 YF+YYYYMMDD+001~999 */ batchNo: string rowspan: number isFirst: boolean transportMode: string transportModeLabel: string freightAmount: number linkedSampleCount: number createBy?: string createByName?: string createTime: string sampleSource?: string protocolNo?: string motherName?: string newbornName?: string sampleCode?: string sampleTypeName?: string sampleId?: string protocolId?: string /** 原始批次,选中时回传 */ freight: SampleFreight } export function flattenSampleFreights(list: SampleFreight[]): SampleFreightFlatRow[] { const rows: SampleFreightFlatRow[] = [] list.forEach((f, batchIndex) => { const items = f.items?.length ? f.items : [null] const batchNo = (f.freightNo || '').trim() || '—' items.forEach((it, idx) => { rows.push({ rowKey: `${f.id}|${it?.sampleId || idx}`, freightId: f.id, batchIndex, batchNo, rowspan: idx === 0 ? items.length : 0, isFirst: idx === 0, transportMode: f.transportMode, transportModeLabel: f.transportModeLabel || f.transportMode, freightAmount: f.freightAmount, linkedSampleCount: f.linkedSampleCount ?? (f.items?.length || 0), createBy: f.createBy || '', createByName: f.createByName || f.createBy || '', createTime: f.createTime || '', sampleSource: it?.sampleSource, protocolNo: it?.protocolNo, motherName: it?.motherName, newbornName: it?.newbornName, sampleCode: it?.sampleCode, sampleTypeName: it?.sampleTypeName, sampleId: it?.sampleId, protocolId: it?.protocolId, freight: f }) }) }) return rows } const DEFAULT_MERGE_PROPS = new Set([ 'selection', 'radio', 'batchNo', 'transportMode', 'freightAmount', 'linkedSampleCount', 'createByName', 'createTime', 'actions' ]) export function sampleFreightSpanMethod( { column, row }: { column: { type?: string; property?: string } row: SampleFreightFlatRow }, extraMergeProps: string[] = [] ): { rowspan: number; colspan: number } { const mergeProps = extraMergeProps.length > 0 ? new Set([...DEFAULT_MERGE_PROPS, ...extraMergeProps]) : DEFAULT_MERGE_PROPS const prop = column.type === 'selection' ? 'selection' : column.property || '' if (mergeProps.has(prop)) { if (row.rowspan > 0) return { rowspan: row.rowspan, colspan: 1 } return { rowspan: 0, colspan: 0 } } return { rowspan: 1, colspan: 1 } }