daily-checkin.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="page">
  3. <view class="nav-bar">
  4. <view class="nav-back" @tap="goBack">
  5. <text class="back-text">‹ 返回</text>
  6. </view>
  7. <text class="nav-title">健康打卡</text>
  8. </view>
  9. <scroll-view class="content" scroll-y>
  10. <view class="card">
  11. <view class="card-accent"></view>
  12. <view class="card-body">
  13. <text class="card-title">今日综合打卡</text>
  14. <text class="card-subtitle">为你的一天各项健康指标打分吧</text>
  15. <view class="score-group">
  16. <text class="score-label">饮食评分</text>
  17. <view class="score-row">
  18. <text class="score-min">差</text>
  19. <slider min="1" max="10" :value="form.dietScore" @change="function(e){form.dietScore=e.detail.value}" block-size="20" activeColor="#FF8C42" />
  20. <text class="score-val">{{ form.dietScore }}</text>
  21. </view>
  22. </view>
  23. <view class="score-group">
  24. <text class="score-label">运动评分</text>
  25. <view class="score-row">
  26. <text class="score-min">差</text>
  27. <slider min="1" max="10" :value="form.exerciseScore" @change="function(e){form.exerciseScore=e.detail.value}" block-size="20" activeColor="#FF8C42" />
  28. <text class="score-val">{{ form.exerciseScore }}</text>
  29. </view>
  30. </view>
  31. <view class="score-group">
  32. <text class="score-label">睡眠评分</text>
  33. <view class="score-row">
  34. <text class="score-min">差</text>
  35. <slider min="1" max="10" :value="form.sleepScore" @change="function(e){form.sleepScore=e.detail.value}" block-size="20" activeColor="#FF8C42" />
  36. <text class="score-val">{{ form.sleepScore }}</text>
  37. </view>
  38. </view>
  39. <view class="score-group">
  40. <text class="score-label">饮水评分</text>
  41. <view class="score-row">
  42. <text class="score-min">差</text>
  43. <slider min="1" max="10" :value="form.waterScore" @change="function(e){form.waterScore=e.detail.value}" block-size="20" activeColor="#FF8C42" />
  44. <text class="score-val">{{ form.waterScore }}</text>
  45. </view>
  46. </view>
  47. <view class="score-group">
  48. <text class="score-label">心情评分</text>
  49. <view class="score-row">
  50. <text class="score-min">差</text>
  51. <slider min="1" max="10" :value="form.moodScore" @change="function(e){form.moodScore=e.detail.value}" block-size="20" activeColor="#FF8C42" />
  52. <text class="score-val">{{ form.moodScore }}</text>
  53. </view>
  54. </view>
  55. <view class="form-group">
  56. <text class="form-label">备注(选填)</text>
  57. <input class="form-input" v-model="form.remark" placeholder="今天的感受..." />
  58. </view>
  59. <view class="submit-btn" @tap="doCheckin">
  60. <text>{{ submitting ? '提交中...' : '提交打卡' }}</text>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 历史记录 -->
  65. <view class="card">
  66. <view class="card-accent"></view>
  67. <view class="card-body">
  68. <text class="card-title">打卡记录</text>
  69. <view class="history-list" v-if="history.length > 0">
  70. <view class="history-item" v-for="item in history" :key="item.id">
  71. <view class="history-left">
  72. <text class="history-type">{{ formatDate(item.checkinDate || item.createdAt) }}</text>
  73. <text class="history-duration">
  74. 饮食{{ item.dietScore || '-' }} 运动{{ item.exerciseScore || '-' }}
  75. 睡眠{{ item.sleepScore || '-' }} 饮水{{ item.waterIntake || '-' }}
  76. 心情{{ item.moodScore || '-' }}
  77. </text>
  78. </view>
  79. <view class="history-right">
  80. <text class="history-date">{{ item.remark || '' }}</text>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="empty-state" v-else>
  85. <text>还没有打卡记录</text>
  86. </view>
  87. </view>
  88. </view>
  89. </scroll-view>
  90. </view>
  91. </template>
  92. <script>
  93. import config from '@/config.js'
  94. export default {
  95. data() {
  96. return {
  97. memberId: null,
  98. submitting: false,
  99. history: [],
  100. form: {
  101. dietScore: 7,
  102. exerciseScore: 7,
  103. sleepScore: 7,
  104. waterScore: 7,
  105. moodScore: 7,
  106. remark: ''
  107. }
  108. }
  109. },
  110. onLoad: function() {
  111. this.memberId = uni.getStorageSync('currentChildId') || null
  112. this.loadHistory()
  113. },
  114. methods: {
  115. goBack: function() {
  116. uni.navigateBack()
  117. },
  118. formatDate: function(dateStr) {
  119. if (!dateStr) return ''
  120. var d = new Date(dateStr)
  121. var m = (d.getMonth() + 1).toString().padStart(2, '0')
  122. var day = d.getDate().toString().padStart(2, '0')
  123. return m + '-' + day
  124. },
  125. loadHistory: function() {
  126. var self = this
  127. var token = uni.getStorageSync('token')
  128. if (!token || !self.memberId) return
  129. uni.request({
  130. url: config.API_BASE_URL + '/api/daily/checkin/list',
  131. method: 'POST',
  132. data: { memberId: self.memberId },
  133. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  134. success: function(res) {
  135. if (res.data && res.data.code === 200 && res.data.data) {
  136. self.history = res.data.data.slice(0, 10)
  137. }
  138. }
  139. })
  140. },
  141. doCheckin: function() {
  142. var self = this
  143. if (!self.memberId) {
  144. uni.showToast({ title: '孩子ID无效', icon: 'none' })
  145. return
  146. }
  147. self.submitting = true
  148. var token = uni.getStorageSync('token')
  149. uni.request({
  150. url: config.API_BASE_URL + '/api/daily/checkin/create',
  151. method: 'POST',
  152. data: {
  153. memberId: self.memberId,
  154. dietScore: self.form.dietScore,
  155. exerciseScore: self.form.exerciseScore,
  156. sleepScore: self.form.sleepScore,
  157. waterIntake: self.form.waterScore,
  158. moodScore: self.form.moodScore,
  159. remark: self.form.remark || ''
  160. },
  161. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  162. success: function(res) {
  163. self.submitting = false
  164. if (res.data && res.data.code === 200) {
  165. uni.showToast({ title: '打卡成功', icon: 'success' })
  166. self.form.remark = ''
  167. self.loadHistory()
  168. } else {
  169. var msg = (res.data && res.data.message) || '打卡失败'
  170. uni.showToast({ title: msg, icon: 'none' })
  171. }
  172. },
  173. fail: function() {
  174. self.submitting = false
  175. uni.showToast({ title: '网络错误', icon: 'none' })
  176. }
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style scoped>
  183. .page {
  184. min-height: 100vh;
  185. background-color: #F5F7FA;
  186. display: flex;
  187. flex-direction: column;
  188. }
  189. .nav-bar {
  190. display: flex;
  191. align-items: center;
  192. justify-content: center;
  193. height: 88rpx;
  194. padding-top: var(--status-bar-height, 0);
  195. background-color: #FFFFFF;
  196. position: relative;
  197. border-bottom: 1rpx solid #f0f0f0;
  198. }
  199. .nav-back { position: absolute; left: 30rpx; top: 50%; transform: translateY(-50%); padding: 10rpx; }
  200. .back-text { font-size: 28rpx; color: #333; }
  201. .nav-title { font-size: 32rpx; font-weight: 600; color: #333; }
  202. .content { flex: 1; padding: 30rpx; }
  203. .card {
  204. display: flex; background-color: #FFFFFF; border-radius: 20rpx; margin-bottom: 30rpx;
  205. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06); overflow: hidden;
  206. }
  207. .card-accent { width: 8rpx; background-color: #FF8C42; flex-shrink: 0; }
  208. .card-body { flex: 1; padding: 30rpx; }
  209. .card-title { font-size: 30rpx; font-weight: 600; color: #333; margin-bottom: 8rpx; display: block; }
  210. .card-subtitle { font-size: 24rpx; color: #999; margin-bottom: 30rpx; display: block; }
  211. .score-group { margin-bottom: 20rpx; }
  212. .score-label { font-size: 26rpx; color: #333; font-weight: 500; margin-bottom: 8rpx; display: block; }
  213. .score-row { display: flex; align-items: center; gap: 16rpx; }
  214. .score-min { font-size: 22rpx; color: #999; flex-shrink: 0; }
  215. .score-val { font-size: 24rpx; color: #FF8C42; font-weight: 500; width: 40rpx; text-align: center; }
  216. .form-group { margin-bottom: 24rpx; }
  217. .form-label { font-size: 26rpx; color: #333; font-weight: 500; margin-bottom: 12rpx; display: block; }
  218. .form-input {
  219. border: 1rpx solid #ddd; border-radius: 12rpx; padding: 16rpx 20rpx;
  220. font-size: 26rpx; background-color: #FAFAFA; width: auto;
  221. }
  222. .submit-btn {
  223. background-color: #FF8C42; color: #FFFFFF; text-align: center; padding: 22rpx 0;
  224. border-radius: 16rpx; font-size: 28rpx; font-weight: 500; margin-top: 10rpx;
  225. }
  226. .history-list { display: flex; flex-direction: column; gap: 16rpx; }
  227. .history-item {
  228. display: flex; justify-content: space-between; align-items: center; padding: 16rpx 0;
  229. border-bottom: 1rpx solid #f0f0f0;
  230. }
  231. .history-left { display: flex; flex-direction: column; gap: 4rpx; }
  232. .history-type { font-size: 26rpx; font-weight: 500; color: #333; }
  233. .history-duration { font-size: 22rpx; color: #999; }
  234. .history-right { text-align: right; max-width: 40%; }
  235. .history-date { font-size: 22rpx; color: #999; }
  236. .empty-state { text-align: center; padding: 40rpx 0; font-size: 26rpx; color: #999; }
  237. </style>