Files
zkxw/web-admin/src/views/cell-storage/sample-freight/index.vue
T
zlwuandCursor 0b4c8dfda8 feat(sample): 展示样本状态并支持样本废弃与作废原因
生产/质检入库卡片展示样本状态并支持【样本废弃】;市场 Web 列表与移动市场部卡片补充样本状态及问号查看作废原因;样本表新增 void_desc,人工作废不联动接收但全部作废时自动作废协议(#131)。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-19 14:25:24 +08:00

596 lines
19 KiB
Vue
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.
<!-- eslint-disable vue/no-v-model-argument -->
<template>
<div class="page-container">
<section class="panel">
<div class="panel-top">
<h2 class="title-bar-heading">运费信息</h2>
</div>
<div class="filter-block">
<el-form :model="searchForm" class="filter-form" @submit.prevent>
<div class="filter-grid">
<el-form-item label="关键词">
<el-input
v-model="searchForm.keyword"
placeholder="批次号/运输方式/样本编码"
clearable
/>
</el-form-item>
<el-form-item label="运输方式">
<el-select
v-model="searchForm.transportMode"
placeholder="全部"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="opt in transportModeOptions"
:key="opt.value"
:label="opt.label"
:value="opt.value"
/>
</el-select>
</el-form-item>
<el-form-item label="样本来源">
<el-select
v-model="searchForm.sampleSource"
placeholder="全部"
clearable
style="width: 100%"
>
<el-option label="细胞存储" value="cell_storage" />
<el-option label="科研捐赠" value="research_donation" />
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="searchForm.createTimeRange"
type="daterange"
value-format="YYYY-MM-DD"
start-placeholder="开始日期"
end-placeholder="结束日期"
style="width: 100%"
/>
</el-form-item>
</div>
<div class="filter-actions-row">
<div class="filter-actions-end">
<el-button class="btn-ghost" @click="handleReset">
<el-icon><RefreshLeft /></el-icon>
重置
</el-button>
<el-button class="btn-main" type="primary" @click="handleSearch">
<el-icon><Search /></el-icon>
搜索
</el-button>
</div>
</div>
</el-form>
</div>
<div class="list-toolbar">
<div class="list-toolbar-row">
<div class="list-toolbar-selected">
已选 <span class="sel-num">{{ selectedFreightIds.length }}</span> 项
</div>
<el-button class="btn-main" type="primary" @click="openConfig">
<el-icon><Plus /></el-icon>
配置运费
</el-button>
<el-button
class="btn-ghost"
:disabled="selectedFreightIds.length === 0"
@click="handleBatchUnlink"
>
<el-icon><Link /></el-icon>
取消样本关联
</el-button>
</div>
</div>
<div class="list-body list-wrap">
<el-table
class="list-table freight-batch-table"
:data="flatRows"
v-loading="loading"
row-key="rowKey"
:span-method="spanMethod"
:row-class-name="freightBatchRowClassName"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
prop="selection"
min-width="48"
align="center"
header-align="center"
:selectable="(row: FlatRow) => row.isFirst && row.freight.settleStatus !== 'yjs'"
/>
<el-table-column
prop="batchNo"
label="批次号"
min-width="160"
align="center"
header-align="center"
show-overflow-tooltip
/>
<el-table-column
prop="transportMode"
label="运输方式"
min-width="120"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag
v-if="row.transportMode || row.transportModeLabel"
:type="transportTypeTagType(String(row.transportMode || ''))"
size="small"
>
{{
row.transportModeLabel ||
transportTypeLabel(String(row.transportMode || '')) ||
'—'
}}
</el-tag>
<span v-else class="muted">—</span>
</template>
</el-table-column>
<el-table-column
prop="freightAmount"
label="运费(元)"
min-width="110"
align="right"
header-align="center"
>
<template #default="{ row }">{{
isSfExpress(row.transportMode) &&
(row.freightAmount == null || row.freightAmount === '')
? '月结'
: row.freightAmount != null &&
row.freightAmount !== '' &&
Number.isFinite(Number(row.freightAmount))
? '¥' + formatMoneyDisplay(row.freightAmount)
: '—'
}}</template>
</el-table-column>
<el-table-column
prop="linkedSampleCount"
label="关联数"
min-width="80"
align="center"
header-align="center"
/>
<el-table-column label="来源" min-width="100" align="center" header-align="center">
<template #default="{ row }">
<el-tag
v-if="row.sampleSource"
:type="receptionSourceTagType(String(row.sampleSource || ''))"
size="small"
>
{{ receptionSourceLabel(String(row.sampleSource || '')) }}
</el-tag>
<span v-else class="muted">—</span>
</template>
</el-table-column>
<el-table-column
prop="motherName"
label="母亲姓名"
min-width="100"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.motherName || '—' }}</template>
</el-table-column>
<el-table-column
prop="newbornName"
label="子女姓名"
min-width="100"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.newbornName || '—' }}</template>
</el-table-column>
<el-table-column
prop="sampleCode"
label="样本编码"
min-width="120"
class-name="freight-cell-wrap"
align="center"
header-align="center"
>
<template #default="{ row }">
<span class="cell-wrap-text">{{ row.sampleCode || '—' }}</span>
</template>
</el-table-column>
<el-table-column label="样本状态" min-width="140" align="center" header-align="center">
<template #default="{ row }">
<SampleStatusTag :status="row.sampleStatus" :void-desc="row.voidDesc" />
</template>
</el-table-column>
<el-table-column
prop="sampleTypeName"
label="样本类型"
min-width="110"
class-name="freight-cell-wrap"
align="center"
header-align="center"
>
<template #default="{ row }">
<span class="cell-wrap-text">{{ row.sampleTypeName || '—' }}</span>
</template>
</el-table-column>
<el-table-column
prop="createByName"
label="创建人"
min-width="100"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.createByName || row.createBy || '—' }}</template>
</el-table-column>
<el-table-column
prop="createTime"
label="创建时间"
min-width="170"
align="center"
header-align="center"
>
<template #default="{ row }">{{ formatDisplayOrDash(row.createTime) }}</template>
</el-table-column>
<el-table-column
prop="actions"
label="操作"
min-width="280"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<div v-if="row.isFirst && row.freight.settleStatus !== 'yjs'" class="op-row">
<el-button class="btn-op-item" @click="openEditById(row.freightId)">
<el-icon><Edit /></el-icon>
编辑
</el-button>
<el-button class="btn-op-item" @click="openUnlinkDialog(row.freightId)">
<el-icon><Link /></el-icon>
取消样本关联
</el-button>
<el-button class="btn-op-item" type="danger" plain @click="handleDelete(row)">
<el-icon><Delete /></el-icon>
删除
</el-button>
</div>
</template>
</el-table-column>
</el-table>
<div class="pagination list-pager-bar">
<el-pagination
:current-page="pagination.page"
:page-size="pagination.pageSize"
:total="pagination.total"
:page-sizes="[10, 20, 50]"
layout="total, sizes, prev, pager, next"
@size-change="(val) => ((pagination.page = 1), (pagination.pageSize = val), loadData())"
@current-change="(val) => ((pagination.page = val), loadData())"
/>
</div>
</div>
</section>
<FreightConfigDialog ref="configDialogRef" @success="loadData" />
<FreightEditDialog ref="editDialogRef" @success="loadData" />
<FreightUnlinkDialog
v-model="unlinkVisible"
title="取消样本关联"
hint="勾选要取消关联的样本:"
empty-warning="请勾选要取消关联的样本"
:items="unlinkDialogItems"
:default-selected-keys="unlinkDefaultKeys"
:submitting="unlinkSubmitting"
@confirm="confirmUnlinkFromDialog"
/>
</div>
</template>
<script setup lang="ts">
import { Delete, Edit, Link, Plus, RefreshLeft, Search } from '@element-plus/icons-vue'
import { fetchDictDataOptions } from '@/api/admin'
import {
fetchDeleteSampleFreight,
fetchSampleFreightDetail,
fetchSampleFreightList,
fetchUnlinkSampleFreight,
type SampleFreight
} from '@/api/sample-freight'
import FreightUnlinkDialog, {
type FreightUnlinkRow
} from '@/components/business/freight-unlink-dialog/index.vue'
import { formatDisplayOrDash } from '@/utils/datetime-display'
import { formatMoneyDisplay } from '@/utils/money-format'
import { isSfExpress } from '@/utils/sf-express-freight'
import {
receptionSourceLabel,
receptionSourceTagType,
transportTypeLabel,
transportTypeTagType
} from '@/utils/status-tag-registry'
import {
flattenSampleFreights,
sampleFreightSpanMethod,
type SampleFreightFlatRow
} from '@/utils/sample-freight-flatten'
import SampleStatusTag from '@/components/business/sample-status-tag/index.vue'
import FreightConfigDialog from './FreightConfigDialog.vue'
import FreightEditDialog from './FreightEditDialog.vue'
defineOptions({ name: 'CellStorageSampleFreight' })
type FlatRow = SampleFreightFlatRow
const loading = ref(false)
const flatRows = ref<FlatRow[]>([])
const freightMap = ref<Record<string, SampleFreight>>({})
const selectedFreightIds = ref<string[]>([])
const transportModeOptions = ref<Array<{ label: string; value: string }>>([])
const configDialogRef = ref<InstanceType<typeof FreightConfigDialog>>()
const editDialogRef = ref<InstanceType<typeof FreightEditDialog>>()
const unlinkVisible = ref(false)
const unlinkDialogItems = ref<FreightUnlinkRow[]>([])
const unlinkDefaultKeys = ref<string[]>([])
const unlinkSubmitting = ref(false)
const searchForm = reactive({
keyword: '',
transportMode: '',
sampleSource: '',
createTimeRange: null as [string, string] | null
})
const pagination = reactive({
page: 1,
pageSize: 10,
total: 0
})
function flattenFreights(list: SampleFreight[]): FlatRow[] {
return flattenSampleFreights(list)
}
function spanMethod(args: { column: any; row: FlatRow }) {
return sampleFreightSpanMethod(args)
}
function freightBatchRowClassName({ row }: { row: FlatRow }) {
return row.batchIndex % 2 === 0 ? 'freight-batch-odd' : 'freight-batch-even'
}
async function loadTransportModeOptions() {
try {
const res = await fetchDictDataOptions('sample_transport_mode')
const list = Array.isArray(res) ? res : (res as any)?.data || []
transportModeOptions.value = list.map((x: any) => ({
label: x.label || x.dictLabel || x.value || x.dictValue,
value: x.value || x.dictValue
}))
} catch {
transportModeOptions.value = []
}
}
async function loadData() {
loading.value = true
try {
const [from, to] = searchForm.createTimeRange || [undefined, undefined]
const res = await fetchSampleFreightList({
page: pagination.page,
pageSize: pagination.pageSize,
keyword: searchForm.keyword || undefined,
transportMode: searchForm.transportMode || undefined,
sampleSource: searchForm.sampleSource || undefined,
createTimeFrom: from,
createTimeTo: to,
includeItems: true
})
const data = (res as any)?.data || res
const list = (data?.list || []) as SampleFreight[]
pagination.total = data?.total || 0
const map: Record<string, SampleFreight> = {}
list.forEach((f) => {
map[f.id] = f
})
freightMap.value = map
flatRows.value = flattenFreights(list)
selectedFreightIds.value = []
} catch {
flatRows.value = []
pagination.total = 0
} finally {
loading.value = false
}
}
function handleSearch() {
pagination.page = 1
loadData()
}
function handleReset() {
searchForm.keyword = ''
searchForm.transportMode = ''
searchForm.sampleSource = ''
searchForm.createTimeRange = null
handleSearch()
}
function handleSelectionChange(rows: FlatRow[]) {
const ids = Array.from(new Set(rows.filter((r) => r.isFirst).map((r) => r.freightId)))
selectedFreightIds.value = ids
}
function openConfig() {
configDialogRef.value?.open()
}
function openEditById(freightId: string) {
const f = freightMap.value[freightId]
if (!f) {
ElMessage.warning('运费批次不存在或已刷新,请重试')
return
}
editDialogRef.value?.open(f)
}
function handleDelete(row: FlatRow) {
const freightId = String(row.freightId || '').trim()
if (!freightId) return
const batchNo = String(row.batchNo || freightId).trim()
const linked = Number(row.linkedSampleCount || 0)
const linkHint =
linked > 0 ? `将解除其全部 ${linked} 条关联样本,并删除该运费单。` : '将删除该运费单。'
ElMessageBox.confirm(`确认删除运费批次「${batchNo}」吗?${linkHint}`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
.then(async () => {
await fetchDeleteSampleFreight(freightId)
await loadData()
})
.catch(() => undefined)
}
function toUnlinkRow(
it: NonNullable<SampleFreight['items']>[number],
freightId: string
): FreightUnlinkRow {
return {
...it,
freightId,
rowKey: `${it.sampleSource}:${it.sampleId}`
}
}
async function openUnlinkDialog(freightId: string) {
try {
const res = await fetchSampleFreightDetail(freightId)
const data = ((res as any)?.data || res) as SampleFreight
unlinkDialogItems.value = (data.items || []).map((it) => toUnlinkRow(it, freightId))
unlinkDefaultKeys.value = unlinkDialogItems.value.map((r) => r.rowKey)
unlinkVisible.value = true
} catch {
ElMessage.error('加载关联样本失败')
}
}
async function confirmUnlinkFromDialog(rows: FreightUnlinkRow[]) {
unlinkSubmitting.value = true
try {
const byFreight = new Map<string, FreightUnlinkRow[]>()
for (const row of rows) {
const fid = String(row.freightId || '').trim()
if (!fid) continue
if (!byFreight.has(fid)) byFreight.set(fid, [])
byFreight.get(fid)!.push(row)
}
for (const [fid, list] of byFreight) {
await fetchUnlinkSampleFreight(
fid,
list.map((x) => ({
sampleSource: x.sampleSource,
sampleId: x.sampleId,
protocolId: x.protocolId,
sampleCode: x.sampleCode
}))
)
}
unlinkVisible.value = false
await loadData()
} catch (e: any) {
ElMessage.error(e?.message || '取消样本关联失败')
} finally {
unlinkSubmitting.value = false
}
}
async function handleBatchUnlink() {
if (!selectedFreightIds.value.length) return
loading.value = true
try {
const byKey = new Map<string, FreightUnlinkRow>()
for (const id of selectedFreightIds.value) {
const res = await fetchSampleFreightDetail(id)
const data = ((res as any)?.data || res) as SampleFreight
for (const it of data.items || []) {
const row = toUnlinkRow(it, id)
byKey.set(row.rowKey, row)
}
}
unlinkDialogItems.value = [...byKey.values()]
unlinkDefaultKeys.value = unlinkDialogItems.value.map((r) => r.rowKey)
if (!unlinkDialogItems.value.length) {
ElMessage.warning('所选运费下没有关联样本')
return
}
unlinkVisible.value = true
} catch {
ElMessage.error('加载关联样本失败')
} finally {
loading.value = false
}
}
onMounted(async () => {
await loadTransportModeOptions()
await loadData()
})
</script>
<style scoped lang="scss">
.op-row {
display: flex;
justify-content: center;
gap: 8px;
}
.muted {
color: var(--mint-text-muted, #64748b);
}
/* 按运费批次交替底色(同批次多样本行同色) */
:deep(.freight-batch-table) {
.el-table__body tr.freight-batch-even > td.el-table__cell {
background-color: var(--el-fill-color-lighter);
}
.el-table__body tr.freight-batch-odd > td.el-table__cell {
background-color: var(--el-bg-color);
}
.el-table__body tr.freight-batch-even:hover > td.el-table__cell,
.el-table__body tr.freight-batch-odd:hover > td.el-table__cell {
background-color: var(--el-table-row-hover-bg-color);
}
td.freight-cell-wrap .cell {
white-space: normal;
word-break: break-word;
line-height: 1.45;
}
}
.cell-wrap-text {
display: inline-block;
max-width: 100%;
white-space: normal;
word-break: break-word;
line-height: 1.45;
}
</style>