ProxyReportUpload.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="proxy-report-upload">
  3. <el-card>
  4. <PageHeader slot="header" title="代传报告上传" />
  5. <el-form ref="uploadForm" :model="uploadForm" label-width="100px" class="upload-form">
  6. <el-form-item label="选择家庭" prop="familyId" required>
  7. <el-select v-model="uploadForm.familyId" placeholder="请选择家庭" filterable class="full-width" @change="onFamilyChange">
  8. <el-option v-for="f in familyList" :key="f.id" :label="f.name" :value="f.id" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="报告对象" prop="subjectId" required>
  12. <el-select v-model="uploadForm.subjectId" placeholder="请选择家庭成员" filterable class="full-width">
  13. <el-option v-for="m in memberList" :key="m.id" :label="m.nickname || m.realName" :value="m.id" />
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="报告文件" prop="file" required>
  17. <el-upload ref="upload" action="" :auto-upload="false" :limit="1" accept=".pdf" :on-change="handleFileChange" :on-exceed="handleExceed">
  18. <el-button size="small" type="primary">选择PDF文件</el-button>
  19. <div slot="tip" class="el-upload__tip">仅支持PDF格式,大小不超过50MB</div>
  20. </el-upload>
  21. </el-form-item>
  22. <el-form-item label="代上传备注">
  23. <el-input v-model="uploadForm.note" type="textarea" :rows="2" placeholder="选填,备注上传原因" />
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" :loading="uploading" @click="handleUpload">上传并解析</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </el-card>
  30. <!-- 解析结果预览 -->
  31. <el-card v-if="previewResult" class="mt-20">
  32. <div slot="header">
  33. <SectionTitle title="解析结果预览">
  34. <StatusTag :type="previewResult.needBind ? 'warning' : 'success'" :text="previewResult.needBind ? '待绑定成员' : '已匹配成员'" />
  35. </SectionTitle>
  36. </div>
  37. <el-descriptions :column="2" border>
  38. <el-descriptions-item label="被检测人">{{ previewResult.extractedName || '-' }}</el-descriptions-item>
  39. <el-descriptions-item label="报告编号">{{ previewResult.extractedReportNumber || '-' }}</el-descriptions-item>
  40. <el-descriptions-item label="报告日期">{{ previewResult.extractedReportDate || '-' }}</el-descriptions-item>
  41. <el-descriptions-item label="健康总分">{{ previewResult.payload && previewResult.payload.summary && previewResult.payload.summary.overallScore != null ? previewResult.payload.summary.overallScore : '-' }}</el-descriptions-item>
  42. <el-descriptions-item label="菌群健康分">{{ previewResult.payload && previewResult.payload.summary && previewResult.payload.summary.gutHealthScore != null ? previewResult.payload.summary.gutHealthScore : '-' }}</el-descriptions-item>
  43. <el-descriptions-item label="肠型">{{ previewResult.payload && previewResult.payload.summary && previewResult.payload.summary.gutType ? previewResult.payload.summary.gutType : '-' }}</el-descriptions-item>
  44. </el-descriptions>
  45. <div class="mt-20-right">
  46. <el-button @click="previewResult = null">取消</el-button>
  47. <el-button type="primary" :loading="confirming" @click="handleConfirm">确认入库</el-button>
  48. </div>
  49. </el-card>
  50. <!-- AI解读结果 -->
  51. <el-card v-if="analysisResult" class="mt-20">
  52. <div slot="header">
  53. <SectionTitle title="AI解读结果">
  54. <StatusTag type="success" size="small" text="已完成" />
  55. </SectionTitle>
  56. </div>
  57. <div v-html="analysisResult" class="analysis-content"></div>
  58. </el-card>
  59. <!-- 代传历史 -->
  60. <el-card class="mt-20">
  61. <div slot="header">
  62. <SectionTitle title="代上传历史记录" />
  63. </div>
  64. <div class="filter-bar">
  65. <el-select v-model="query.type" placeholder="报告类型" clearable class="w-140">
  66. <el-option label="全部" value=""></el-option>
  67. <el-option label="菌群检测" value="gut_flora"></el-option>
  68. <el-option label="体检报告" value="physical_exam"></el-option>
  69. <el-option label="DAN测评" value="dan"></el-option>
  70. <el-option label="保单" value="insurance"></el-option>
  71. <el-option label="家庭周报" value="fortune"></el-option>
  72. </el-select>
  73. <el-input v-model="query.keyword" placeholder="搜索标题/名称" class="w-200" clearable @keyup.enter.native="loadProxyReports"></el-input>
  74. <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="w-240"></el-date-picker>
  75. <el-button type="primary" @click="loadProxyReports">查询</el-button>
  76. </div>
  77. <div class="adm-table-wrap">
  78. <el-table :data="proxyReportList" border stripe v-loading="proxyListLoading" height="100%">
  79. <el-table-column prop="id" label="ID" width="70" />
  80. <el-table-column label="报告对象" width="120">
  81. <template slot-scope="{ row }">{{ row.subjectName || row.childName || row.personName || row.userName || '-' }}</template>
  82. </el-table-column>
  83. <el-table-column label="报告类型" width="100">
  84. <template slot-scope="{ row }">
  85. <StatusTag :type="getTypeTag(row.reportType)" :text="typeLabel(row.reportType)" />
  86. </template>
  87. </el-table-column>
  88. <el-table-column prop="title" label="标题" min-width="140" show-overflow-tooltip />
  89. <el-table-column label="健康分" width="80">
  90. <template slot-scope="{ row }">{{ row.overallScore == null ? '-' : row.overallScore }}</template>
  91. </el-table-column>
  92. <el-table-column label="上传时间" width="160">
  93. <template slot-scope="{ row }">{{ formatTime(row.createdAt) }}</template>
  94. </el-table-column>
  95. <el-table-column label="操作" width="100" fixed="right">
  96. <template slot-scope="{ row }">
  97. <el-button size="mini" type="text" @click="viewProxyReport(row)">查看</el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. </div>
  102. <el-pagination @size-change="onProxySizeChange" @current-change="onProxyPageChange" :current-page="proxyPage" :page-size="proxySize" :total="proxyTotal" layout="total, prev, pager, next" class="pagination-wrap" />
  103. </el-card>
  104. <!-- 报告详情弹窗 -->
  105. <el-dialog title="报告详情" :visible.sync="detailDialogVisible" width="700px" top="5vh">
  106. <el-descriptions v-if="detailReport" :column="2" border>
  107. <el-descriptions-item label="报告ID">{{ detailReport.id }}</el-descriptions-item>
  108. <el-descriptions-item label="报告类型">{{ detailReport.reportType || typeLabel(detailReport.reportType) }}</el-descriptions-item>
  109. <el-descriptions-item label="报告编号">{{ detailReport.reportNumber || '-' }}</el-descriptions-item>
  110. <el-descriptions-item label="报告日期">{{ detailReport.reportDate || '-' }}</el-descriptions-item>
  111. <el-descriptions-item label="健康总分">{{ detailReport.overallScore || '-' }}</el-descriptions-item>
  112. <el-descriptions-item label="菌群健康分">{{ detailReport.gutHealthScore || '-' }}</el-descriptions-item>
  113. <el-descriptions-item label="肠型">{{ detailReport.gutType || '-' }}</el-descriptions-item>
  114. <el-descriptions-item label="肠道年龄">{{ detailReport.gutAge || '-' }}</el-descriptions-item>
  115. <el-descriptions-item label="AI解读" :span="2">
  116. <div v-html="detailReport.aiAnalysis" class="analysis-content analysis-scroll"></div>
  117. </el-descriptions-item>
  118. </el-descriptions>
  119. <span slot="footer"><el-button @click="detailDialogVisible = false">关闭</el-button></span>
  120. </el-dialog>
  121. </div>
  122. </template>
  123. <script>
  124. import ListStateMixin from '@/mixins/ListStateMixin'
  125. import { getFamilyList, getFamilyMemberList } from '@/api/admin'
  126. import { proxyParseReport, proxyReparseReport, proxyConfirmReport, adminListHealthReports, getHealthReportDetail } from '@/api/admin'
  127. export default {
  128. name: 'ProxyReportUpload',
  129. mixins: [ListStateMixin],
  130. data() {
  131. return {
  132. uploading: false,
  133. confirming: false,
  134. proxyListLoading: false,
  135. familyList: [],
  136. memberList: [],
  137. proxyReportList: [],
  138. previewResult: null,
  139. analysisResult: null,
  140. proxyPage: 1,
  141. proxySize: 20,
  142. proxyTotal: 0,
  143. query: { type: '', keyword: '' },
  144. dateRange: [],
  145. uploadForm: { familyId: null, subjectId: null, file: null, note: '' },
  146. detailDialogVisible: false,
  147. detailReport: null
  148. }
  149. },
  150. created() {
  151. this.loadFamilies()
  152. this.loadProxyReports()
  153. },
  154. methods: {
  155. async loadFamilies() {
  156. try {
  157. var res = await getFamilyList({ page: 1, size: 200 })
  158. this.familyList = res.data && res.data.records ? res.data.records : (res.data || [])
  159. } catch (e) {
  160. console.error(e)
  161. }
  162. },
  163. async onFamilyChange(familyId) {
  164. if (!familyId) { this.memberList = []; return }
  165. try {
  166. var res = await getFamilyMemberList({ familyId: familyId })
  167. this.memberList = res.data || []
  168. this.uploadForm.subjectId = null
  169. } catch (e) {
  170. this.memberList = []
  171. }
  172. },
  173. handleFileChange(file) {
  174. this.uploadForm.file = file.raw
  175. },
  176. handleExceed() {
  177. this.$message.warning('只能上传一个文件')
  178. },
  179. async handleUpload() {
  180. if (!this.uploadForm.familyId) { this.$message.warning('请选择家庭'); return }
  181. if (!this.uploadForm.subjectId) { this.$message.warning('请选择报告对象'); return }
  182. if (!this.uploadForm.file) { this.$message.warning('请选择PDF文件'); return }
  183. this.uploading = true
  184. try {
  185. var res = await proxyParseReport({ familyId: this.uploadForm.familyId, subjectId: this.uploadForm.subjectId, file: this.uploadForm.file, note: this.uploadForm.note })
  186. if (res.code === 200) {
  187. this.previewResult = res.data
  188. this.analysisResult = null
  189. this.notifyParseFallback(res.data)
  190. } else {
  191. this.$message.error(res.message || '解析失败')
  192. }
  193. } catch (e) {
  194. this.$message.error('上传失败: ' + (e.message || ''))
  195. } finally {
  196. this.uploading = false
  197. }
  198. },
  199. async handleConfirm() {
  200. if (!this.previewResult || !this.previewResult.draftId) {
  201. this.$message.warning('没有可确认的草稿')
  202. return
  203. }
  204. this.confirming = true
  205. try {
  206. var res = await proxyConfirmReport({ draftId: this.previewResult.draftId, subjectId: this.uploadForm.subjectId })
  207. if (res.code === 200) {
  208. this.$message.success('报告入库成功')
  209. this.previewResult = null
  210. this.applyAiAnalysisResult(res.data)
  211. this.loadProxyReports()
  212. } else if (this.isDraftExpired(res.message)) {
  213. // B3-2:草稿过期降级——提示重新上传,支持基于 fileUrl 重新解析(复用原文件)
  214. this.reparseExpiredDraft()
  215. } else {
  216. this.$message.error(res.message || '确认失败')
  217. }
  218. } catch (e) {
  219. this.$message.error('确认失败: ' + (e.message || ''))
  220. } finally {
  221. this.confirming = false
  222. }
  223. },
  224. // B3-1:按 B1-5 返回的 aiAnalysisStatus/aiAnalysisMessage 提示「AI 解读未完成:原因」而非静默
  225. applyAiAnalysisResult(data) {
  226. var aiStatus = data && data.aiAnalysisStatus
  227. // 有解读结果即展示;状态缺失时按成功处理(兼容未带 status 的旧返回)
  228. if ((aiStatus === 'success' || !aiStatus) && data && data.aiAnalysis) {
  229. this.analysisResult = data.aiAnalysis
  230. return
  231. }
  232. this.analysisResult = null
  233. var reason = (data && data.aiAnalysisMessage) || (data && data.aiAnalysisStatus) || ''
  234. this.$message.warning('AI解读未完成:' + (reason || '未知原因'))
  235. },
  236. // B3-3:LangGraph 不可用走本地解析时的提示文案
  237. notifyParseFallback(data) {
  238. if (data && data.parseFallback) {
  239. this.$message.warning('解析服务暂不可用,已用本地解析')
  240. }
  241. },
  242. // B3-2:草稿不存在或已过期 → 基于 fileUrl 重新建草稿并解析,不重新传 PDF
  243. async reparseExpiredDraft() {
  244. var fileUrl = this.previewResult && this.previewResult.fileUrl
  245. if (!fileUrl) {
  246. this.$message.error('草稿已过期,且无法获取原文件,请重新上传')
  247. return
  248. }
  249. var confirmed = false
  250. try {
  251. confirmed = await this.$confirm('草稿已过期,是否基于原文件重新解析?', '提示', {
  252. confirmButtonText: '重新解析',
  253. cancelButtonText: '取消',
  254. type: 'warning'
  255. })
  256. } catch (e) {
  257. confirmed = false
  258. }
  259. if (!confirmed) return
  260. this.uploading = true
  261. try {
  262. var res = await proxyReparseReport({
  263. fileUrl: fileUrl,
  264. familyId: this.uploadForm.familyId,
  265. subjectId: this.uploadForm.subjectId,
  266. note: this.uploadForm.note
  267. })
  268. if (res.code === 200) {
  269. this.previewResult = res.data
  270. this.analysisResult = null
  271. this.$message.success('已重新解析,请重新确认入库')
  272. this.notifyParseFallback(res.data)
  273. } else {
  274. this.$message.error(res.message || '重新解析失败')
  275. }
  276. } catch (e) {
  277. this.$message.error('重新解析失败: ' + (e.message || ''))
  278. } finally {
  279. this.uploading = false
  280. }
  281. },
  282. isDraftExpired(message) {
  283. return !!(message && (message.indexOf('草稿不存在') >= 0 || message.indexOf('已过期') >= 0))
  284. },
  285. async loadProxyReports() {
  286. this.proxyListLoading = true
  287. try {
  288. var params = {
  289. page: this.proxyPage,
  290. size: this.proxySize,
  291. type: this.query.type,
  292. keyword: this.query.keyword
  293. }
  294. if (this.dateRange && this.dateRange.length === 2) {
  295. params.startDate = this.dateRange[0].format ? this.dateRange[0].format('YYYY-MM-DD') : this.dateRange[0]
  296. params.endDate = this.dateRange[1].format ? this.dateRange[1].format('YYYY-MM-DD') : this.dateRange[1]
  297. }
  298. var res = await adminListHealthReports(params)
  299. var data = (res && res.data && res.data.data) ? res.data.data : (res && res.data ? res.data : null)
  300. if (data) {
  301. this.proxyReportList = data.records || []
  302. this.proxyTotal = data.total || this.proxyReportList.length
  303. } else {
  304. this.proxyReportList = []
  305. this.proxyTotal = 0
  306. }
  307. } catch (e) {
  308. console.error(e)
  309. this.proxyReportList = []
  310. this.proxyTotal = 0
  311. } finally {
  312. this.proxyListLoading = false
  313. }
  314. },
  315. viewProxyReport(row) {
  316. var self = this
  317. getHealthReportDetail(row.id).then(function(res) {
  318. if (res && res.code === 200) {
  319. // B1-4:详情接口返回嵌套结构 {report:{...}, indicators, ...},取 report 层
  320. self.detailReport = (res.data && res.data.report) ? res.data.report : res.data
  321. self.detailDialogVisible = true
  322. } else {
  323. self.$message.error('加载详情失败')
  324. }
  325. }).catch(function() {
  326. self.$message.error('加载详情失败')
  327. })
  328. },
  329. onProxySizeChange(size) {
  330. this.proxySize = size
  331. this.proxyPage = 1
  332. this.loadProxyReports()
  333. },
  334. onProxyPageChange(page) {
  335. this.proxyPage = page
  336. this.loadProxyReports()
  337. },
  338. typeLabel(type) {
  339. var map = { gut_flora: '菌群检测', physical_exam: '体检报告', dan: 'DAN测评', insurance: '保单', fortune: '家庭周报' }
  340. return map[type] || type || '-'
  341. },
  342. getTypeTag(type) {
  343. var map = { gut_flora: 'success', physical_exam: 'primary', dan: 'warning', insurance: 'info', fortune: 'danger' }
  344. return map[type] || 'info'
  345. }
  346. }
  347. }
  348. </script>
  349. <style scoped>
  350. .proxy-report-upload { padding: 16px; }
  351. .upload-form { max-width: 600px; }
  352. .filter-bar { display: flex; flex-direction: row; align-items: center; gap: 12px; flex-wrap: wrap; }
  353. .pagination-wrap { margin-top: 16px; text-align: right; }
  354. .analysis-content { font-size: 14px; line-height: 1.8; color: var(--adm-text-88); }
  355. .analysis-content :deep(p) { margin: 8px 0; }
  356. /* == C 批内联清理工具类 == */
  357. .w-140 { width: 140px; }
  358. .w-200 { width: 200px; }
  359. .w-240 { width: 240px; }
  360. .full-width { width: 100%; }
  361. .mt-20 { margin-top: 24px; }
  362. .mt-20-right { margin-top: 24px; text-align: right; }
  363. .analysis-scroll { max-height: 300px; overflow: auto; }
  364. </style>