action-section.vue 6.2 KB

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