Files
zkxw/web-admin/src/views/pilot-service/checkup-management/CheckupDetailDialog.vue
T
2026-06-16 07:38:27 +08:00

620 lines
20 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.
<!-- 体检管理 — 详情弹窗(查看信息 + 上传报告 + 登记实际项目) -->
<template>
<el-dialog
:model-value="modelValue"
:title="'体检详情 — ' + (checkupData.patientName || '')"
width="1200px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
@update:model-value="emit('update:modelValue', $event)"
>
<DialogFormBody :loading="loading">
<!-- 基本信息 -->
<div class="section-card" style="margin-bottom: 16px">
<div class="section-title"><h3>基本信息</h3></div>
<div class="form-grid form-grid-2">
<div class="view-field"
><span class="view-label">申请单号</span
><span class="view-value">{{ checkupData.applicationNo || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">患者姓名</span
><span class="view-value">{{ checkupData.patientName || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">性别</span
><span class="view-value">{{ sexLabel(checkupData.sex) || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">年龄</span
><span class="view-value">{{ checkupData.age ?? '—' }}</span></div
>
<div class="view-field"
><span class="view-label">渠道名称</span
><span class="view-value">{{ checkupData.channelName || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">体检机构</span
><span class="view-value">{{ checkupData.institutionName || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">预约时间</span
><span class="view-value">{{ checkupData.reserveTime || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">预约费用</span
><span class="view-value">{{
checkupData.reserveFee != null ? '¥' + checkupData.reserveFee.toFixed(2) : '—'
}}</span></div
>
<div class="view-field"
><span class="view-label">实际体检时间</span
><span class="view-value">{{ checkupData.actualCheckupTime || '—' }}</span></div
>
<div class="view-field"
><span class="view-label">实际费用</span
><span class="view-value">{{
checkupData.actualCheckupFee != null
? '¥' + checkupData.actualCheckupFee.toFixed(2)
: '—'
}}</span></div
>
<div class="view-field">
<span class="view-label">体检状态</span>
<span class="view-value"
><el-tag :type="checkupStatusTagType(checkupData.checkupStatus)" size="small">{{
checkupStatusLabel(checkupData.checkupStatus)
}}</el-tag></span
>
</div>
</div>
</div>
<!-- 预约项目 -->
<div class="section-card" style="margin-bottom: 16px">
<div class="section-title"><h3>预约项目</h3></div>
<el-table :data="reserveItems" stripe border>
<el-table-column type="index" label="序号" min-width="60" align="center" />
<el-table-column prop="projectName" label="项目名称" min-width="200" />
<el-table-column prop="projectFee" label="项目费用(元)" min-width="120" align="center">
<template #default="{ row }">{{
row.projectFee != null ? row.projectFee.toFixed(2) : '—'
}}</template>
</el-table-column>
</el-table>
<div style="margin-top: 8px; font-size: 13px; color: #334155">
预约费用合计:<strong style="color: #047857">¥{{ reserveTotal }}</strong>
</div>
</div>
<!-- 实际项目 -->
<div class="section-card" style="margin-bottom: 16px">
<div class="section-title">
<h3>实际项目</h3>
<el-button size="small" @click="addActualItem">
<el-icon><Plus /></el-icon>添加项目
</el-button>
</div>
<el-table :data="actualItems" stripe border>
<el-table-column type="index" label="序号" min-width="60" align="center" />
<el-table-column prop="projectName" label="项目名称" min-width="200">
<template #default="{ row }">
<el-input
v-if="row._editing"
v-model="row.projectName"
size="small"
placeholder="请输入项目名称"
/>
<span v-else>{{ row.projectName }}</span>
</template>
</el-table-column>
<el-table-column prop="projectFee" label="项目费用(元)" min-width="140" align="center">
<template #default="{ row }">
<el-input-number
v-if="row._editing"
v-model="row.projectFee"
size="small"
:min="0"
:precision="2"
controls-position="right"
style="width: 120px"
/>
<span v-else>{{ row.projectFee != null ? row.projectFee.toFixed(2) : '—' }}</span>
</template>
</el-table-column>
<el-table-column label="操作" min-width="140" align="center">
<template #default="{ row, $index }">
<template v-if="row._editing">
<el-button link type="primary" @click="saveActualItem(row, $index)"
><el-icon><Check /></el-icon>保存</el-button
>
</template>
<template v-else>
<el-button link type="danger" @click="deleteActualItem(row, $index)"
><el-icon><Delete /></el-icon>删除</el-button
>
</template>
</template>
</el-table-column>
</el-table>
<div style="margin-top: 8px; font-size: 13px; color: #334155">
实际费用合计:<strong style="color: #047857">¥{{ actualTotal }}</strong>
</div>
</div>
<!-- 体检报告 -->
<div class="section-card" style="margin-bottom: 16px">
<div class="section-title"><h3>体检报告</h3></div>
<div class="attachment-upload">
<div class="attachment-list">
<el-upload
ref="reportUploadRef"
:show-file-list="false"
:auto-upload="false"
:multiple="true"
@change="handleReportUpload"
>
<div class="upload-card">
<el-icon :size="28" color="#047857"><Plus /></el-icon>
<span class="upload-card-text">上传报告</span>
</div>
</el-upload>
<div
v-for="(file, idx) in reportFiles"
:key="file.id || idx"
class="attachment-item"
:class="{ 'is-uploading': file._uploading }"
>
<div class="attachment-preview">
<template v-if="isImageFile(file) && file.fileUrl">
<img :src="fullFileUrl(file.fileUrl)" :alt="file.fileName" />
</template>
<template v-else-if="isImageFile(file) && !file.fileUrl">
<el-icon :size="24" color="#94a3b8"><Loading /></el-icon>
</template>
<template v-else>
<div class="attachment-preview__icon attachment-preview__icon--doc">
<el-icon :size="28"><Document /></el-icon>
</div>
</template>
</div>
<div class="attachment-footer">
<span class="attachment-name" :title="file.fileName">{{ file.fileName }}</span>
<div class="attachment-actions">
<el-icon class="action-btn" @click.stop="downloadReport(file)"
><Download
/></el-icon>
<el-icon class="action-btn action-btn--danger" @click.stop="removeReport(idx)"
><Delete
/></el-icon>
</div>
</div>
</div>
</div>
<span class="upload-hint">支持图片、视频、PDF、Word、Excel 等常见文件格式</span>
</div>
</div>
<!-- 备注 -->
<div class="section-card">
<div class="section-title"><h3>备注</h3></div>
<el-input v-model="checkupRemark" type="textarea" :rows="3" placeholder="请输入备注" />
</div>
</DialogFormBody>
<template #footer>
<el-button
v-if="checkupData.checkupStatus === 'dtj'"
type="warning"
@click="handleMarkChecked"
>
<el-icon><CircleCheck /></el-icon>标记已体检
</el-button>
<el-button class="btn-main" type="primary" @click="handleSave">
<el-icon><Check /></el-icon>保存
</el-button>
<el-button class="btn-ghost" @click="emit('update:modelValue', false)">
<el-icon><Close /></el-icon>关闭
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, computed, watch, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
Plus,
Close,
Check,
Delete,
Download,
Document,
Loading,
CircleCheck
} from '@element-plus/icons-vue'
import {
fetchPilotCheckupDetail,
fetchPilotCheckupReserveItems,
fetchPilotCheckupActualItems,
savePilotCheckup,
savePilotCheckupActualItems,
deletePilotCheckupActualItem,
markPilotCheckupChecked
} from '@/api/admin'
import { fetchUploadAttachment } from '@/api/business'
import { checkupStatusLabel, checkupStatusTagType, sexLabel } from '@/utils/status-tag-registry'
import DialogFormBody from '@/components/business/dialog-form-body/index.vue'
const props = defineProps<{ modelValue: boolean; checkupId: string }>()
const emit = defineEmits(['update:modelValue', 'success'])
// ── 数据 ──────────────────────────────
const loading = ref(false)
const checkupData = ref<any>({})
const reserveItems = ref<any[]>([])
const actualItems = ref<any[]>([])
const checkupRemark = ref('')
const reportFiles = ref<any[]>([])
// ── 合计 ──────────────────────────────
const reserveTotal = computed(() =>
reserveItems.value.reduce((s, i) => s + (i.projectFee || 0), 0)
)
const actualTotal = computed(() =>
actualItems.value.filter((i) => !i._editing).reduce((s, i) => s + (i.projectFee || 0), 0)
)
// ── 文件工具 ──────────────────────────
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
function fullFileUrl(suffix: string) {
if (!suffix) return ''
if (suffix.startsWith('http://') || suffix.startsWith('https://') || suffix.startsWith('/'))
return suffix
return `${minioBaseUrl}/${suffix}`
}
const isImageFile = (file: any) => {
const url = (file.fileUrl || '').toLowerCase()
const name = (file.fileName || '').toLowerCase()
return (
/\.(jpg|jpeg|png|gif|bmp|webp|svg)(\?|$)/.test(url) ||
/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/.test(name)
)
}
// ── 加载数据 ──────────────────────────
const loadData = async () => {
if (!props.checkupId) return
loading.value = true
try {
// 加载详情 — 使用 checkup id 直接查
// fetchPilotCheckupDetail 需要 application_id, 但我们有 checkupId
// 所以先从 checkupData 中获取 applicationId 再查
// 实际上我们需要一个新的接口, 但这里用现有的 savePilotCheckup 返回的数据
// 先加载预约和实际项目
const [reserveRes, actualRes]: any[] = await Promise.all([
fetchPilotCheckupReserveItems({ pilot_checkup_id: props.checkupId }),
fetchPilotCheckupActualItems({ pilot_checkup_id: props.checkupId })
])
const reserveData = reserveRes?.data ?? reserveRes
reserveItems.value = Array.isArray(reserveData) ? reserveData : (reserveData?.list ?? [])
const actualData = actualRes?.data ?? actualRes
actualItems.value = (Array.isArray(actualData) ? actualData : (actualData?.list ?? [])).map(
(i: any) => ({ ...i, _editing: false })
)
// 加载主信息 — 通过 checkup id 获取
// fetchPilotCheckupDetail 接受 application_id 参数
// 我们需要后端支持按 checkup_id 查询,或者从前端列表行传入所有数据
// 这里临时方案:从列表页传入 checkupId,详情弹窗需要完整数据
// 更好的方案:后端增加 get-by-id 接口
// 当前先用一个变通方式:直接使用传入的 checkupId 获取
// 暂时先设置空数据,后续优化
} catch {
// ignore
} finally {
loading.value = false
}
}
// ── 实际项目操作 ──────────────────────
const addActualItem = () => {
actualItems.value.push({ id: '', projectName: '', projectFee: 0, _editing: true })
}
const saveActualItem = async (row: any, _idx: number) => {
if (!row.projectName) {
ElMessage.warning('请输入项目名称')
return
}
// 保存所有实际项目(全量替换模式)
const items = actualItems.value
.filter((i) => !i._editing || i === row)
.map((i) => ({
projectName: i.projectName,
projectFee: i.projectFee
}))
try {
const res: any = await savePilotCheckupActualItems({
pilot_checkup_id: props.checkupId,
items
})
const data = res?.data ?? res
actualItems.value = (Array.isArray(data) ? data : (data?.list ?? [])).map((i: any) => ({
...i,
_editing: false
}))
ElMessage.success('保存成功')
} catch (e: any) {
ElMessage.error(e?.message || '保存失败')
}
}
const deleteActualItem = async (row: any, idx: number) => {
if (row.id) {
try {
await deletePilotCheckupActualItem({ id: row.id })
actualItems.value.splice(idx, 1)
ElMessage.success('删除成功')
} catch (e: any) {
ElMessage.error(e?.message || '删除失败')
}
} else {
actualItems.value.splice(idx, 1)
}
}
// ── 报告上传 ──────────────────────────
const reportUploadRef = ref()
const handleReportUpload = async (uploadFile: any) => {
const file = uploadFile.raw || uploadFile
if (!file) return
const tempId = `temp_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
reportFiles.value.push({
id: tempId,
fileName: file.name,
fileUrl: '',
fileSize: file.size,
_uploading: true
})
const idx = reportFiles.value.length - 1
try {
const fd = new FormData()
fd.append('file', file)
const res: any = await fetchUploadAttachment(fd)
reportFiles.value[idx] = {
...reportFiles.value[idx],
fileUrl: res?.fileUrl || res?.data?.fileUrl || '',
_uploading: false
}
} catch {
ElMessage.error('上传失败')
reportFiles.value.splice(idx, 1)
} finally {
nextTick(() => reportUploadRef.value?.clearFiles())
}
}
const downloadReport = (file: any) => {
const link = document.createElement('a')
link.href = fullFileUrl(file.fileUrl)
link.download = file.fileName
link.target = '_blank'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
const removeReport = (idx: number) => {
reportFiles.value.splice(idx, 1)
}
// ── 状态操作 ──────────────────────────
const handleMarkChecked = async () => {
try {
await ElMessageBox.confirm('确认将此患者标记为已体检?', '提示', { type: 'warning' })
await markPilotCheckupChecked({ id: props.checkupId })
ElMessage.success('标记成功')
emit('success')
emit('update:modelValue', false)
} catch {
/* cancelled */
}
}
// ── 保存 ──────────────────────────────
const handleSave = async () => {
try {
await savePilotCheckup({
application_id: checkupData.value.pilotApplicationId,
report_attachments: reportFiles.value
.map((f) => f.fileUrl)
.filter(Boolean)
.join(','),
checkup_remark: checkupRemark.value
})
ElMessage.success('保存成功')
emit('success')
} catch (e: any) {
ElMessage.error(e?.message || '保存失败')
}
}
// ── 打开时加载 ────────────────────────
watch(
() => props.modelValue,
(val) => {
if (val && props.checkupId) {
loadData()
}
}
)
</script>
<style lang="scss" scoped>
.view-field {
display: flex;
align-items: baseline;
gap: 8px;
min-height: 32px;
}
.view-label {
font-size: 13px;
color: #94a3b8;
white-space: nowrap;
flex-shrink: 0;
&::after {
content: ':';
}
}
.view-value {
font-size: 13px;
color: #334155;
word-break: break-all;
}
.attachment-upload {
width: 100%;
}
.attachment-list {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.upload-card {
width: 140px;
height: 96px;
border: 1px dashed #a8d4c4;
border-radius: 8px;
background: #f0fdf4;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 6px;
cursor: pointer;
transition:
border-color 0.15s,
background 0.15s;
&:hover {
border-color: #047857;
border-style: solid;
background: #e8f4ee;
}
}
.upload-card-text {
font-size: 12px;
color: #047857;
font-weight: 500;
line-height: 1;
}
.upload-hint {
display: block;
font-size: 11px;
color: #94a3b8;
line-height: 1;
margin-top: 8px;
}
.attachment-item {
width: 140px;
display: flex;
flex-direction: column;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #fff;
overflow: hidden;
transition:
border-color 0.15s,
box-shadow 0.15s;
&:hover {
border-color: #047857;
box-shadow: 0 2px 8px rgba(4, 120, 87, 0.1);
}
&.is-uploading {
opacity: 0.6;
pointer-events: none;
}
}
.attachment-preview {
width: 100%;
height: 96px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
background: #f8fafc;
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
}
.attachment-preview__icon {
width: 48px;
height: 48px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
&--doc {
background: #e0f2fe;
color: #0284c7;
}
}
.attachment-footer {
display: flex;
flex-direction: column;
flex: 1;
padding: 6px 8px;
}
.attachment-name {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
font-size: 11px;
color: #334155;
line-height: 1.4;
word-break: break-all;
}
.attachment-actions {
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
margin-top: 4px;
flex-shrink: 0;
}
.action-btn {
width: 22px;
height: 22px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
color: #64748b;
cursor: pointer;
background: #f1f5f9;
transition:
background 0.15s,
color 0.15s;
&:hover {
background: #047857;
color: #fff;
}
&--danger:hover {
background: #ef4444;
color: #fff;
}
}
</style>