action-section.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="action-section">
  3. <!-- 今日任务 -->
  4. <view class="section-card" v-if="todayTasks.length > 0">
  5. <view class="section-header">
  6. <text class="section-title">✅ 今日任务</text>
  7. </view>
  8. <view class="task-item" v-for="task in todayTasks" :key="task.id" @click="goTaskDetail(task)">
  9. <view class="task-status" :class="task.status === 'completed' ? 'task-done' : 'task-pending'"></view>
  10. <text class="task-name">{{ task.title || task.name }}</text>
  11. <text class="task-points">{{ task.points || task.coin || 0 }}分</text>
  12. </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="checkinStats">
  22. <view class="section-header">
  23. <text class="section-title">📊 打卡统计</text>
  24. </view>
  25. <view class="stats-row">
  26. <view class="stat-item">
  27. <text class="stat-value">{{ checkinStats.totalDays || 0 }}</text>
  28. <text class="stat-label">累计天数</text>
  29. </view>
  30. <view class="stat-item">
  31. <text class="stat-value">{{ checkinStats.currentStreak || 0 }}</text>
  32. <text class="stat-label">连续打卡</text>
  33. </view>
  34. <view class="stat-item">
  35. <text class="stat-value">{{ checkinStats.thisMonth || 0 }}</text>
  36. <text class="stat-label">本月次数</text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 近期活动 -->
  41. <view class="section-card" v-if="activityList.length > 0">
  42. <view class="section-header">
  43. <text class="section-title">🎪 近期活动</text>
  44. </view>
  45. <view class="activity-item" v-for="act in activityList" :key="act.id" @click="goActivityDetail(act)">
  46. <text class="activity-name">{{ act.title || act.name }}</text>
  47. <text class="activity-date">{{ formatDate(act.startTime || act.activityDate) }}</text>
  48. </view>
  49. </view>
  50. <!-- 非孩子成员提示 -->
  51. <view class="section-card" v-if="!memberId && !loading">
  52. <view class="empty-state">
  53. <text class="empty-text">该成员暂无行动数据</text>
  54. </view>
  55. </view>
  56. <!-- 加载中 -->
  57. <view class="loading" v-if="loading">加载中...</view>
  58. </view>
  59. </template>
  60. <script>
  61. import { getTodayTasksByCategory, getCheckinStats, getActivityList } from '../../utils/api.js'
  62. export default {
  63. props: {
  64. memberId: {
  65. type: [Number, String],
  66. default: null
  67. },
  68. memberType: {
  69. type: String,
  70. default: ''
  71. },
  72. memberInfo: {
  73. type: Object,
  74. default: null
  75. },
  76. sandboxData: {
  77. type: Object,
  78. default: null
  79. },
  80. energyMap: {
  81. type: Object,
  82. default: null
  83. }
  84. },
  85. data: function() {
  86. return {
  87. loading: true,
  88. todayTasks: [],
  89. checkinStats: null,
  90. activityList: []
  91. }
  92. },
  93. mounted: function() {
  94. if (this.memberId) {
  95. this.loadData()
  96. } else {
  97. this.loading = false
  98. }
  99. },
  100. methods: {
  101. loadData: function() {
  102. var self = this
  103. getTodayTasksByCategory(this.memberId, 'action').then(function(res) {
  104. if (res.code === 200 && res.data) {
  105. self.todayTasks = Array.isArray(res.data) ? res.data : (res.data.records || [])
  106. }
  107. }).catch(function(e) {
  108. console.log('加载今日任务失败', e)
  109. })
  110. getCheckinStats({ memberId: this.memberId }).then(function(res) {
  111. if (res.code === 200 && res.data) {
  112. self.checkinStats = res.data
  113. }
  114. }).catch(function(e) {
  115. console.log('加载打卡统计失败', e)
  116. })
  117. getActivityList({ page: 1, size: 3 }).then(function(res) {
  118. if (res.code === 200 && res.data) {
  119. self.activityList = Array.isArray(res.data) ? res.data : (res.data.records || [])
  120. }
  121. }).catch(function(e) {
  122. console.log('加载活动列表失败', e)
  123. })
  124. this.loading = false
  125. },
  126. formatDate: function(dateStr) {
  127. if (!dateStr) return ''
  128. var d = new Date(dateStr)
  129. return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
  130. },
  131. goTaskDetail: function(task) {
  132. // TODO: task-detail 页面尚未实现,暂不跳转
  133. console.log('task-detail not implemented', task)
  134. },
  135. goActivityDetail: function(act) {
  136. if (!act || !act.id) return
  137. uni.navigateTo({
  138. url: '/pages/activity/activity-detail/activity-detail?id=' + act.id
  139. })
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .action-section {}
  146. .section-card {
  147. background: #fff;
  148. border-radius: 24rpx;
  149. padding: 24rpx;
  150. margin-bottom: 20rpx;
  151. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  152. }
  153. .section-header {
  154. margin-bottom: 16rpx;
  155. }
  156. .section-title {
  157. font-size: 30rpx;
  158. font-weight: bold;
  159. color: #333;
  160. }
  161. .task-item {
  162. display: flex;
  163. flex-direction: row;
  164. align-items: center;
  165. padding: 14rpx 0;
  166. border-bottom: 1rpx solid #f5f5f5;
  167. }
  168. .task-status {
  169. width: 16rpx;
  170. height: 16rpx;
  171. border-radius: 50%;
  172. margin-right: 16rpx;
  173. }
  174. .task-done {
  175. background: #10B981;
  176. }
  177. .task-pending {
  178. background: #F59E0B;
  179. }
  180. .task-name {
  181. flex: 1;
  182. font-size: 28rpx;
  183. color: #333;
  184. }
  185. .task-points {
  186. font-size: 24rpx;
  187. color: #10B981;
  188. }
  189. .stats-row {
  190. display: flex;
  191. flex-direction: row;
  192. justify-content: space-around;
  193. padding: 16rpx 0;
  194. }
  195. .stat-item {
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. }
  200. .stat-value {
  201. font-size: 40rpx;
  202. font-weight: bold;
  203. color: #10B981;
  204. }
  205. .stat-label {
  206. font-size: 24rpx;
  207. color: #999;
  208. margin-top: 4rpx;
  209. }
  210. .activity-item {
  211. display: flex;
  212. flex-direction: row;
  213. justify-content: space-between;
  214. padding: 12rpx 0;
  215. border-bottom: 1rpx solid #f5f5f5;
  216. }
  217. .activity-name {
  218. font-size: 26rpx;
  219. color: #333;
  220. flex: 1;
  221. }
  222. .activity-date {
  223. font-size: 22rpx;
  224. color: #999;
  225. }
  226. .empty-state {
  227. padding: 30rpx 0;
  228. text-align: center;
  229. }
  230. .empty-text {
  231. font-size: 28rpx;
  232. color: #999;
  233. }
  234. .empty-sub {
  235. font-size: 24rpx;
  236. color: #ccc;
  237. margin-top: 8rpx;
  238. }
  239. .loading {
  240. text-align: center;
  241. padding: 40rpx;
  242. color: #999;
  243. }
  244. </style>