wisdom-section.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="wisdom-section">
  3. <!-- 最新测评结果 -->
  4. <view class="section-card" v-if="latestResult">
  5. <view class="section-header">
  6. <text class="section-title">🧠 最新测评结果</text>
  7. </view>
  8. <view class="result-overview" @click="goResultDetail">
  9. <text class="result-score">{{ latestResult.score || '--' }}</text>
  10. <text class="result-dimension">{{ latestResult.dimensionName || latestResult.title || '综合测评' }}</text>
  11. </view>
  12. <view class="result-date">测评日期:{{ formatDate(latestResult.createTime || latestResult.testDate) }}</view>
  13. </view>
  14. <view class="section-card" v-else-if="!loading && memberId">
  15. <view class="empty-state">
  16. <text class="empty-text">暂无测评记录</text>
  17. <text class="empty-sub">完成测评后结果将显示在这里</text>
  18. </view>
  19. </view>
  20. <!-- 测评历史 -->
  21. <view class="section-card" v-if="historyList.length > 0">
  22. <view class="section-header">
  23. <text class="section-title">📋 测评历史</text>
  24. </view>
  25. <view class="history-item" v-for="item in historyList" :key="item.id" @click="goResultDetail">
  26. <text class="history-title">{{ item.title || item.dimensionName || '测评' }}</text>
  27. <text class="history-score">{{ item.score || '--' }}</text>
  28. <text class="history-date">{{ formatDate(item.createTime || item.testDate) }}</text>
  29. </view>
  30. </view>
  31. <!-- 非孩子成员提示 -->
  32. <view class="section-card" v-if="!memberId && !loading">
  33. <view class="empty-state">
  34. <text class="empty-text">该成员暂无测评数据</text>
  35. </view>
  36. </view>
  37. <!-- 加载中 -->
  38. <view class="loading" v-if="loading">加载中...</view>
  39. </view>
  40. </template>
  41. <script>
  42. import { getAssessmentLatestResult, getAssessmentHistory } from '../../utils/api.js'
  43. import { parseDate } from '../../utils/format.js'
  44. export default {
  45. props: {
  46. memberId: {
  47. type: [Number, String],
  48. default: null
  49. },
  50. memberType: {
  51. type: String,
  52. default: ''
  53. },
  54. memberInfo: {
  55. type: Object,
  56. default: null
  57. },
  58. sandboxData: {
  59. type: Object,
  60. default: null
  61. },
  62. energyMap: {
  63. type: Object,
  64. default: null
  65. }
  66. },
  67. data: function() {
  68. return {
  69. loading: true,
  70. latestResult: null,
  71. historyList: []
  72. }
  73. },
  74. mounted: function() {
  75. if (this.memberId) {
  76. this.loadData()
  77. } else {
  78. this.loading = false
  79. }
  80. },
  81. methods: {
  82. loadData: function() {
  83. var self = this
  84. getAssessmentLatestResult(this.memberId).then(function(res) {
  85. if (res.code === 200 && res.data) {
  86. self.latestResult = res.data
  87. }
  88. }).catch(function(e) {
  89. console.log('加载测评结果失败', e)
  90. })
  91. getAssessmentHistory(this.memberId, 5).then(function(res) {
  92. if (res.code === 200 && res.data) {
  93. self.historyList = Array.isArray(res.data) ? res.data : (res.data.records || [])
  94. }
  95. }).catch(function(e) {
  96. console.log('加载测评历史失败', e)
  97. })
  98. this.loading = false
  99. },
  100. formatDate: function(dateStr) {
  101. if (!dateStr) return ''
  102. var d = parseDate(dateStr)
  103. if (!d) return ''
  104. return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
  105. },
  106. goResultDetail: function() {
  107. uni.navigateTo({
  108. url: '/pages/wisdom/assessment-detail?memberId=' + this.memberId
  109. })
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped>
  115. .wisdom-section {}
  116. .section-card {
  117. background: #fff;
  118. border-radius: 24rpx;
  119. padding: 24rpx;
  120. margin-bottom: 20rpx;
  121. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  122. }
  123. .section-header {
  124. margin-bottom: 16rpx;
  125. }
  126. .section-title {
  127. font-size: 30rpx;
  128. font-weight: bold;
  129. color: #333;
  130. }
  131. .result-overview {
  132. display: flex;
  133. flex-direction: column;
  134. align-items: center;
  135. padding: 20rpx 0;
  136. }
  137. .result-score {
  138. font-size: 72rpx;
  139. font-weight: bold;
  140. color: #6366F1;
  141. }
  142. .result-dimension {
  143. font-size: 28rpx;
  144. color: #555;
  145. margin-top: 8rpx;
  146. }
  147. .result-date {
  148. font-size: 24rpx;
  149. color: #999;
  150. padding-top: 12rpx;
  151. border-top: 1rpx solid #f0f0f0;
  152. margin-top: 8rpx;
  153. }
  154. .history-item {
  155. display: flex;
  156. flex-direction: row;
  157. justify-content: space-between;
  158. padding: 14rpx 0;
  159. border-bottom: 1rpx solid #f5f5f5;
  160. }
  161. .history-title {
  162. font-size: 26rpx;
  163. color: #333;
  164. flex: 1;
  165. }
  166. .history-score {
  167. font-size: 26rpx;
  168. color: #6366F1;
  169. width: 80rpx;
  170. text-align: center;
  171. }
  172. .history-date {
  173. font-size: 22rpx;
  174. color: #999;
  175. width: 140rpx;
  176. text-align: right;
  177. }
  178. .empty-state {
  179. padding: 30rpx 0;
  180. text-align: center;
  181. }
  182. .empty-text {
  183. font-size: 28rpx;
  184. color: #999;
  185. }
  186. .empty-sub {
  187. font-size: 24rpx;
  188. color: #ccc;
  189. margin-top: 8rpx;
  190. }
  191. .loading {
  192. text-align: center;
  193. padding: 40rpx;
  194. color: #999;
  195. }
  196. </style>