Files
zkxw/mobile-oa-h5/src/market/modules/freight.js
T
2026-10-14 12:32:03 +08:00

91 lines
3.7 KiB
JavaScript

const SOURCE_LABELS = Object.freeze({ cell_storage: '细胞存储', research_donation: '科研捐赠' })
function dictionaryLabel(map, code, providedLabel) {
const label = String(providedLabel || '').trim()
const key = String(code || '').trim()
if (label && label !== key) return label
return map[key] || (key ? '未知' : '—')
}
function person(name, id) {
const displayName = String(name || '').trim()
const referenceId = String(id || '').trim()
if (displayName && displayName !== referenceId) return displayName
return referenceId ? '未知人员' : '—'
}
function money(value) {
const amount = Number(value)
if (!Number.isFinite(amount)) return '—'
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
}
export default {
key: 'freight',
resource: 'freights',
actions: {
specialist: ['view', 'create', 'edit', 'link', 'unlink'],
manager: ['view', 'create', 'edit', 'link', 'unlink']
},
listParams: ({ status } = {}) => ({ transportMode: status || '', includeItems: true }),
statusOptions: [{ text: '全部运输方式', value: '' }],
filterFields: [
{ key: 'transportMode', label: '运输方式', type: 'select', optionKey: 'transportModes' },
{
key: 'sampleSource', label: '样本来源', type: 'select', options: [
{ text: '细胞存储', value: 'cell_storage' },
{ text: '科研捐赠', value: 'research_donation' }
]
},
{ key: 'createTimeRange', label: '创建时间', type: 'date-range' }
],
detailSections(detail) {
return [
{
key: 'base',
title: '运费信息',
fields: [
{ label: '批次号', value: detail?.freightNo || '—' },
{ label: '运输方式', value: dictionaryLabel({}, detail?.transportMode, detail?.transportModeLabel), tag: true, tagType: 'primary' },
{ label: '运费金额', value: money(detail?.freightAmount) },
{ label: '关联数', value: String(detail?.visibleItemCount ?? detail?.items?.length ?? 0) },
{ label: '创建人', value: person(detail?.creatorName || detail?.createByName, detail?.createBy) },
{ label: '创建时间', value: detail?.createTime || '—' },
{ label: '更新时间', value: detail?.updateTime || '—' },
{ label: '备注', value: detail?.remark || '—' }
],
cards: []
},
{
key: 'items',
title: '关联样本',
fields: [],
cards: (detail?.items || []).map((item, index) => ({
key: String(item?.id || `item-${index}`),
title: item?.sampleCode || `样本 ${index + 1}`,
statusText: dictionaryLabel(SOURCE_LABELS, item?.sampleSource),
fields: [
{ label: '来源', value: dictionaryLabel(SOURCE_LABELS, item?.sampleSource) },
{ label: '协议单号', value: item?.protocolNo || '—' },
{ label: '样本编码', value: item?.sampleCode || '—' },
{ label: '样本类型', value: item?.sampleTypeName || '—' },
{ label: '母亲姓名', value: item?.motherName || '—' },
{ label: '子女姓名', value: item?.newbornName || '—' }
]
}))
}
]
},
usesPagedSampleOptions(action) {
return ['create', 'link'].includes(action)
},
sampleOptions(action, detailItems, optionRows) {
if (action === 'unlink') return Array.isArray(detailItems) ? detailItems : []
return Array.isArray(optionRows) ? optionRows : []
},
formSections: [{ key: 'base', title: '运费批次', fields: [
{ key: 'transportMode', label: '运输方式', type: 'select', optionKey: 'transportModes', required: true },
{ key: 'freightAmount', label: '运费金额', type: 'number', required: true }
] }]
}