| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- <template>
- <div class="proxy-report-upload">
- <el-card>
- <PageHeader slot="header" title="代传报告上传" />
- <el-form ref="uploadForm" :model="uploadForm" label-width="100px" class="upload-form">
- <el-form-item label="选择家庭" prop="familyId" required>
- <el-select v-model="uploadForm.familyId" placeholder="请选择家庭" filterable class="full-width" @change="onFamilyChange">
- <el-option v-for="f in familyList" :key="f.id" :label="f.name" :value="f.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="报告对象" prop="subjectId" required>
- <el-select v-model="uploadForm.subjectId" placeholder="请选择家庭成员" filterable class="full-width">
- <el-option v-for="m in memberList" :key="m.id" :label="m.nickname || m.realName" :value="m.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="报告文件" prop="file" required>
- <el-upload ref="upload" action="" :auto-upload="false" :limit="1" accept=".pdf" :on-change="handleFileChange" :on-exceed="handleExceed">
- <el-button size="small" type="primary">选择PDF文件</el-button>
- <div slot="tip" class="el-upload__tip">仅支持PDF格式,大小不超过50MB</div>
- </el-upload>
- </el-form-item>
- <el-form-item label="代上传备注">
- <el-input v-model="uploadForm.note" type="textarea" :rows="2" placeholder="选填,备注上传原因" />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" :loading="uploading" @click="handleUpload">上传并解析</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- <!-- 解析结果预览 -->
- <el-card v-if="previewResult" class="mt-20">
- <div slot="header">
- <SectionTitle title="解析结果预览">
- <StatusTag :type="previewResult.needBind ? 'warning' : 'success'" :text="previewResult.needBind ? '待绑定成员' : '已匹配成员'" />
- </SectionTitle>
- </div>
- <el-descriptions :column="2" border>
- <el-descriptions-item label="被检测人">{{ previewResult.extractedName || '-' }}</el-descriptions-item>
- <el-descriptions-item label="报告编号">{{ previewResult.extractedReportNumber || '-' }}</el-descriptions-item>
- <el-descriptions-item label="报告日期">{{ previewResult.extractedReportDate || '-' }}</el-descriptions-item>
- <el-descriptions-item label="健康总分">{{ previewResult.payload && previewResult.payload.summary && previewResult.payload.summary.overallScore != null ? previewResult.payload.summary.overallScore : '-' }}</el-descriptions-item>
- <el-descriptions-item label="菌群健康分">{{ previewResult.payload && previewResult.payload.summary && previewResult.payload.summary.gutHealthScore != null ? previewResult.payload.summary.gutHealthScore : '-' }}</el-descriptions-item>
- <el-descriptions-item label="肠型">{{ previewResult.payload && previewResult.payload.summary && previewResult.payload.summary.gutType ? previewResult.payload.summary.gutType : '-' }}</el-descriptions-item>
- </el-descriptions>
- <div class="mt-20-right">
- <el-button @click="previewResult = null">取消</el-button>
- <el-button type="primary" :loading="confirming" @click="handleConfirm">确认入库</el-button>
- </div>
- </el-card>
- <!-- AI解读结果 -->
- <el-card v-if="analysisResult" class="mt-20">
- <div slot="header">
- <SectionTitle title="AI解读结果">
- <StatusTag type="success" size="small" text="已完成" />
- </SectionTitle>
- </div>
- <div v-html="analysisResult" class="analysis-content"></div>
- </el-card>
- <!-- 代传历史 -->
- <el-card class="mt-20">
- <div slot="header">
- <SectionTitle title="代上传历史记录" />
- </div>
- <div class="filter-bar">
- <el-select v-model="query.type" placeholder="报告类型" clearable class="w-140">
- <el-option label="全部" value=""></el-option>
- <el-option label="菌群检测" value="gut_flora"></el-option>
- <el-option label="体检报告" value="physical_exam"></el-option>
- <el-option label="DAN测评" value="dan"></el-option>
- <el-option label="保单" value="insurance"></el-option>
- <el-option label="家庭周报" value="fortune"></el-option>
- </el-select>
- <el-input v-model="query.keyword" placeholder="搜索标题/名称" class="w-200" clearable @keyup.enter.native="loadProxyReports"></el-input>
- <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="w-240"></el-date-picker>
- <el-button type="primary" @click="loadProxyReports">查询</el-button>
- </div>
- <div class="adm-table-wrap">
- <el-table :data="proxyReportList" border stripe v-loading="proxyListLoading" height="100%">
- <el-table-column prop="id" label="ID" width="70" />
- <el-table-column label="报告对象" width="120">
- <template slot-scope="{ row }">{{ row.subjectName || row.childName || row.personName || row.userName || '-' }}</template>
- </el-table-column>
- <el-table-column label="报告类型" width="100">
- <template slot-scope="{ row }">
- <StatusTag :type="getTypeTag(row.reportType)" :text="typeLabel(row.reportType)" />
- </template>
- </el-table-column>
- <el-table-column prop="title" label="标题" min-width="140" show-overflow-tooltip />
- <el-table-column label="健康分" width="80">
- <template slot-scope="{ row }">{{ row.overallScore == null ? '-' : row.overallScore }}</template>
- </el-table-column>
- <el-table-column label="上传时间" width="160">
- <template slot-scope="{ row }">{{ formatTime(row.createdAt) }}</template>
- </el-table-column>
- <el-table-column label="操作" width="100" fixed="right">
- <template slot-scope="{ row }">
- <el-button size="mini" type="text" @click="viewProxyReport(row)">查看</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <el-pagination @size-change="onProxySizeChange" @current-change="onProxyPageChange" :current-page="proxyPage" :page-size="proxySize" :total="proxyTotal" layout="total, prev, pager, next" class="pagination-wrap" />
- </el-card>
- <!-- 报告详情弹窗 -->
- <el-dialog title="报告详情" :visible.sync="detailDialogVisible" width="700px" top="5vh">
- <el-descriptions v-if="detailReport" :column="2" border>
- <el-descriptions-item label="报告ID">{{ detailReport.id }}</el-descriptions-item>
- <el-descriptions-item label="报告类型">{{ detailReport.reportType || typeLabel(detailReport.reportType) }}</el-descriptions-item>
- <el-descriptions-item label="报告编号">{{ detailReport.reportNumber || '-' }}</el-descriptions-item>
- <el-descriptions-item label="报告日期">{{ detailReport.reportDate || '-' }}</el-descriptions-item>
- <el-descriptions-item label="健康总分">{{ detailReport.overallScore || '-' }}</el-descriptions-item>
- <el-descriptions-item label="菌群健康分">{{ detailReport.gutHealthScore || '-' }}</el-descriptions-item>
- <el-descriptions-item label="肠型">{{ detailReport.gutType || '-' }}</el-descriptions-item>
- <el-descriptions-item label="肠道年龄">{{ detailReport.gutAge || '-' }}</el-descriptions-item>
- <el-descriptions-item label="AI解读" :span="2">
- <div v-html="detailReport.aiAnalysis" class="analysis-content analysis-scroll"></div>
- </el-descriptions-item>
- </el-descriptions>
- <span slot="footer"><el-button @click="detailDialogVisible = false">关闭</el-button></span>
- </el-dialog>
- </div>
- </template>
- <script>
- import ListStateMixin from '@/mixins/ListStateMixin'
- import { getFamilyList, getFamilyMemberList } from '@/api/admin'
- import { proxyParseReport, proxyReparseReport, proxyConfirmReport, adminListHealthReports, getHealthReportDetail } from '@/api/admin'
- export default {
- name: 'ProxyReportUpload',
- mixins: [ListStateMixin],
- data() {
- return {
- uploading: false,
- confirming: false,
- proxyListLoading: false,
- familyList: [],
- memberList: [],
- proxyReportList: [],
- previewResult: null,
- analysisResult: null,
- proxyPage: 1,
- proxySize: 20,
- proxyTotal: 0,
- query: { type: '', keyword: '' },
- dateRange: [],
- uploadForm: { familyId: null, subjectId: null, file: null, note: '' },
- detailDialogVisible: false,
- detailReport: null
- }
- },
- created() {
- this.loadFamilies()
- this.loadProxyReports()
- },
- methods: {
- async loadFamilies() {
- try {
- var res = await getFamilyList({ page: 1, size: 200 })
- this.familyList = res.data && res.data.records ? res.data.records : (res.data || [])
- } catch (e) {
- console.error(e)
- }
- },
- async onFamilyChange(familyId) {
- if (!familyId) { this.memberList = []; return }
- try {
- var res = await getFamilyMemberList({ familyId: familyId })
- this.memberList = res.data || []
- this.uploadForm.subjectId = null
- } catch (e) {
- this.memberList = []
- }
- },
- handleFileChange(file) {
- this.uploadForm.file = file.raw
- },
- handleExceed() {
- this.$message.warning('只能上传一个文件')
- },
- async handleUpload() {
- if (!this.uploadForm.familyId) { this.$message.warning('请选择家庭'); return }
- if (!this.uploadForm.subjectId) { this.$message.warning('请选择报告对象'); return }
- if (!this.uploadForm.file) { this.$message.warning('请选择PDF文件'); return }
- this.uploading = true
- try {
- var res = await proxyParseReport({ familyId: this.uploadForm.familyId, subjectId: this.uploadForm.subjectId, file: this.uploadForm.file, note: this.uploadForm.note })
- if (res.code === 200) {
- this.previewResult = res.data
- this.analysisResult = null
- this.notifyParseFallback(res.data)
- } else {
- this.$message.error(res.message || '解析失败')
- }
- } catch (e) {
- this.$message.error('上传失败: ' + (e.message || ''))
- } finally {
- this.uploading = false
- }
- },
- async handleConfirm() {
- if (!this.previewResult || !this.previewResult.draftId) {
- this.$message.warning('没有可确认的草稿')
- return
- }
- this.confirming = true
- try {
- var res = await proxyConfirmReport({ draftId: this.previewResult.draftId, subjectId: this.uploadForm.subjectId })
- if (res.code === 200) {
- this.$message.success('报告入库成功')
- this.previewResult = null
- this.applyAiAnalysisResult(res.data)
- this.loadProxyReports()
- } else if (this.isDraftExpired(res.message)) {
- // B3-2:草稿过期降级——提示重新上传,支持基于 fileUrl 重新解析(复用原文件)
- this.reparseExpiredDraft()
- } else {
- this.$message.error(res.message || '确认失败')
- }
- } catch (e) {
- this.$message.error('确认失败: ' + (e.message || ''))
- } finally {
- this.confirming = false
- }
- },
- // B3-1:按 B1-5 返回的 aiAnalysisStatus/aiAnalysisMessage 提示「AI 解读未完成:原因」而非静默
- applyAiAnalysisResult(data) {
- var aiStatus = data && data.aiAnalysisStatus
- // 有解读结果即展示;状态缺失时按成功处理(兼容未带 status 的旧返回)
- if ((aiStatus === 'success' || !aiStatus) && data && data.aiAnalysis) {
- this.analysisResult = data.aiAnalysis
- return
- }
- this.analysisResult = null
- var reason = (data && data.aiAnalysisMessage) || (data && data.aiAnalysisStatus) || ''
- this.$message.warning('AI解读未完成:' + (reason || '未知原因'))
- },
- // B3-3:LangGraph 不可用走本地解析时的提示文案
- notifyParseFallback(data) {
- if (data && data.parseFallback) {
- this.$message.warning('解析服务暂不可用,已用本地解析')
- }
- },
- // B3-2:草稿不存在或已过期 → 基于 fileUrl 重新建草稿并解析,不重新传 PDF
- async reparseExpiredDraft() {
- var fileUrl = this.previewResult && this.previewResult.fileUrl
- if (!fileUrl) {
- this.$message.error('草稿已过期,且无法获取原文件,请重新上传')
- return
- }
- var confirmed = false
- try {
- confirmed = await this.$confirm('草稿已过期,是否基于原文件重新解析?', '提示', {
- confirmButtonText: '重新解析',
- cancelButtonText: '取消',
- type: 'warning'
- })
- } catch (e) {
- confirmed = false
- }
- if (!confirmed) return
- this.uploading = true
- try {
- var res = await proxyReparseReport({
- fileUrl: fileUrl,
- familyId: this.uploadForm.familyId,
- subjectId: this.uploadForm.subjectId,
- note: this.uploadForm.note
- })
- if (res.code === 200) {
- this.previewResult = res.data
- this.analysisResult = null
- this.$message.success('已重新解析,请重新确认入库')
- this.notifyParseFallback(res.data)
- } else {
- this.$message.error(res.message || '重新解析失败')
- }
- } catch (e) {
- this.$message.error('重新解析失败: ' + (e.message || ''))
- } finally {
- this.uploading = false
- }
- },
- isDraftExpired(message) {
- return !!(message && (message.indexOf('草稿不存在') >= 0 || message.indexOf('已过期') >= 0))
- },
- async loadProxyReports() {
- this.proxyListLoading = true
- try {
- var params = {
- page: this.proxyPage,
- size: this.proxySize,
- type: this.query.type,
- keyword: this.query.keyword
- }
- if (this.dateRange && this.dateRange.length === 2) {
- params.startDate = this.dateRange[0].format ? this.dateRange[0].format('YYYY-MM-DD') : this.dateRange[0]
- params.endDate = this.dateRange[1].format ? this.dateRange[1].format('YYYY-MM-DD') : this.dateRange[1]
- }
- var res = await adminListHealthReports(params)
- var data = (res && res.data && res.data.data) ? res.data.data : (res && res.data ? res.data : null)
- if (data) {
- this.proxyReportList = data.records || []
- this.proxyTotal = data.total || this.proxyReportList.length
- } else {
- this.proxyReportList = []
- this.proxyTotal = 0
- }
- } catch (e) {
- console.error(e)
- this.proxyReportList = []
- this.proxyTotal = 0
- } finally {
- this.proxyListLoading = false
- }
- },
- viewProxyReport(row) {
- var self = this
- getHealthReportDetail(row.id).then(function(res) {
- if (res && res.code === 200) {
- // B1-4:详情接口返回嵌套结构 {report:{...}, indicators, ...},取 report 层
- self.detailReport = (res.data && res.data.report) ? res.data.report : res.data
- self.detailDialogVisible = true
- } else {
- self.$message.error('加载详情失败')
- }
- }).catch(function() {
- self.$message.error('加载详情失败')
- })
- },
- onProxySizeChange(size) {
- this.proxySize = size
- this.proxyPage = 1
- this.loadProxyReports()
- },
- onProxyPageChange(page) {
- this.proxyPage = page
- this.loadProxyReports()
- },
- typeLabel(type) {
- var map = { gut_flora: '菌群检测', physical_exam: '体检报告', dan: 'DAN测评', insurance: '保单', fortune: '家庭周报' }
- return map[type] || type || '-'
- },
- getTypeTag(type) {
- var map = { gut_flora: 'success', physical_exam: 'primary', dan: 'warning', insurance: 'info', fortune: 'danger' }
- return map[type] || 'info'
- }
- }
- }
- </script>
- <style scoped>
- .proxy-report-upload { padding: 16px; }
- .upload-form { max-width: 600px; }
- .filter-bar { display: flex; flex-direction: row; align-items: center; gap: 12px; flex-wrap: wrap; }
- .pagination-wrap { margin-top: 16px; text-align: right; }
- .analysis-content { font-size: 14px; line-height: 1.8; color: var(--adm-text-88); }
- .analysis-content :deep(p) { margin: 8px 0; }
- /* == C 批内联清理工具类 == */
- .w-140 { width: 140px; }
- .w-200 { width: 200px; }
- .w-240 { width: 240px; }
- .full-width { width: 100%; }
- .mt-20 { margin-top: 24px; }
- .mt-20-right { margin-top: 24px; text-align: right; }
- .analysis-scroll { max-height: 300px; overflow: auto; }
- </style>
|