action-section.vue 6.1 KB

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