report-detail.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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, extractReferralCode } 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 + '&refCode=' + 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 + '&refCode=' + 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. this.referralCode = extractReferralCode(res)
  75. } catch (e) {}
  76. this.referralCodeLoaded = true
  77. },
  78. loadDetail() {
  79. var self = this
  80. getReportSummaryDetail(self.reportId).then(function(res) {
  81. if (res && res.data) {
  82. self.detail = res.data
  83. uni.setNavigationBarTitle({ title: self.detail.title || '报告详情' })
  84. }
  85. }).catch(function(e) {
  86. console.log('加载详情失败', e)
  87. uni.showToast({ title: '加载失败', icon: 'none' })
  88. })
  89. },
  90. downloadReport() {
  91. var self = this
  92. uni.showLoading({ title: '下载中...' })
  93. downloadReportSummary(self.reportId).then(function(res) {
  94. if (res && res.data && res.data.fileUrl) {
  95. var url = res.data.fileUrl
  96. var name = res.data.fileName || 'report'
  97. uni.downloadFile({
  98. url: url,
  99. filePath: wx.env.USER_DATA_PATH + '/' + name,
  100. success: function(res2) {
  101. uni.saveFileToDisk({
  102. filePath: res2.filePath,
  103. success: function() {
  104. uni.showToast({ title: '保存成功', icon: 'success' })
  105. },
  106. fail: function() {
  107. uni.showToast({ title: '保存失败', icon: 'none' })
  108. }
  109. })
  110. },
  111. fail: function() {
  112. uni.showToast({ title: '下载失败', icon: 'none' })
  113. },
  114. complete: function() {
  115. uni.hideLoading()
  116. }
  117. })
  118. }
  119. }).catch(function(e) {
  120. uni.hideLoading()
  121. uni.showToast({ title: '下载失败', icon: 'none' })
  122. })
  123. },
  124. goToOriginalDetail() {
  125. var route = this.detail.detailRoute || ''
  126. if (route) {
  127. var url = route + (this.detail.sourceId ? '?reportId=' + this.detail.sourceId : '')
  128. uni.navigateTo({ url: url })
  129. } else {
  130. uni.showToast({ title: '暂无详情页面', icon: 'none' })
  131. }
  132. },
  133. getBadgeClass(reportType) {
  134. return reportType || 'default'
  135. },
  136. formatDate(dateStr) {
  137. if (!dateStr) return '--'
  138. return dateStr
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. .container {
  145. min-height: 100vh;
  146. background: #f5f7fa;
  147. padding: 24rpx;
  148. }
  149. .report-header {
  150. background: #fff;
  151. border-radius: 16rpx;
  152. padding: 32rpx 24rpx;
  153. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  154. margin-bottom: 16rpx;
  155. }
  156. .type-badge {
  157. display: inline-block;
  158. font-size: 22rpx;
  159. padding: 6rpx 20rpx;
  160. border-radius: 12rpx;
  161. margin-bottom: 16rpx;
  162. }
  163. .badge-gut_flora { background: #E8F5E9; color: #2E7D32; }
  164. .badge-physical_exam { background: #E3F2FD; color: #1565C0; }
  165. .badge-dan { background: #F3E5F5; color: #7B1FA2; }
  166. .badge-insurance { background: #FFF3E0; color: #E65100; }
  167. .badge-fortune { background: #FCE4EC; color: #C62828; }
  168. .report-title {
  169. font-size: 32rpx;
  170. font-weight: bold;
  171. color: #333;
  172. display: block;
  173. margin-bottom: 12rpx;
  174. }
  175. .report-meta {
  176. display: flex;
  177. flex-direction: row;
  178. margin-bottom: 16rpx;
  179. }
  180. .meta-item {
  181. font-size: 24rpx;
  182. color: #888;
  183. margin-right: 24rpx;
  184. }
  185. .score-section {
  186. display: flex;
  187. flex-direction: row;
  188. align-items: baseline;
  189. }
  190. .score {
  191. font-size: 56rpx;
  192. font-weight: bold;
  193. color: #5B9BD5;
  194. }
  195. .score-label {
  196. font-size: 24rpx;
  197. color: #888;
  198. margin-left: 12rpx;
  199. }
  200. .summary-section {
  201. background: #fff;
  202. border-radius: 16rpx;
  203. padding: 24rpx;
  204. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  205. margin-bottom: 16rpx;
  206. }
  207. .section-title {
  208. font-size: 28rpx;
  209. font-weight: bold;
  210. color: #333;
  211. display: block;
  212. margin-bottom: 12rpx;
  213. }
  214. .summary-text {
  215. font-size: 26rpx;
  216. color: #666;
  217. line-height: 1.6;
  218. }
  219. .action-section {
  220. background: #fff;
  221. border-radius: 16rpx;
  222. padding: 24rpx;
  223. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  224. }
  225. .action-btn {
  226. background: #5B9BD5;
  227. color: #fff;
  228. font-size: 28rpx;
  229. border-radius: 12rpx;
  230. margin-bottom: 16rpx;
  231. }
  232. .action-btn.secondary {
  233. background: #f0f0f0;
  234. color: #333;
  235. margin-bottom: 0;
  236. }
  237. </style>