feat(web-admin): add sample freight menu list with configure dialogs

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-10-08 10:02:15 +08:00
1 parent 86ba0c2cd0
commit 26fd37e6f9
4 files changed
+1037 -3

No files matched your search

+1
View File
@@ -77,6 +77,7 @@
[/(SOP)/i, 'auto-title-file'],
[/(捐赠|协议)/, 'auto-title-file'],
[/(缴费|退费)/, 'auto-title-calc'],
[/(运费)/, 'auto-title-calc'],
[/(接收|检查项|样本|编码)/, 'auto-title-file'],
[/(审核|记录)/, 'auto-title-file'],
[/(客户|公司|机构|医院)/, 'auto-title-user'],
@@ -0,0 +1,333 @@
<template>
<el-dialog
v-model="visible"
title="配置运费"
width="860px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
@closed="onClosed"
>
<el-radio-group v-model="mode" class="freight-mode-radio" style="margin-bottom: 12px">
<el-radio-button value="create">新建运费</el-radio-button>
<el-radio-button value="link">关联已有</el-radio-button>
</el-radio-group>
<el-form v-if="mode === 'create'" label-position="top" class="biz-dialog-form">
<div class="form-grid-2">
<el-form-item label="运输方式" required>
<el-select
v-model="form.transportMode"
placeholder="选择或输入运输方式"
filterable
allow-create
default-first-option
clearable
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="运费(元)" required>
<AmountInput v-model="form.freightAmount" :min="0" placeholder="请输入运费" />
</el-form-item>
</div>
</el-form>
<div v-else class="list-body list-wrap" style="margin-bottom: 12px">
<el-table
:data="existingFreightList"
v-loading="existingLoading"
stripe
class="list-table"
highlight-current-row
max-height="220"
@current-change="onExistingSelect"
>
<el-table-column label="运输方式" min-width="120" show-overflow-tooltip>
<template #default="{ row }">
{{ row.transportModeLabel || row.transportMode || '—' }}
</template>
</el-table-column>
<el-table-column label="运费(元)" min-width="100" align="right" header-align="center">
<template #default="{ row }">¥{{ formatMoneyDisplay(row.freightAmount) }}</template>
</el-table-column>
<el-table-column label="关联数" min-width="80" align="center" header-align="center">
<template #default="{ row }">{{ row.linkedSampleCount ?? 0 }}</template>
</el-table-column>
<el-table-column label="创建时间" min-width="160" show-overflow-tooltip>
<template #default="{ row }">{{ row.createTime || '—' }}</template>
</el-table-column>
</el-table>
</div>
<div class="sample-pick-block">
<div class="sample-pick-toolbar">
<el-select
v-model="sampleSourceFilter"
placeholder="样本来源"
clearable
style="width: 160px"
@change="reloadSampleOptions"
>
<el-option label="细胞存储" value="cell_storage" />
<el-option label="科研捐赠" value="research_donation" />
</el-select>
<el-input
v-model="sampleKeyword"
placeholder="协议单号/样本编码"
clearable
style="width: 220px"
@keyup.enter="reloadSampleOptions"
/>
<el-button class="btn-ghost" @click="reloadSampleOptions">
<el-icon><Search /></el-icon>
搜索样本
</el-button>
</div>
<el-table
:data="sampleOptions"
v-loading="sampleLoading"
stripe
class="list-table"
max-height="280"
row-key="rowKey"
@selection-change="onSampleSelectionChange"
>
<el-table-column type="selection" min-width="48" align="center" header-align="center" />
<el-table-column label="来源" min-width="100" align="center" header-align="center">
<template #default="{ row }">
<el-tag :type="row.sampleSource === 'cell_storage' ? 'success' : 'warning'" size="small">
{{ row.sampleSource === 'cell_storage' ? '细胞存储' : '科研捐赠' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="protocolNo" label="协议单号" min-width="140" show-overflow-tooltip />
<el-table-column prop="sampleCode" label="样本编码" min-width="120" show-overflow-tooltip />
<el-table-column
prop="sampleTypeName"
label="样本类型"
min-width="110"
show-overflow-tooltip
/>
<el-table-column label="已有运费" min-width="90" align="center" header-align="center">
<template #default="{ row }">
<el-tag v-if="row.freightId" type="warning" size="small">已关联</el-tag>
<span v-else class="muted">—</span>
</template>
</el-table-column>
</el-table>
</div>
<template #footer>
<el-button class="btn-ghost" @click="visible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button class="btn-main" type="primary" :loading="submitting" @click="handleSubmit">
<el-icon><Check /></el-icon>
确定
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { Check, Close, Search } from '@element-plus/icons-vue'
import AmountInput from '@/components/common/amount-input/index.vue'
import { fetchDictDataOptions } from '@/api/admin'
import { formatMoneyDisplay } from '@/utils/money-format'
import {
fetchCreateSampleFreight,
fetchLinkSampleFreight,
fetchSampleFreightList,
fetchSampleFreightSampleOptions,
type SampleFreight,
type SampleFreightItem
} from '@/api/sample-freight'
defineOptions({ name: 'FreightConfigDialog' })
const emit = defineEmits<{ success: [] }>()
type SampleOptionRow = SampleFreightItem & { rowKey: string }
const visible = ref(false)
const mode = ref<'create' | 'link'>('create')
const submitting = ref(false)
const existingLoading = ref(false)
const sampleLoading = ref(false)
const transportModeOptions = ref<Array<{ label: string; value: string }>>([])
const existingFreightList = ref<SampleFreight[]>([])
const selectedExisting = ref<SampleFreight | null>(null)
const sampleOptions = ref<SampleOptionRow[]>([])
const selectedSamples = ref<SampleOptionRow[]>([])
const sampleSourceFilter = ref<string>('')
const sampleKeyword = ref('')
const form = reactive({
transportMode: '',
freightAmount: null as number | null
})
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 = [
{ label: '顺丰快递', value: 'sfkd' },
{ label: '专线车', value: 'zxc' }
]
}
}
async function loadExistingFreights() {
existingLoading.value = true
try {
const res = await fetchSampleFreightList({ page: 1, pageSize: 50 })
const data = (res as any)?.data || res
existingFreightList.value = data?.list || []
} catch {
existingFreightList.value = []
} finally {
existingLoading.value = false
}
}
async function reloadSampleOptions() {
sampleLoading.value = true
try {
const res = await fetchSampleFreightSampleOptions({
page: 1,
pageSize: 50,
keyword: sampleKeyword.value || undefined,
sampleSource: sampleSourceFilter.value || undefined
})
const data = (res as any)?.data || res
const list = (data?.list || []) as SampleFreightItem[]
sampleOptions.value = list.map((x) => ({
...x,
rowKey: `${x.sampleSource}|${x.sampleId}`
}))
} catch {
sampleOptions.value = []
} finally {
sampleLoading.value = false
}
}
async function open() {
mode.value = 'create'
form.transportMode = ''
form.freightAmount = null
selectedExisting.value = null
selectedSamples.value = []
sampleKeyword.value = ''
sampleSourceFilter.value = ''
await Promise.all([loadTransportModeOptions(), loadExistingFreights(), reloadSampleOptions()])
visible.value = true
}
function onClosed() {
selectedSamples.value = []
selectedExisting.value = null
}
function onExistingSelect(row: SampleFreight | null) {
selectedExisting.value = row
}
function onSampleSelectionChange(rows: SampleOptionRow[]) {
selectedSamples.value = rows
}
function toItems(rows: SampleOptionRow[]): SampleFreightItem[] {
return rows.map((r) => ({
sampleSource: r.sampleSource,
sampleId: r.sampleId,
protocolId: r.protocolId,
sampleCode: r.sampleCode
}))
}
async function handleSubmit() {
if (!selectedSamples.value.length) {
ElMessage.warning('请勾选需要关联的样本')
return
}
const conflicted = selectedSamples.value.filter((s) => s.freightId)
if (conflicted.length) {
try {
await ElMessageBox.confirm(
`已选 ${conflicted.length} 个样本已有运费关联,确定将替换为本次配置?`,
'确认替换',
{ type: 'warning', confirmButtonText: '确定替换', cancelButtonText: '取消' }
)
} catch {
return
}
}
submitting.value = true
try {
if (mode.value === 'create') {
if (!form.transportMode || form.freightAmount == null) {
ElMessage.warning('请填写运输方式与运费')
return
}
const amount = Number(form.freightAmount)
if (Number.isNaN(amount) || amount < 0) {
ElMessage.warning('运费须为不小于 0 的数字')
return
}
await fetchCreateSampleFreight({
transportMode: form.transportMode,
freightAmount: amount,
items: toItems(selectedSamples.value)
})
} else {
if (!selectedExisting.value?.id) {
ElMessage.warning('请选择一笔已有运费')
return
}
await fetchLinkSampleFreight(selectedExisting.value.id, toItems(selectedSamples.value))
}
visible.value = false
emit('success')
} finally {
submitting.value = false
}
}
defineExpose({ open })
</script>
<style scoped lang="scss">
.sample-pick-block {
margin-top: 4px;
}
.sample-pick-toolbar {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 10px;
}
.muted {
color: var(--mint-text-muted, #64748b);
}
</style>
@@ -0,0 +1,150 @@
<template>
<el-dialog
v-model="visible"
title="编辑运费"
width="560px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
@closed="onClosed"
>
<p v-if="linkedCount > 0" class="edit-hint">
将同步更新关联的 {{ linkedCount }} 个样本的运输方式与运费(不影响合同金额)。
</p>
<el-form
ref="formRef"
:model="form"
:rules="rules"
label-position="top"
scroll-to-error
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
>
<div class="form-grid-2">
<el-form-item label="运输方式" prop="transportMode">
<el-select
v-model="form.transportMode"
placeholder="选择或输入运输方式"
filterable
allow-create
default-first-option
clearable
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="运费(元)" prop="freightAmount">
<AmountInput v-model="form.freightAmount" :min="0" placeholder="请输入运费" />
</el-form-item>
</div>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="visible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button class="btn-main" type="primary" :loading="submitting" @click="handleSubmit">
<el-icon><Check /></el-icon>
确定
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { Check, Close } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
import AmountInput from '@/components/common/amount-input/index.vue'
import { fetchDictDataOptions } from '@/api/admin'
import { fetchUpdateSampleFreight, type SampleFreight } from '@/api/sample-freight'
defineOptions({ name: 'FreightEditDialog' })
const emit = defineEmits<{ success: [] }>()
const visible = ref(false)
const submitting = ref(false)
const formRef = ref<FormInstance>()
const freightId = ref('')
const linkedCount = ref(0)
const transportModeOptions = ref<Array<{ label: string; value: string }>>([])
const form = reactive({
transportMode: '',
freightAmount: null as number | null
})
const rules: FormRules = {
transportMode: [{ required: true, message: '请选择运输方式', trigger: 'change' }],
freightAmount: [{ required: true, message: '请输入运费', trigger: 'blur' }]
}
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 = [
{ label: '顺丰快递', value: 'sfkd' },
{ label: '专线车', value: 'zxc' }
]
}
}
async function open(row: SampleFreight) {
freightId.value = row.id
linkedCount.value = row.linkedSampleCount ?? row.items?.length ?? 0
form.transportMode = row.transportMode || ''
form.freightAmount = row.freightAmount ?? null
await loadTransportModeOptions()
visible.value = true
}
function onClosed() {
formRef.value?.resetFields()
freightId.value = ''
linkedCount.value = 0
}
async function handleSubmit() {
if (!formRef.value) return
await formRef.value.validate()
const amount = Number(form.freightAmount)
if (Number.isNaN(amount) || amount < 0) {
ElMessage.warning('运费须为不小于 0 的数字')
return
}
submitting.value = true
try {
await fetchUpdateSampleFreight(freightId.value, {
transportMode: form.transportMode,
freightAmount: amount
})
visible.value = false
emit('success')
} finally {
submitting.value = false
}
}
defineExpose({ open })
</script>
<style scoped lang="scss">
.edit-hint {
margin: 0 0 12px;
font-size: 13px;
color: var(--mint-text-muted, #64748b);
}
</style>
@@ -1,18 +1,568 @@
<!-- 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"><!-- Task 5 填充 --></div>
<div class="list-toolbar"><!-- Task 5 --></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>
<el-button
class="btn-ghost"
:disabled="selectedFreightIds.length !== 1"
@click="openEditSelected"
>
<el-icon><Edit /></el-icon>
编辑运费
</el-button>
</div>
</div>
<div class="list-body list-wrap">
<el-empty description="运费列表加载中…" />
<el-table
class="list-table"
:data="flatRows"
v-loading="loading"
stripe
row-key="rowKey"
:span-method="spanMethod"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
prop="selection"
min-width="48"
align="center"
header-align="center"
:selectable="(row: FlatRow) => row.isFirst"
/>
<el-table-column
prop="transportMode"
label="运输方式"
min-width="120"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag type="primary" size="small" effect="plain">
{{ row.transportModeLabel || row.transportMode || '—' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
prop="freightAmount"
label="运费(元)"
min-width="110"
align="right"
header-align="center"
>
<template #default="{ row }">¥{{ 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="row.sampleSource === 'cell_storage' ? 'success' : 'warning'"
size="small"
>
{{ row.sampleSource === 'cell_storage' ? '细胞存储' : '科研捐赠' }}
</el-tag>
<span v-else class="muted">—</span>
</template>
</el-table-column>
<el-table-column
prop="protocolNo"
label="协议单号"
min-width="140"
show-overflow-tooltip
align="center"
header-align="center"
>
<template #default="{ row }">{{ row.protocolNo || '—' }}</template>
</el-table-column>
<el-table-column
prop="sampleCode"
label="样本编码"
min-width="120"
show-overflow-tooltip
align="center"
header-align="center"
>
<template #default="{ row }">{{ row.sampleCode || '—' }}</template>
</el-table-column>
<el-table-column
prop="sampleTypeName"
label="样本类型"
min-width="110"
show-overflow-tooltip
align="center"
header-align="center"
>
<template #default="{ row }">{{ row.sampleTypeName || '—' }}</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="260"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<div v-if="row.isFirst" 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>
</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" />
<el-dialog
v-model="unlinkVisible"
title="取消关联"
width="720px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
>
<p class="unlink-hint">勾选要从该运费批次解除关联的样本:</p>
<el-table
:data="unlinkItems"
stripe
class="list-table"
max-height="360"
row-key="sampleId"
@selection-change="(rows: UnlinkItem[]) => (unlinkSelected = rows)"
>
<el-table-column type="selection" min-width="48" align="center" header-align="center" />
<el-table-column label="来源" min-width="100" align="center" header-align="center">
<template #default="{ row }">
<el-tag :type="row.sampleSource === 'cell_storage' ? 'success' : 'warning'" size="small">
{{ row.sampleSource === 'cell_storage' ? '细胞存储' : '科研捐赠' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="protocolNo" label="协议单号" min-width="140" show-overflow-tooltip />
<el-table-column prop="sampleCode" label="样本编码" min-width="120" show-overflow-tooltip />
<el-table-column
prop="sampleTypeName"
label="样本类型"
min-width="110"
show-overflow-tooltip
/>
</el-table>
<template #footer>
<el-button class="btn-ghost" @click="unlinkVisible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button
class="btn-main"
type="primary"
:loading="unlinkSubmitting"
@click="confirmUnlink"
>
<el-icon><Check /></el-icon>
确定解除
</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { Check, Close, Edit, Link, Plus, RefreshLeft, Search } from '@element-plus/icons-vue'
import { fetchDictDataOptions } from '@/api/admin'
import {
fetchSampleFreightDetail,
fetchSampleFreightList,
fetchUnlinkSampleFreight,
type SampleFreight,
type SampleFreightItem
} from '@/api/sample-freight'
import { formatDisplayOrDash } from '@/utils/datetime-display'
import { formatMoneyDisplay } from '@/utils/money-format'
import FreightConfigDialog from './FreightConfigDialog.vue'
import FreightEditDialog from './FreightEditDialog.vue'
defineOptions({ name: 'CellStorageSampleFreight' })
type FlatRow = {
rowKey: string
freightId: string
rowspan: number
isFirst: boolean
transportMode: string
transportModeLabel: string
freightAmount: number
linkedSampleCount: number
createTime: string
sampleSource?: string
protocolNo?: string
sampleCode?: string
sampleTypeName?: string
sampleId?: string
protocolId?: string
}
type UnlinkItem = SampleFreightItem
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 unlinkFreightId = ref('')
const unlinkItems = ref<UnlinkItem[]>([])
const unlinkSelected = ref<UnlinkItem[]>([])
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[] {
const rows: FlatRow[] = []
for (const f of list) {
const items = f.items?.length ? f.items : [null]
items.forEach((it, idx) => {
rows.push({
rowKey: `${f.id}|${it?.sampleId || idx}`,
freightId: f.id,
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),
createTime: f.createTime || '',
sampleSource: it?.sampleSource,
protocolNo: it?.protocolNo,
sampleCode: it?.sampleCode,
sampleTypeName: it?.sampleTypeName,
sampleId: it?.sampleId,
protocolId: it?.protocolId
})
})
}
return rows
}
function spanMethod({ column, row }: { column: any; row: FlatRow }) {
const mergeProps = [
'selection',
'transportMode',
'freightAmount',
'linkedSampleCount',
'createTime',
'actions'
]
if (column.type === 'selection' || mergeProps.includes(column.property)) {
if (row.rowspan > 0) return { rowspan: row.rowspan, colspan: 1 }
return { rowspan: 0, colspan: 0 }
}
return { rowspan: 1, colspan: 1 }
}
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 openEditSelected() {
if (selectedFreightIds.value.length !== 1) return
openEditById(selectedFreightIds.value[0])
}
async function openUnlinkDialog(freightId: string) {
unlinkFreightId.value = freightId
unlinkSelected.value = []
try {
const res = await fetchSampleFreightDetail(freightId)
const data = ((res as any)?.data || res) as SampleFreight
unlinkItems.value = data.items || []
unlinkVisible.value = true
} catch {
ElMessage.error('加载关联样本失败')
}
}
async function confirmUnlink() {
if (!unlinkSelected.value.length) {
ElMessage.warning('请勾选要解除关联的样本')
return
}
unlinkSubmitting.value = true
try {
await fetchUnlinkSampleFreight(
unlinkFreightId.value,
unlinkSelected.value.map((x) => ({
sampleSource: x.sampleSource,
sampleId: x.sampleId,
protocolId: x.protocolId,
sampleCode: x.sampleCode
}))
)
unlinkVisible.value = false
await loadData()
} finally {
unlinkSubmitting.value = false
}
}
async function handleBatchUnlink() {
if (!selectedFreightIds.value.length) return
try {
await ElMessageBox.confirm(
`将解除已选 ${selectedFreightIds.value.length} 笔运费下的全部样本关联,是否继续?`,
'批量取消关联',
{ type: 'warning', confirmButtonText: '确定', cancelButtonText: '取消' }
)
} catch {
return
}
loading.value = true
try {
for (const id of selectedFreightIds.value) {
const res = await fetchSampleFreightDetail(id)
const data = ((res as any)?.data || res) as SampleFreight
const items = data.items || []
if (!items.length) continue
await fetchUnlinkSampleFreight(
id,
items.map((x) => ({
sampleSource: x.sampleSource,
sampleId: x.sampleId,
protocolId: x.protocolId,
sampleCode: x.sampleCode
}))
)
}
await loadData()
} 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);
}
.unlink-hint {
margin: 0 0 10px;
font-size: 13px;
color: var(--mint-text-muted, #64748b);
}
</style>