self-check-entry.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view class="sce-page">
  3. <view v-if="loading" class="sce-loading">
  4. <text class="sce-loading-text">加载中...</text>
  5. </view>
  6. <template v-else>
  7. <!-- 总分横幅 -->
  8. <view class="sce-hero" :style="{ background: heroGradient }">
  9. <view class="sce-hero-inner">
  10. <text class="sce-hero-label">最近自检总分</text>
  11. <view class="sce-hero-score-row">
  12. <text class="sce-hero-score">{{ lastResult && lastResult.totalScore || 0 }}</text>
  13. <text class="sce-hero-total">/45</text>
  14. </view>
  15. <text class="sce-hero-date" v-if="lastResult && lastResult.createdAt">
  16. {{ formatCreatedDate(lastResult.createdAt) }}
  17. </text>
  18. </view>
  19. </view>
  20. <!-- 维度分数条 -->
  21. <view class="sce-card" v-if="lastResult && lastResult.dimensions && lastResult.dimensions.length > 0">
  22. <view class="sce-card-title">
  23. <text class="sce-card-title-text">五维得分</text>
  24. </view>
  25. <view class="sce-dim-list">
  26. <view class="sce-dim-item" v-for="dim in lastResult.dimensions" :key="dim.dimension">
  27. <view class="sce-dim-head">
  28. <view class="sce-dim-label">
  29. <view class="sce-dim-dot" :style="{ background: dim.color }"></view>
  30. <text class="sce-dim-name">{{ dim.name }}</text>
  31. </view>
  32. <view class="sce-dim-score-wrap">
  33. <text class="sce-dim-score" :style="{ color: dim.color }">{{ dim.score }}</text>
  34. <text class="sce-dim-max">/9</text>
  35. </view>
  36. </view>
  37. <view class="sce-dim-bar">
  38. <view class="sce-dim-bar-fill" :style="{ width: (dim.score / 9 * 100) + '%', background: dim.color }"></view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 状态提示 -->
  44. <view class="sce-status" v-if="!canCheck && lastResult">
  45. <text class="sce-status-text">距下次自检还有 {{ daysLeft }} 天</text>
  46. </view>
  47. <view class="sce-status" v-else-if="canCheck && lastResult">
  48. <text class="sce-status-text">已满 15 天,可再次自检</text>
  49. </view>
  50. <!-- 按钮区域 -->
  51. <view class="sce-footer">
  52. <button v-if="canCheck && lastResult" class="sce-btn sce-btn-primary" @click="retake">
  53. 再次自检
  54. </button>
  55. <button v-if="canCheck && lastResult" class="sce-btn sce-btn-outline" @click="ignore">
  56. 忽略本次
  57. </button>
  58. <button v-if="!lastResult" class="sce-btn sce-btn-primary" @click="retake">
  59. 开始自检
  60. </button>
  61. <button v-if="!canCheck && lastResult" class="sce-btn sce-btn-disabled" disabled>
  62. {{ daysLeft }} 天后可再次自检
  63. </button>
  64. </view>
  65. </template>
  66. </view>
  67. </template>
  68. <script>
  69. import { getSelfCheckStatus, ignoreSelfCheck } from '@/utils/api'
  70. import { parseDate } from '@/utils/format.js'
  71. export default {
  72. data() {
  73. return {
  74. loading: true,
  75. lastResult: null,
  76. canCheck: false,
  77. daysLeft: 0
  78. }
  79. },
  80. computed: {
  81. heroGradient: function() {
  82. if (!this.lastResult || !this.lastResult.dimensions || this.lastResult.dimensions.length === 0) {
  83. return 'linear-gradient(135deg, #F97316, #FF8C42)'
  84. }
  85. var lowest = this.lastResult.dimensions.reduce(function(min, d) {
  86. return d.score < min.score ? d : min
  87. }, this.lastResult.dimensions[0])
  88. return 'linear-gradient(135deg, ' + lowest.color + ', ' + (lowest.color + 'bb') + ')'
  89. }
  90. },
  91. onLoad: function() {
  92. this.loadStatus()
  93. },
  94. methods: {
  95. loadStatus: function() {
  96. var self = this
  97. getSelfCheckStatus().then(function(res) {
  98. self.loading = false
  99. if (res.code === 200 && res.data) {
  100. self.lastResult = res.data.lastResult || null
  101. self.canCheck = res.data.canCheck
  102. self.daysLeft = res.data.daysLeft || 0
  103. } else {
  104. uni.showToast({ title: (res && res.message) || '加载失败', icon: 'none' })
  105. }
  106. }).catch(function() {
  107. self.loading = false
  108. uni.showToast({ title: '网络异常', icon: 'none' })
  109. })
  110. },
  111. retake: function() {
  112. uni.navigateTo({ url: '/pages/family/self-check?retake=1' })
  113. },
  114. ignore: function() {
  115. var self = this
  116. ignoreSelfCheck({ checkId: this.lastResult && this.lastResult.id }).then(function(res) {
  117. if (res.code === 200) {
  118. uni.showToast({ title: '已忽略,15 天后再次提醒', icon: 'none' })
  119. setTimeout(function() {
  120. uni.navigateBack()
  121. }, 800)
  122. } else {
  123. uni.showToast({ title: (res && res.message) || '操作失败', icon: 'none' })
  124. }
  125. }).catch(function() {
  126. uni.showToast({ title: '操作失败', icon: 'none' })
  127. })
  128. },
  129. formatCreatedDate: function(dateStr) {
  130. if (!dateStr) return ''
  131. var d = parseDate(dateStr)
  132. if (!d) return ''
  133. var pad = function(n) { return n < 10 ? '0' + n : '' + n }
  134. return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
  135. }
  136. }
  137. }
  138. </script>
  139. <style scoped>
  140. .sce-page {
  141. min-height: 100vh;
  142. background: #F5FAFE;
  143. padding: 24rpx 30rpx 120rpx;
  144. box-sizing: border-box;
  145. }
  146. .sce-loading {
  147. display: flex;
  148. justify-content: center;
  149. align-items: center;
  150. height: 50vh;
  151. }
  152. .sce-loading-text {
  153. font-size: 28rpx;
  154. color: #999;
  155. }
  156. .sce-hero {
  157. background: linear-gradient(135deg, #F97316, #FF8C42);
  158. border-radius: 24rpx;
  159. padding: 40rpx 30rpx;
  160. margin-bottom: 24rpx;
  161. box-shadow: 0 6rpx 20rpx rgba(249, 114, 22, 0.25);
  162. }
  163. .sce-hero-inner {
  164. display: flex;
  165. flex-direction: column;
  166. align-items: center;
  167. }
  168. .sce-hero-label {
  169. font-size: 26rpx;
  170. color: rgba(255, 255, 255, 0.9);
  171. }
  172. .sce-hero-score-row {
  173. display: flex;
  174. align-items: baseline;
  175. margin-top: 10rpx;
  176. }
  177. .sce-hero-score {
  178. font-size: 88rpx;
  179. font-weight: 700;
  180. color: #fff;
  181. }
  182. .sce-hero-total {
  183. font-size: 30rpx;
  184. color: rgba(255, 255, 255, 0.7);
  185. margin-left: 6rpx;
  186. }
  187. .sce-hero-date {
  188. display: block;
  189. text-align: center;
  190. font-size: 22rpx;
  191. color: rgba(255, 255, 255, 0.8);
  192. margin-top: 16rpx;
  193. }
  194. .sce-card {
  195. background: #fff;
  196. border-radius: 24rpx;
  197. padding: 30rpx 26rpx;
  198. margin-bottom: 24rpx;
  199. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  200. }
  201. .sce-card-title {
  202. margin-bottom: 24rpx;
  203. }
  204. .sce-card-title-text {
  205. font-size: 32rpx;
  206. font-weight: 600;
  207. color: #333;
  208. }
  209. .sce-dim-list {
  210. display: flex;
  211. flex-direction: column;
  212. }
  213. .sce-dim-item {
  214. margin-bottom: 24rpx;
  215. }
  216. .sce-dim-item:last-child {
  217. margin-bottom: 0;
  218. }
  219. .sce-dim-head {
  220. display: flex;
  221. align-items: center;
  222. justify-content: space-between;
  223. }
  224. .sce-dim-label {
  225. display: flex;
  226. align-items: center;
  227. }
  228. .sce-dim-dot {
  229. width: 28rpx;
  230. height: 28rpx;
  231. border-radius: 50%;
  232. margin-right: 12rpx;
  233. }
  234. .sce-dim-name {
  235. font-size: 30rpx;
  236. font-weight: 600;
  237. color: #333;
  238. }
  239. .sce-dim-score-wrap {
  240. display: flex;
  241. align-items: baseline;
  242. }
  243. .sce-dim-score {
  244. font-size: 40rpx;
  245. font-weight: 700;
  246. }
  247. .sce-dim-max {
  248. font-size: 22rpx;
  249. color: #BBB;
  250. }
  251. .sce-dim-bar {
  252. height: 12rpx;
  253. background: #F0F0F0;
  254. border-radius: 6rpx;
  255. margin-top: 14rpx;
  256. overflow: hidden;
  257. }
  258. .sce-dim-bar-fill {
  259. height: 100%;
  260. border-radius: 6rpx;
  261. transition: width 0.5s ease;
  262. }
  263. .sce-status {
  264. background: #FFF7ED;
  265. border-radius: 16rpx;
  266. padding: 24rpx 20rpx;
  267. margin-bottom: 24rpx;
  268. text-align: center;
  269. }
  270. .sce-status-text {
  271. font-size: 26rpx;
  272. color: #E65100;
  273. }
  274. .sce-footer {
  275. display: flex;
  276. flex-direction: column;
  277. gap: 16rpx;
  278. margin-top: 20rpx;
  279. }
  280. .sce-btn {
  281. height: 88rpx;
  282. line-height: 88rpx;
  283. font-size: 30rpx;
  284. border-radius: 44rpx;
  285. text-align: center;
  286. border: none;
  287. }
  288. .sce-btn-primary {
  289. background: linear-gradient(135deg, #F97316, #FF8C42);
  290. color: #fff;
  291. font-weight: 600;
  292. }
  293. .sce-btn-outline {
  294. background: #fff;
  295. color: #F97316;
  296. border: 2rpx solid #F97316;
  297. }
  298. .sce-btn-disabled {
  299. background: #E5E7EB;
  300. color: #999;
  301. font-weight: 400;
  302. }
  303. </style>