Files
zkxw/web-admin/src/views/quality-inspection/lab-sample-process/index.vue
T
zlwuandCursor b3c191ee99 fix(web-admin): 实验室样本处理数据 Tab 对齐样本接收胶囊样式
与质检样本接收页共用 panel-pill-tabs,保持质检管理列表页视觉一致。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 13:33:44 +08:00

350 lines
11 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-pill-tabs panel-pill-tabs--lg">
<div class="panel-pill-tabs__track" role="tablist">
<button
v-for="tab in LAB_PROCESS_TABS"
:key="tab.key"
type="button"
role="tab"
class="panel-pill-tabs__btn"
:class="{ 'is-active': activeTab === tab.key }"
:aria-selected="activeTab === tab.key"
@click="handleTabChange(tab.key)"
>
{{ tab.label }}
</button>
</div>
</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.labStorageCode"
placeholder="实验室入库编码"
clearable
/>
</el-form-item>
<el-form-item label="母亲姓名">
<el-input v-model="searchForm.motherName" placeholder="母亲/准妈妈姓名" clearable />
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="searchForm.createTimeRange"
type="datetimerange"
value-format="YYYY-MM-DD HH:mm:ss"
start-placeholder="开始时间"
end-placeholder="结束时间"
clearable
/>
</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">{{ pagination.total }}</span> 条
</div>
<el-button class="btn-main" type="primary" @click="handleExport">
<el-icon><Download /></el-icon>
导出 Excel
</el-button>
</div>
</div>
<div class="list-body list-wrap">
<el-table
class="list-table"
:data="tableData"
v-loading="loading"
stripe
row-key="receptionId"
>
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
:index="(index) => (pagination.page - 1) * pagination.pageSize + index + 1"
/>
<el-table-column
v-for="col in currentColumns"
:key="col.prop"
:prop="col.prop"
:label="col.label"
:min-width="col.minWidth || 120"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ displayCell(row[col.prop]) }}</template>
</el-table-column>
<el-table-column
label="操作"
min-width="260"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<div style="display: flex; justify-content: center; gap: 8px">
<el-button class="btn-op-item" @click="openSupplement(row)">
<el-icon><Edit /></el-icon>补录
</el-button>
</div>
</template>
</el-table-column>
</el-table>
<div class="pagination list-pager-bar">
<el-pagination
v-model:current-page="pagination.page"
v-model:page-size="pagination.pageSize"
:total="pagination.total"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
background
@size-change="loadData"
@current-change="loadData"
/>
</div>
</div>
</section>
<el-dialog
v-model="supplementVisible"
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"
>
<el-form label-position="top" class="biz-dialog-form">
<p class="form-tip"
>入库编码:{{ supplementForm.labStorageCode || '—' }}(补录数据跟随实验室入库编码)</p
>
<div class="form-grid-2">
<el-form-item
v-for="key in supplementKeys"
:key="key"
:label="SUPPLEMENT_FIELD_LABELS[key] || key"
>
<el-input v-model="supplementForm.payload[key]" clearable />
</el-form-item>
<el-form-item label="备注" class="form-col-span-2">
<el-input v-model="supplementForm.remark" type="textarea" :rows="2" />
</el-form-item>
</div>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="supplementVisible = false"
><el-icon><Close /></el-icon>取消</el-button
>
<el-button class="btn-main" type="primary" :loading="saving" @click="submitSupplement"
><el-icon><Check /></el-icon>确定</el-button
>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { Check, Close, Download, Edit, RefreshLeft, Search } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import * as XLSX from 'xlsx'
import {
fetchLabSampleProcessList,
fetchLabSampleProcessSupplement,
saveLabSampleProcessSupplement,
type LabSampleProcessTabKey
} from '@/api/lab-sample-process'
import {
LAB_PROCESS_COLUMNS,
LAB_PROCESS_TABS,
SUPPLEMENT_FIELD_LABELS
} from '@/utils/lab-sample-process-columns'
defineOptions({ name: 'QualityInspectionLabSampleProcess' })
const activeTab = ref<LabSampleProcessTabKey>('cell_hsc')
const loading = ref(false)
const saving = ref(false)
const tableData = ref<Record<string, unknown>[]>([])
const supplementKeys = ref<string[]>([])
const searchForm = reactive({
labStorageCode: '',
motherName: '',
createTimeRange: null as [string, string] | null
})
const pagination = reactive({
page: 1,
pageSize: 10,
total: 0
})
const currentColumns = computed(() => LAB_PROCESS_COLUMNS[activeTab.value] || [])
const currentTabMeta = computed(
() => LAB_PROCESS_TABS.find((t) => t.key === activeTab.value) || LAB_PROCESS_TABS[0]
)
const supplementVisible = ref(false)
const supplementForm = reactive({
labStorageCode: '',
receptionSource: 'cell_storage',
sampleTypeName: '',
remark: '',
payload: {} as Record<string, string>
})
function displayCell(value: unknown) {
if (value === null || value === undefined || value === '') return '—'
return String(value)
}
async function loadData() {
loading.value = true
try {
const range = searchForm.createTimeRange
const res = await fetchLabSampleProcessList({
tabKey: activeTab.value,
page: pagination.page,
pageSize: pagination.pageSize,
labStorageCode: searchForm.labStorageCode || undefined,
motherName: searchForm.motherName || undefined,
createTimeStart: range?.[0],
createTimeEnd: range?.[1]
})
tableData.value = (res?.list || []) as Record<string, unknown>[]
pagination.total = Number(res?.total || 0)
supplementKeys.value = (res?.supplementKeys || []) as string[]
} catch (e: any) {
ElMessage.error(e?.message || '加载失败')
} finally {
loading.value = false
}
}
function handleSearch() {
pagination.page = 1
loadData()
}
function handleReset() {
searchForm.labStorageCode = ''
searchForm.motherName = ''
searchForm.createTimeRange = null
handleSearch()
}
function handleTabChange(name: LabSampleProcessTabKey) {
if (activeTab.value === name) return
activeTab.value = name
pagination.page = 1
loadData()
}
async function openSupplement(row: Record<string, unknown>) {
const code = String(row.labStorageCode || row.cellCode || row.labFlowCode || '').trim()
if (!code) {
ElMessage.warning('缺少实验室入库编码,无法补录')
return
}
const meta = currentTabMeta.value
supplementForm.labStorageCode = code
supplementForm.receptionSource = meta.source
supplementForm.sampleTypeName = meta.sampleTypeName
supplementForm.remark = ''
const keys = supplementKeys.value.length
? supplementKeys.value
: currentColumns.value.map((c) => c.prop)
const payload: Record<string, string> = {}
keys.forEach((k) => {
payload[k] = ''
})
try {
const data = await fetchLabSampleProcessSupplement(code)
const existing = (data?.payload || {}) as Record<string, string>
keys.forEach((k) => {
payload[k] = existing[k] != null ? String(existing[k]) : ''
})
supplementForm.remark = data?.remark || ''
} catch {
// 无补录记录时用空表单
}
supplementForm.payload = payload
supplementVisible.value = true
}
async function submitSupplement() {
saving.value = true
try {
await saveLabSampleProcessSupplement({
labStorageCode: supplementForm.labStorageCode,
receptionSource: supplementForm.receptionSource,
sampleTypeName: supplementForm.sampleTypeName,
payload: { ...supplementForm.payload },
remark: supplementForm.remark
})
ElMessage.success('补录已保存')
supplementVisible.value = false
loadData()
} catch (e: any) {
ElMessage.error(e?.message || '保存失败')
} finally {
saving.value = false
}
}
function handleExport() {
const cols = currentColumns.value
const headers = ['序号', ...cols.map((c) => c.label)]
const rows = tableData.value.map((row, idx) => {
const line: Record<string, string | number> = {
序号: (pagination.page - 1) * pagination.pageSize + idx + 1
}
cols.forEach((c) => {
const v = row[c.prop]
line[c.label] = v === null || v === undefined || v === '' ? '' : String(v)
})
return line
})
const sheet = XLSX.utils.json_to_sheet(rows, { header: headers })
const workbook = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(workbook, sheet, currentTabMeta.value.label.slice(0, 31))
const stamp = new Date().toISOString().slice(0, 19).replace(/[:T]/g, '')
XLSX.writeFile(workbook, `实验室样本处理数据_${currentTabMeta.value.key}_${stamp}.xlsx`)
}
onMounted(() => {
loadData()
})
</script>
<style scoped lang="scss">
.form-tip {
margin: 0 0 12px;
color: var(--mint-text-muted, #6b7280);
font-size: 13px;
}
</style>