Files
zkxw/web-admin/src/utils/sample-freight-flatten.ts
T
zlwuandCursor db31990ebe feat: 细胞存储缴费催缴、统一样本信息与协议支付能力增强
汇总近期业务改动:催缴菜单与后端、样本信息快捷登记与进度、运费关联、客户档案扩展、协议优惠/期次与押金划转,并同步 SQL 迁移与管理端页面收敛。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 21:20:37 +08:00

99 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 }
}