report-detail.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  33. export default {
  34. mixins: [fontScaleMixin],
  35. data() {
  36. return {
  37. reportId: null,
  38. detail: {},
  39. referralCode: '',
  40. referralCodeLoaded: false
  41. }
  42. },
  43. onLoad(options) {
  44. if (options && options.id) {
  45. this.reportId = parseInt(options.id)
  46. this.loadDetail()
  47. }
  48. this.loadReferralCode()
  49. },
  50. onShareAppMessage() {
  51. var path = '/pages/profile/report-detail?id=' + this.reportId
  52. if (this.referralCode) {
  53. path = path + '&refCode=' + this.referralCode
  54. }
  55. return {
  56. title: this.detail.title || '浠艾福报告',
  57. path: path
  58. }
  59. },
  60. onShareTimeline() {
  61. var query = 'id=' + this.reportId
  62. if (this.referralCode) {
  63. query = query + '&refCode=' + this.referralCode
  64. }
  65. return {
  66. title: this.detail.title || '浠艾福报告',
  67. query: query
  68. }
  69. },
  70. methods: {
  71. /** 获取自己的邀请码用于分享 */
  72. async loadReferralCode() {
  73. if (this.referralCodeLoaded || !uni.getStorageSync('token')) return
  74. try {
  75. var res = await getReferralCode()
  76. this.referralCode = extractReferralCode(res)
  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 lang="scss">
  146. .container {
  147. min-height: 100vh;
  148. background: $app-bg;
  149. padding: 24rpx;
  150. }
  151. .report-header {
  152. background: $app-surface;
  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: calc(22rpx * var(--font-scale, 1));
  161. padding: 6rpx 20rpx;
  162. border-radius: 16rpx;
  163. margin-bottom: 16rpx;
  164. }
  165. .badge-gut_flora { background: $mat-green-tint; color: $mat-green-strong; }
  166. .badge-physical_exam { background: $mat-blue-tint; color: $mat-blue-strong; }
  167. .badge-dan { background: $fortune-3-tint; color: $fortune-3-ink; }
  168. .badge-insurance { background: $fortune-1-tint; color: $mat-orange-strong; }
  169. .badge-fortune { background: $accent-pink-tint-2; color: $status-danger-strong-2; }
  170. .report-title {
  171. font-size: calc(32rpx * var(--font-scale, 1));
  172. font-weight: bold;
  173. color: $facade-text-strong;
  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: calc(24rpx * var(--font-scale, 1));
  184. color: $facade-text-faint;
  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: calc($uni-font-size-display * var(--font-scale, 1));
  194. font-weight: bold;
  195. color: $brand-primary;
  196. }
  197. .score-label {
  198. font-size: calc(24rpx * var(--font-scale, 1));
  199. color: $facade-text-faint;
  200. margin-left: 12rpx;
  201. }
  202. .summary-section {
  203. background: $app-surface;
  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: calc(28rpx * var(--font-scale, 1));
  211. font-weight: bold;
  212. color: $facade-text-strong;
  213. display: block;
  214. margin-bottom: 12rpx;
  215. }
  216. .summary-text {
  217. font-size: calc(26rpx * var(--font-scale, 1));
  218. color: $facade-text-body;
  219. line-height: 1.6;
  220. }
  221. .action-section {
  222. background: $app-surface;
  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: $brand-primary;
  229. color: $app-surface;
  230. font-size: calc(28rpx * var(--font-scale, 1));
  231. border-radius: 16rpx;
  232. margin-bottom: 16rpx;
  233. }
  234. .action-btn.secondary {
  235. background: $facade-fill;
  236. color: $facade-text-strong;
  237. margin-bottom: 0;
  238. }
  239. </style>