report-list.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="list-container">
  3. <!-- 成员过滤 -->
  4. <view class="member-filter">
  5. <scroll-view class="filter-scroll" scroll-x="true" :show-scrollbar="false">
  6. <view class="filter-chips">
  7. <view class="chip" :class="{ 'chip-active': !selectedMemberId }" @click="selectAllMembers">
  8. <text class="chip-text">全部</text>
  9. </view>
  10. <view
  11. class="chip"
  12. v-for="item in members"
  13. :key="item.id"
  14. :class="{ 'chip-active': selectedMemberId === item._filterId }"
  15. @click="selectMember(item)"
  16. >
  17. <text class="chip-text">{{ item.nickname || '成员' }}</text>
  18. </view>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. <!-- 加载状态 -->
  23. <view class="loading-wrap" v-if="loading">
  24. <text class="loading-text">加载中...</text>
  25. </view>
  26. <!-- 报告列表 -->
  27. <view class="report-list" v-else-if="reports.length > 0">
  28. <swipe-action v-for="item in reports" :key="item.id">
  29. <view class="report-card" @click="goToDetail(item.id, item.reportType)">
  30. <view class="report-card-left">
  31. <view class="report-type-badge" :class="'badge-' + (item.reportType === 'gut_flora' ? 'gut' : item.reportType === 'tongue' ? 'tongue' : 'exam')">
  32. <text>{{ item.reportType === 'gut_flora' ? '肠道检测' : item.reportType === 'tongue' ? '舌诊' : '体检报告' }}</text>
  33. </view>
  34. <text class="report-person" v-if="item.personName">{{ item.personName }}</text>
  35. <text class="report-date">报告日期:{{ formatDate(item.reportDate) }}</text>
  36. <text class="report-upload-date">上传日期:{{ formatDate(item.createdAt) }}</text>
  37. </view>
  38. <view class="report-card-right">
  39. <text class="report-score">{{ item.overallScore || '--' }}<text class="score-unit">分</text></text>
  40. <text class="report-arrow">›</text>
  41. </view>
  42. </view>
  43. <template #right>
  44. <button class="swipe-delete" @click.stop="confirmDelete(item)">删除</button>
  45. </template>
  46. </swipe-action>
  47. </view>
  48. <!-- 空状态 -->
  49. <view class="empty-wrap" v-else>
  50. <text class="empty-icon">📋</text>
  51. <text class="empty-title">暂无健康报告</text>
  52. <text class="empty-desc">上传体检报告或肠道检测报告,获取 解读</text>
  53. <view class="empty-btn" @click="goToUpload">上传报告</view>
  54. </view>
  55. <!-- 底部占位 -->
  56. <view class="bottom-spacer"></view>
  57. </view>
  58. </template>
  59. <script>
  60. import { getReportList, deleteReport, getFamilyMemberList } from '../../utils/api.js'
  61. import { parseDate } from '../../utils/format.js'
  62. export default {
  63. data() {
  64. return {
  65. reports: [],
  66. members: [],
  67. selectedMemberId: null,
  68. loading: false,
  69. memberId: null
  70. }
  71. },
  72. onLoad(options) {
  73. // 导航参数可带初始 memberId(预选对应成员);未传时默认"全部"
  74. this.memberId = options.memberId ? parseInt(options.memberId) : null
  75. this.selectedMemberId = this.memberId
  76. this.loadMembers()
  77. this.loadData()
  78. },
  79. methods: {
  80. loadMembers() {
  81. var self = this
  82. getFamilyMemberList({}).then(function(res) {
  83. if (res.code === 200 && Array.isArray(res.data)) {
  84. // _filterId 预计算,供 :class 内联比较使用(小程序 :class 禁止方法调用)
  85. var list = []
  86. for (var i = 0; i < res.data.length; i++) {
  87. var m = res.data[i]
  88. list.push({
  89. id: m.id,
  90. nickname: m.nickname,
  91. avatar: m.avatar,
  92. _filterId: m.id || m.userId
  93. })
  94. }
  95. self.members = list
  96. }
  97. }).catch(function(e) {
  98. console.log('获取家庭成员失败', e)
  99. })
  100. },
  101. selectAllMembers() {
  102. if (this.selectedMemberId === null) return
  103. this.selectedMemberId = null
  104. this.loadData()
  105. },
  106. selectMember(item) {
  107. var filterId = item._filterId
  108. if (this.selectedMemberId === filterId) return
  109. this.selectedMemberId = filterId
  110. this.loadData()
  111. },
  112. loadData() {
  113. var self = this
  114. self.loading = true
  115. getReportList(self.selectedMemberId).then(function(res) {
  116. self.reports = res.data || []
  117. }).catch(function(e) {
  118. console.log('获取报告列表失败', e)
  119. uni.showToast({ title: '加载失败', icon: 'none' })
  120. }).finally(function() {
  121. self.loading = false
  122. })
  123. },
  124. goToDetail(reportId, reportType) {
  125. var url
  126. if (reportType === 'gut_flora') {
  127. url = '/pages/health/gut-flora-detail?reportId=' + reportId
  128. } else if (reportType === 'dan') {
  129. url = '/pages/dan-assessment/report-result?reportId=' + reportId
  130. } else {
  131. url = '/pages/health/report-detail?reportType=' + (reportType || 'gut_flora') + '&reportId=' + reportId
  132. }
  133. uni.navigateTo({ url: url })
  134. },
  135. goToUpload() {
  136. uni.navigateTo({ url: '/pages/health/report-upload' })
  137. },
  138. confirmDelete(item) {
  139. var self = this
  140. uni.showModal({
  141. title: '删除报告',
  142. content: '确定删除该健康报告吗?删除后不可恢复。',
  143. confirmColor: '#F56C6C',
  144. success: function(res) {
  145. if (!res.confirm) return
  146. self.doDelete(item)
  147. }
  148. })
  149. },
  150. doDelete(item) {
  151. var self = this
  152. deleteReport(item.id).then(function(res) {
  153. if (res.code === 200) {
  154. uni.showToast({ title: '已删除', icon: 'success' })
  155. self.loadData()
  156. } else {
  157. uni.showToast({ title: res.message || '删除失败', icon: 'none' })
  158. }
  159. }).catch(function(e) {
  160. console.log('删除报告失败', e)
  161. uni.showToast({ title: '删除失败', icon: 'none' })
  162. })
  163. },
  164. formatDate(dateStr) {
  165. if (!dateStr) return '--'
  166. var d = parseDate(dateStr)
  167. if (!d) return dateStr
  168. var y = d.getFullYear()
  169. var m = ('' + (d.getMonth() + 1)).padStart(2, '0')
  170. var day = ('' + d.getDate()).padStart(2, '0')
  171. return y + '-' + m + '-' + day
  172. }
  173. }
  174. }
  175. </script>
  176. <style scoped>
  177. .list-container {
  178. min-height: 100vh;
  179. background: #F5F7FA;
  180. }
  181. /* ===== 成员过滤 ===== */
  182. .member-filter {
  183. background: #F5F7FA;
  184. padding: 20rpx 30rpx 4rpx;
  185. }
  186. .filter-scroll {
  187. width: 100%;
  188. white-space: nowrap;
  189. }
  190. .filter-chips {
  191. display: flex;
  192. flex-direction: row;
  193. }
  194. .chip {
  195. flex-shrink: 0;
  196. background: #fff;
  197. border: 1rpx solid #E2E8F0;
  198. border-radius: 28rpx;
  199. padding: 10rpx 30rpx;
  200. margin-right: 16rpx;
  201. }
  202. .chip-active {
  203. background: #5B9BD5;
  204. border-color: #5B9BD5;
  205. }
  206. .chip-text {
  207. font-size: 26rpx;
  208. color: #64748B;
  209. }
  210. .chip-active .chip-text {
  211. color: #fff;
  212. }
  213. /* ===== 加载状态 ===== */
  214. .loading-wrap {
  215. display: flex;
  216. justify-content: center;
  217. padding: 80rpx 0;
  218. }
  219. .loading-text {
  220. font-size: 28rpx;
  221. color: #999;
  222. }
  223. /* ===== 报告列表 ===== */
  224. .report-list {
  225. margin: 20rpx 30rpx;
  226. }
  227. .report-card {
  228. background: #fff;
  229. border-radius: 16rpx;
  230. padding: 28rpx 24rpx;
  231. margin-bottom: 16rpx;
  232. display: flex;
  233. flex-direction: row;
  234. align-items: center;
  235. justify-content: space-between;
  236. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  237. }
  238. .report-card:active {
  239. opacity: 0.8;
  240. }
  241. .report-card-left {
  242. display: flex;
  243. flex-direction: column;
  244. gap: 2rpx;
  245. flex: 1;
  246. min-width: 0;
  247. }
  248. .report-type-badge {
  249. display: inline-block;
  250. font-size: 22rpx;
  251. padding: 4rpx 18rpx;
  252. border-radius: 20rpx;
  253. align-self: flex-start;
  254. }
  255. .badge-exam {
  256. background: #E3F2FD;
  257. color: #1565C0;
  258. }
  259. .badge-gut {
  260. background: #E8F5E9;
  261. color: #2E7D32;
  262. }
  263. .badge-tongue {
  264. background: #FFF3E0;
  265. color: #E65100;
  266. }
  267. .report-person {
  268. font-size: 26rpx;
  269. color: #333;
  270. font-weight: 500;
  271. margin-top: 4rpx;
  272. }
  273. .report-date {
  274. font-size: 22rpx;
  275. color: #888;
  276. margin-top: 4rpx;
  277. }
  278. .report-upload-date {
  279. font-size: 22rpx;
  280. color: #AAA;
  281. margin-top: 2rpx;
  282. }
  283. .report-card-right {
  284. display: flex;
  285. flex-direction: row;
  286. align-items: center;
  287. gap: 12rpx;
  288. }
  289. .report-score {
  290. font-size: 36rpx;
  291. font-weight: bold;
  292. color: #333;
  293. }
  294. .score-unit {
  295. font-size: 22rpx;
  296. color: #999;
  297. font-weight: normal;
  298. }
  299. .report-arrow {
  300. font-size: 36rpx;
  301. color: #CCC;
  302. }
  303. /* ===== 空状态 ===== */
  304. .empty-wrap {
  305. display: flex;
  306. flex-direction: column;
  307. align-items: center;
  308. padding: 120rpx 60rpx;
  309. }
  310. .empty-icon {
  311. font-size: 80rpx;
  312. margin-bottom: 24rpx;
  313. }
  314. .empty-title {
  315. font-size: 32rpx;
  316. font-weight: bold;
  317. color: #333;
  318. margin-bottom: 12rpx;
  319. }
  320. .empty-desc {
  321. font-size: 26rpx;
  322. color: #999;
  323. text-align: center;
  324. margin-bottom: 40rpx;
  325. line-height: 1.5;
  326. }
  327. .empty-btn {
  328. background: #5B9BD5;
  329. color: #fff;
  330. font-size: 28rpx;
  331. padding: 20rpx 60rpx;
  332. border-radius: 40rpx;
  333. }
  334. .empty-btn:active {
  335. opacity: 0.8;
  336. }
  337. /* ===== 滑动删除 ===== */
  338. .swipe-delete {
  339. height: 100%;
  340. width: 160rpx;
  341. background: #F56C6C;
  342. color: #fff;
  343. font-size: 28rpx;
  344. border: none;
  345. border-radius: 0;
  346. }
  347. /* swipe-action 组件内部样式覆盖 */
  348. /deep/ .uni-swipe-action__content {
  349. border-radius: 16rpx;
  350. }
  351. /deep/ .uni-swipe-action__button {
  352. border-radius: 0 16rpx 16rpx 0;
  353. }
  354. /* ===== 底部 ===== */
  355. .bottom-spacer {
  356. height: 60rpx;
  357. }
  358. </style>