report-detail.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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, getReferralCode } from '../../utils/api.js'
  32. export default {
  33. data() {
  34. return {
  35. reportId: null,
  36. detail: {},
  37. referralCode: '',
  38. referralCodeLoaded: false
  39. }
  40. },
  41. onLoad(options) {
  42. if (options && options.id) {
  43. this.reportId = parseInt(options.id)
  44. this.loadDetail()
  45. }
  46. this.loadReferralCode()
  47. },
  48. onShareAppMessage() {
  49. var path = '/pages/profile/report-detail?id=' + this.reportId
  50. if (this.referralCode) {
  51. path = path + '&inviteCode=' + this.referralCode
  52. }
  53. return {
  54. title: this.detail.title || '浠艾福报告',
  55. path: path
  56. }
  57. },
  58. onShareTimeline() {
  59. var query = 'id=' + this.reportId
  60. if (this.referralCode) {
  61. query = query + '&inviteCode=' + this.referralCode
  62. }
  63. return {
  64. title: this.detail.title || '浠艾福报告',
  65. query: query
  66. }
  67. },
  68. methods: {
  69. /** 获取自己的邀请码用于分享 */
  70. async loadReferralCode() {
  71. if (this.referralCodeLoaded || !uni.getStorageSync('token')) return
  72. try {
  73. var res = await getReferralCode()
  74. if (res && res.code === 200 && res.data) {
  75. this.referralCode = res.data.referralCode || res.data.code || ''
  76. }
  77. } catch (e) {}
  78. this.referralCodeLoaded = true
  79. },
  80. loadDetail() {
  81. var self = this
  82. getReportSummaryDetail(self.reportId).then(function(res) {
  83. if (res && res.data) {
  84. self.detail = res.data
  85. uni.setNavigationBarTitle({ title: self.detail.title || '报告详情' })
  86. }
  87. }).catch(function(e) {
  88. console.log('加载详情失败', e)
  89. uni.showToast({ title: '加载失败', icon: 'none' })
  90. })
  91. },
  92. downloadReport() {
  93. var self = this
  94. uni.showLoading({ title: '下载中...' })
  95. downloadReportSummary(self.reportId).then(function(res) {
  96. if (res && res.data && res.data.fileUrl) {
  97. var url = res.data.fileUrl
  98. var name = res.data.fileName || 'report'
  99. uni.downloadFile({
  100. url: url,
  101. filePath: wx.env.USER_DATA_PATH + '/' + name,
  102. success: function(res2) {
  103. uni.saveFileToDisk({
  104. filePath: res2.filePath,
  105. success: function() {
  106. uni.showToast({ title: '保存成功', icon: 'success' })
  107. },
  108. fail: function() {
  109. uni.showToast({ title: '保存失败', icon: 'none' })
  110. }
  111. })
  112. },
  113. fail: function() {
  114. uni.showToast({ title: '下载失败', icon: 'none' })
  115. },
  116. complete: function() {
  117. uni.hideLoading()
  118. }
  119. })
  120. }
  121. }).catch(function(e) {
  122. uni.hideLoading()
  123. uni.showToast({ title: '下载失败', icon: 'none' })
  124. })
  125. },
  126. goToOriginalDetail() {
  127. var route = this.detail.detailRoute || ''
  128. if (route) {
  129. var url = route + (this.detail.sourceId ? '?reportId=' + this.detail.sourceId : '')
  130. uni.navigateTo({ url: url })
  131. } else {
  132. uni.showToast({ title: '暂无详情页面', icon: 'none' })
  133. }
  134. },
  135. getBadgeClass(reportType) {
  136. return reportType || 'default'
  137. },
  138. formatDate(dateStr) {
  139. if (!dateStr) return '--'
  140. return dateStr
  141. }
  142. }
  143. }
  144. </script>
  145. <style scoped>
  146. .container {
  147. min-height: 100vh;
  148. background: #f5f7fa;
  149. padding: 24rpx;
  150. }
  151. .report-header {
  152. background: #fff;
  153. border-radius: 16rpx;
  154. padding: 32rpx 24rpx;
  155. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  156. margin-bottom: 16rpx;
  157. }
  158. .type-badge {
  159. display: inline-block;
  160. font-size: 22rpx;
  161. padding: 6rpx 20rpx;
  162. border-radius: 12rpx;
  163. margin-bottom: 16rpx;
  164. }
  165. .badge-gut_flora { background: #E8F5E9; color: #2E7D32; }
  166. .badge-physical_exam { background: #E3F2FD; color: #1565C0; }
  167. .badge-dan { background: #F3E5F5; color: #7B1FA2; }
  168. .badge-insurance { background: #FFF3E0; color: #E65100; }
  169. .badge-fortune { background: #FCE4EC; color: #C62828; }
  170. .report-title {
  171. font-size: 32rpx;
  172. font-weight: bold;
  173. color: #333;
  174. display: block;
  175. margin-bottom: 12rpx;
  176. }
  177. .report-meta {
  178. display: flex;
  179. flex-direction: row;
  180. margin-bottom: 16rpx;
  181. }
  182. .meta-item {
  183. font-size: 24rpx;
  184. color: #888;
  185. margin-right: 24rpx;
  186. }
  187. .score-section {
  188. display: flex;
  189. flex-direction: row;
  190. align-items: baseline;
  191. }
  192. .score {
  193. font-size: 56rpx;
  194. font-weight: bold;
  195. color: #5B9BD5;
  196. }
  197. .score-label {
  198. font-size: 24rpx;
  199. color: #888;
  200. margin-left: 12rpx;
  201. }
  202. .summary-section {
  203. background: #fff;
  204. border-radius: 16rpx;
  205. padding: 24rpx;
  206. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  207. margin-bottom: 16rpx;
  208. }
  209. .section-title {
  210. font-size: 28rpx;
  211. font-weight: bold;
  212. color: #333;
  213. display: block;
  214. margin-bottom: 12rpx;
  215. }
  216. .summary-text {
  217. font-size: 26rpx;
  218. color: #666;
  219. line-height: 1.6;
  220. }
  221. .action-section {
  222. background: #fff;
  223. border-radius: 16rpx;
  224. padding: 24rpx;
  225. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  226. }
  227. .action-btn {
  228. background: #5B9BD5;
  229. color: #fff;
  230. font-size: 28rpx;
  231. border-radius: 12rpx;
  232. margin-bottom: 16rpx;
  233. }
  234. .action-btn.secondary {
  235. background: #f0f0f0;
  236. color: #333;
  237. margin-bottom: 0;
  238. }
  239. </style>