report-detail.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="container">
  3. <view class="report-header">
  4. <view class="type-badge" :class="'badge-' + getBadgeClass(detail.reportType)">
  5. <text>{{ detail.reportTypeName || '报告' }}</text>
  6. </view>
  7. <text class="report-title">{{ detail.title }}</text>
  8. <view class="report-meta">
  9. <text class="meta-item">{{ detail.subjectName }}</text>
  10. <text class="meta-item">{{ formatDate(detail.reportDate) }}</text>
  11. </view>
  12. <view class="score-section" v-if="detail.overallScore !== null && detail.overallScore !== undefined">
  13. <text class="score">{{ detail.overallScore }}</text>
  14. <text class="score-label">综合评分</text>
  15. </view>
  16. </view>
  17. <view class="summary-section" v-if="detail.summary">
  18. <text class="section-title">报告摘要</text>
  19. <text class="summary-text">{{ detail.summary }}</text>
  20. </view>
  21. <view class="action-section" v-if="detail.hasFile">
  22. <button class="action-btn" @click="downloadReport">下载报告</button>
  23. <button class="action-btn secondary" @click="goToOriginalDetail">查看原始详情</button>
  24. </view>
  25. <view class="action-section" v-else>
  26. <button class="action-btn secondary" @click="goToOriginalDetail">查看原始详情</button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { getReportSummaryDetail, downloadReportSummary } from '../../utils/api.js'
  32. export default {
  33. data() {
  34. return {
  35. reportId: null,
  36. detail: {}
  37. }
  38. },
  39. onLoad(options) {
  40. if (options && options.id) {
  41. this.reportId = parseInt(options.id)
  42. this.loadDetail()
  43. }
  44. },
  45. onShareAppMessage() {
  46. return {
  47. title: '浠艾福报告',
  48. path: '/pages/profile/report-detail?id=' + this.reportId
  49. }
  50. },
  51. methods: {
  52. loadDetail() {
  53. var self = this
  54. getReportSummaryDetail(self.reportId).then(function(res) {
  55. if (res && res.data) {
  56. self.detail = res.data
  57. uni.setNavigationBarTitle({ title: self.detail.title || '报告详情' })
  58. }
  59. }).catch(function(e) {
  60. console.log('加载详情失败', e)
  61. uni.showToast({ title: '加载失败', icon: 'none' })
  62. })
  63. },
  64. downloadReport() {
  65. var self = this
  66. uni.showLoading({ title: '下载中...' })
  67. downloadReportSummary(self.reportId).then(function(res) {
  68. if (res && res.data && res.data.fileUrl) {
  69. var url = res.data.fileUrl
  70. var name = res.data.fileName || 'report'
  71. uni.downloadFile({
  72. url: url,
  73. filePath: wx.env.USER_DATA_PATH + '/' + name,
  74. success: function(res2) {
  75. uni.saveFileToDisk({
  76. filePath: res2.filePath,
  77. success: function() {
  78. uni.showToast({ title: '保存成功', icon: 'success' })
  79. },
  80. fail: function() {
  81. uni.showToast({ title: '保存失败', icon: 'none' })
  82. }
  83. })
  84. },
  85. fail: function() {
  86. uni.showToast({ title: '下载失败', icon: 'none' })
  87. },
  88. complete: function() {
  89. uni.hideLoading()
  90. }
  91. })
  92. }
  93. }).catch(function(e) {
  94. uni.hideLoading()
  95. uni.showToast({ title: '下载失败', icon: 'none' })
  96. })
  97. },
  98. goToOriginalDetail() {
  99. var route = this.detail.detailRoute || ''
  100. if (route) {
  101. var url = route + (this.detail.sourceId ? '?reportId=' + this.detail.sourceId : '')
  102. uni.navigateTo({ url: url })
  103. } else {
  104. uni.showToast({ title: '暂无详情页面', icon: 'none' })
  105. }
  106. },
  107. getBadgeClass(reportType) {
  108. return reportType || 'default'
  109. },
  110. formatDate(dateStr) {
  111. if (!dateStr) return '--'
  112. return dateStr
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped>
  118. .container {
  119. min-height: 100vh;
  120. background: #f5f7fa;
  121. padding: 24rpx;
  122. }
  123. .report-header {
  124. background: #fff;
  125. border-radius: 16rpx;
  126. padding: 32rpx 24rpx;
  127. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  128. margin-bottom: 16rpx;
  129. }
  130. .type-badge {
  131. display: inline-block;
  132. font-size: 22rpx;
  133. padding: 6rpx 20rpx;
  134. border-radius: 12rpx;
  135. margin-bottom: 16rpx;
  136. }
  137. .badge-gut_flora { background: #E8F5E9; color: #2E7D32; }
  138. .badge-physical_exam { background: #E3F2FD; color: #1565C0; }
  139. .badge-dan { background: #F3E5F5; color: #7B1FA2; }
  140. .badge-insurance { background: #FFF3E0; color: #E65100; }
  141. .badge-fortune { background: #FCE4EC; color: #C62828; }
  142. .report-title {
  143. font-size: 32rpx;
  144. font-weight: bold;
  145. color: #333;
  146. display: block;
  147. margin-bottom: 12rpx;
  148. }
  149. .report-meta {
  150. display: flex;
  151. flex-direction: row;
  152. margin-bottom: 16rpx;
  153. }
  154. .meta-item {
  155. font-size: 24rpx;
  156. color: #888;
  157. margin-right: 24rpx;
  158. }
  159. .score-section {
  160. display: flex;
  161. flex-direction: row;
  162. align-items: baseline;
  163. }
  164. .score {
  165. font-size: 56rpx;
  166. font-weight: bold;
  167. color: #5B9BD5;
  168. }
  169. .score-label {
  170. font-size: 24rpx;
  171. color: #888;
  172. margin-left: 12rpx;
  173. }
  174. .summary-section {
  175. background: #fff;
  176. border-radius: 16rpx;
  177. padding: 24rpx;
  178. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  179. margin-bottom: 16rpx;
  180. }
  181. .section-title {
  182. font-size: 28rpx;
  183. font-weight: bold;
  184. color: #333;
  185. display: block;
  186. margin-bottom: 12rpx;
  187. }
  188. .summary-text {
  189. font-size: 26rpx;
  190. color: #666;
  191. line-height: 1.6;
  192. }
  193. .action-section {
  194. background: #fff;
  195. border-radius: 16rpx;
  196. padding: 24rpx;
  197. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  198. }
  199. .action-btn {
  200. background: #5B9BD5;
  201. color: #fff;
  202. font-size: 28rpx;
  203. border-radius: 12rpx;
  204. margin-bottom: 16rpx;
  205. }
  206. .action-btn.secondary {
  207. background: #f0f0f0;
  208. color: #333;
  209. margin-bottom: 0;
  210. }
  211. </style>