index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <text class="title">成长档案</text>
  5. <text class="subtitle">记录孩子的每一次成长</text>
  6. </view>
  7. <view class="children-list" v-if="!childId">
  8. <view class="child-card" v-for="child in children" :key="child.id" @click="viewChildRecords(child)">
  9. <view class="child-info">
  10. <text class="child-name">{{ child.nickname || child.name }}</text>
  11. <text class="child-age" v-if="child.age">年龄:{{ child.age }}岁</text>
  12. </view>
  13. <view class="arrow">
  14. <text class="arrow-icon">›</text>
  15. </view>
  16. </view>
  17. <view class="empty-state" v-if="children.length === 0 && !loading">
  18. <text class="empty-icon">📋</text>
  19. <text class="empty-text">还没有添加孩子</text>
  20. <text class="empty-hint">请先在"我的"页面添加孩子</text>
  21. </view>
  22. </view>
  23. <view class="records-section" v-if="selectedChild">
  24. <view class="section-header">
  25. <text class="section-title">{{ selectedChildName }} 的成长档案</text>
  26. </view>
  27. <view class="record-card" v-for="record in records" :key="record.id" @click="viewDetail(record)">
  28. <view class="record-header">
  29. <text class="record-title">{{ record.recordTitle || '成长档案' }}</text>
  30. <text class="record-tag" :class="record.status === 'completed' ? 'tag-completed' : 'tag-pending'">
  31. {{ record.status === 'completed' ? '已完成' : '待同步' }}
  32. </text>
  33. </view>
  34. <view class="record-scores" v-if="record.danLevel || record.overallScore">
  35. <text class="score-item" v-if="record.danLevel">DAN: {{ record.danLevel }}</text>
  36. <text class="score-item" v-if="record.overallScore">得分: {{ record.overallScore }}</text>
  37. <text class="score-item" v-if="record.createdAt">{{ formatDate(record.createdAt) }}</text>
  38. </view>
  39. </view>
  40. <view class="empty-state" v-if="records.length === 0">
  41. <text class="empty-text">暂无成长档案记录</text>
  42. </view>
  43. </view>
  44. <view class="footer-btn" v-if="selectedChild">
  45. <button class="btn-create" @click="createRecord">创建成长档案</button>
  46. </view>
  47. <view class="footer-btn" v-if="!selectedChild && children.length > 0">
  48. <button class="btn-invite-guide" open-type="share" @click="prepareGuideInvite">邀请成长规划师</button>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { getChildren, getChildRecords } from '../../utils/api.js'
  54. export default {
  55. data() {
  56. return {
  57. loading: false,
  58. children: [],
  59. selectedChild: null,
  60. selectedChildName: '',
  61. records: [],
  62. childId: '',
  63. shareData: null
  64. }
  65. },
  66. onShareAppMessage() {
  67. if (this.shareData) {
  68. return {
  69. title: this.shareData.title,
  70. path: this.shareData.path,
  71. imageUrl: '/static/invite-card.png'
  72. }
  73. }
  74. },
  75. onLoad(options) {
  76. this.childId = options.childId || ''
  77. this.loadChildren()
  78. },
  79. methods: {
  80. async loadChildren() {
  81. this.loading = true
  82. try {
  83. const res = await getChildren()
  84. if (res.code === 200) {
  85. this.children = res.data || []
  86. // 如果指定了 childId,自动选中该孩子并加载档案
  87. if (this.childId && this.children.length > 0) {
  88. const matched = this.children.find(c => String(c.id) === String(this.childId))
  89. if (matched) {
  90. this.viewChildRecords(matched)
  91. }
  92. }
  93. }
  94. } catch (e) {
  95. console.error('加载孩子列表失败', e)
  96. } finally {
  97. this.loading = false
  98. }
  99. },
  100. async viewChildRecords(child) {
  101. this.selectedChild = child
  102. this.selectedChildName = child.nickname || child.name
  103. this.loading = true
  104. try {
  105. const res = await getChildRecords(child.id)
  106. if (res.code === 200) {
  107. this.records = res.data || []
  108. }
  109. } catch (e) {
  110. console.error('加载成长档案失败', e)
  111. } finally {
  112. this.loading = false
  113. }
  114. },
  115. viewDetail(record) {
  116. uni.navigateTo({
  117. url: '/pages/growth/detail?recordId=' + record.id
  118. })
  119. },
  120. createRecord() {
  121. uni.navigateTo({
  122. url: '/pages/growth/create?childId=' + this.selectedChild.id + '&childName=' + encodeURIComponent(this.selectedChildName)
  123. })
  124. },
  125. formatDate(date) {
  126. if (!date) return ''
  127. return date.substring(0, 10)
  128. },
  129. async prepareGuideInvite() {
  130. try {
  131. const familyId = uni.getStorageSync('familyId')
  132. if (!familyId) {
  133. uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
  134. return
  135. }
  136. const userInfo = uni.getStorageSync('userInfo')
  137. const { generateInviteCard } = require('../../utils/api.js')
  138. const res = await generateInviteCard('guide', familyId)
  139. const code = res.data.code
  140. this.shareData = {
  141. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为成长规划师',
  142. path: '/pages/login/login?invite_code=' + code
  143. }
  144. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  145. } catch (e) {
  146. uni.showToast({ title: e.message || '生成邀请失败', icon: 'none' })
  147. }
  148. }
  149. }
  150. }
  151. </script>
  152. <style scoped>
  153. .container {
  154. padding: 30rpx;
  155. background: #F8F8F8;
  156. min-height: 100vh;
  157. }
  158. .header {
  159. text-align: center;
  160. padding: 40rpx 0;
  161. }
  162. .title {
  163. font-size: 40rpx;
  164. font-weight: bold;
  165. color: #333;
  166. display: block;
  167. margin-bottom: 10rpx;
  168. }
  169. .subtitle {
  170. font-size: 26rpx;
  171. color: #999;
  172. }
  173. .child-card {
  174. display: flex;
  175. align-items: center;
  176. background: #fff;
  177. border-radius: 20rpx;
  178. padding: 30rpx;
  179. margin-bottom: 20rpx;
  180. }
  181. .child-info {
  182. flex: 1;
  183. }
  184. .child-name {
  185. font-size: 32rpx;
  186. font-weight: bold;
  187. color: #333;
  188. display: block;
  189. }
  190. .child-age {
  191. font-size: 24rpx;
  192. color: #999;
  193. margin-top: 6rpx;
  194. display: block;
  195. }
  196. .child-meta {
  197. text-align: center;
  198. margin: 0 30rpx;
  199. }
  200. .meta-label {
  201. font-size: 22rpx;
  202. color: #999;
  203. display: block;
  204. }
  205. .meta-value {
  206. font-size: 28rpx;
  207. color: #667eea;
  208. font-weight: bold;
  209. display: block;
  210. }
  211. .arrow {
  212. width: 40rpx;
  213. }
  214. .arrow-icon {
  215. font-size: 40rpx;
  216. color: #ccc;
  217. }
  218. .records-section {
  219. margin-top: 20rpx;
  220. }
  221. .section-header {
  222. margin-bottom: 20rpx;
  223. }
  224. .section-title {
  225. font-size: 30rpx;
  226. font-weight: bold;
  227. color: #333;
  228. }
  229. .record-card {
  230. background: #fff;
  231. border-radius: 16rpx;
  232. padding: 24rpx;
  233. margin-bottom: 16rpx;
  234. }
  235. .record-header {
  236. display: flex;
  237. justify-content: space-between;
  238. align-items: center;
  239. margin-bottom: 12rpx;
  240. }
  241. .record-title {
  242. font-size: 28rpx;
  243. color: #333;
  244. font-weight: bold;
  245. }
  246. .record-tag {
  247. font-size: 22rpx;
  248. padding: 4rpx 12rpx;
  249. border-radius: 20rpx;
  250. }
  251. .tag-completed {
  252. background: #e8f5e9;
  253. color: #4caf50;
  254. }
  255. .tag-pending {
  256. background: #fff3e0;
  257. color: #ff9800;
  258. }
  259. .record-scores {
  260. display: flex;
  261. gap: 20rpx;
  262. }
  263. .score-item {
  264. font-size: 24rpx;
  265. color: #666;
  266. }
  267. .empty-state {
  268. text-align: center;
  269. padding: 60rpx 0;
  270. }
  271. .empty-icon {
  272. font-size: 80rpx;
  273. display: block;
  274. margin-bottom: 20rpx;
  275. }
  276. .empty-text {
  277. font-size: 28rpx;
  278. color: #999;
  279. display: block;
  280. }
  281. .empty-hint {
  282. font-size: 24rpx;
  283. color: #ccc;
  284. margin-top: 10rpx;
  285. display: block;
  286. }
  287. .footer-btn {
  288. padding: 30rpx 0;
  289. }
  290. .btn-create {
  291. width: 100%;
  292. height: 88rpx;
  293. line-height: 88rpx;
  294. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  295. color: #fff;
  296. border-radius: 44rpx;
  297. font-size: 32rpx;
  298. font-weight: bold;
  299. text-align: center;
  300. }
  301. .btn-invite-guide {
  302. width: 100%;
  303. height: 88rpx;
  304. line-height: 88rpx;
  305. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  306. color: #fff;
  307. border-radius: 44rpx;
  308. font-size: 32rpx;
  309. font-weight: bold;
  310. text-align: center;
  311. }
  312. </style>