index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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="filter-tabs">
  28. <view class="filter-tab" :class="activeFilter === 'all' ? 'tab-active' : ''" @click="setFilter('all')">
  29. <text class="tab-text" :class="activeFilter === 'all' ? 'tab-active-text' : ''">全部</text>
  30. </view>
  31. <view class="filter-tab" :class="activeFilter === 'manual' ? 'tab-active' : ''" @click="setFilter('manual')">
  32. <text class="tab-text" :class="activeFilter === 'manual' ? 'tab-active-text' : ''">手动</text>
  33. </view>
  34. <view class="filter-tab" :class="activeFilter === 'assessment' ? 'tab-active' : ''" @click="setFilter('assessment')">
  35. <text class="tab-text" :class="activeFilter === 'assessment' ? 'tab-active-text' : ''">测评</text>
  36. </view>
  37. <view class="filter-tab" :class="activeFilter === 'upload' ? 'tab-active' : ''" @click="setFilter('upload')">
  38. <text class="tab-text" :class="activeFilter === 'upload' ? 'tab-active-text' : ''">上传</text>
  39. </view>
  40. <view class="filter-tab" :class="activeFilter === 'supplement' ? 'tab-active' : ''" @click="setFilter('supplement')">
  41. <text class="tab-text" :class="activeFilter === 'supplement' ? 'tab-active-text' : ''">补充</text>
  42. </view>
  43. </view>
  44. <view class="record-card" v-for="record in filteredRecords" :key="record.id" @click="viewDetail(record)">
  45. <view class="record-header">
  46. <text class="record-title">{{ record.recordTitle || '成长档案' }}</text>
  47. <view class="record-badges">
  48. <text class="record-source-tag" v-if="record.sourceType">{{ sourceTypeLabel(record.sourceType) }}</text>
  49. <text class="record-tag" :class="record.status === 'completed' ? 'tag-completed' : 'tag-pending'">
  50. {{ record.status === 'completed' ? '已完成' : '待同步' }}
  51. </text>
  52. </view>
  53. </view>
  54. <view class="record-scores" v-if="record.overallScore || record.reportDate">
  55. <text class="score-item" v-if="record.overallScore">得分: {{ record.overallScore }}</text>
  56. <text class="score-item" v-if="record.reportDate">{{ record.reportDate }}</text>
  57. <text class="score-item" v-if="!record.reportDate && record.createdAt">{{ formatDate(record.createdAt) }}</text>
  58. </view>
  59. </view>
  60. <view class="empty-state" v-if="filteredRecords.length === 0 && records.length > 0">
  61. <text class="empty-text">该类型暂无记录</text>
  62. </view>
  63. <view class="empty-state" v-if="records.length === 0">
  64. <text class="empty-text">暂无成长档案记录</text>
  65. </view>
  66. </view>
  67. <view class="footer-btn" v-if="selectedChild">
  68. <button class="btn-create" @click="createRecord">创建成长档案</button>
  69. </view>
  70. <view class="footer-btn" v-if="!selectedChild && children.length > 0">
  71. <button class="btn-invite-guide" open-type="share" @click="prepareGuideInvite">邀请成长规划师</button>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import { getChildren, getChildRecords } from '../../utils/api.js'
  77. export default {
  78. data() {
  79. return {
  80. loading: false,
  81. children: [],
  82. selectedChild: null,
  83. selectedChildName: '',
  84. records: [],
  85. childId: '',
  86. activeFilter: 'all',
  87. shareData: null
  88. }
  89. },
  90. computed: {
  91. filteredRecords: function() {
  92. if (this.activeFilter === 'all') return this.records
  93. var filter = this.activeFilter
  94. return this.records.filter(function(r) { return r.sourceType === filter })
  95. }
  96. },
  97. onShareAppMessage() {
  98. if (this.shareData) {
  99. return {
  100. title: this.shareData.title,
  101. path: this.shareData.path,
  102. imageUrl: '/static/invite-card.png'
  103. }
  104. }
  105. },
  106. onLoad(options) {
  107. this.childId = options.childId || ''
  108. this.loadChildren()
  109. },
  110. methods: {
  111. sourceTypeLabel(type) {
  112. var map = { 'manual': '手动', 'assessment': '测评', 'upload': '上传', 'supplement': '补充' }
  113. return map[type] || type
  114. },
  115. setFilter(type) {
  116. this.activeFilter = type
  117. },
  118. async loadChildren() {
  119. this.loading = true
  120. try {
  121. var res = await getChildren()
  122. if (res.code === 200) {
  123. this.children = res.data || []
  124. if (this.childId && this.children.length > 0) {
  125. var matched = this.children.find(function(c) { return String(c.id) === String(this.childId) }.bind(this))
  126. if (matched) {
  127. this.viewChildRecords(matched)
  128. }
  129. }
  130. }
  131. } catch (e) {
  132. console.error('加载孩子列表失败', e)
  133. } finally {
  134. this.loading = false
  135. }
  136. },
  137. async viewChildRecords(child) {
  138. this.selectedChild = child
  139. this.selectedChildName = child.nickname || child.name
  140. this.loading = true
  141. try {
  142. var res = await getChildRecords(child.id)
  143. if (res.code === 200) {
  144. this.records = res.data || []
  145. }
  146. } catch (e) {
  147. console.error('加载成长档案失败', e)
  148. } finally {
  149. this.loading = false
  150. }
  151. },
  152. viewDetail(record) {
  153. uni.navigateTo({
  154. url: '/pages/growth/detail?recordId=' + record.id
  155. })
  156. },
  157. createRecord() {
  158. uni.navigateTo({
  159. url: '/pages/growth/create?childId=' + this.selectedChild.id + '&childName=' + encodeURIComponent(this.selectedChildName)
  160. })
  161. },
  162. formatDate(date) {
  163. if (!date) return ''
  164. return date.substring(0, 10)
  165. },
  166. async prepareGuideInvite() {
  167. try {
  168. var familyId = uni.getStorageSync('familyId')
  169. if (!familyId) {
  170. uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
  171. return
  172. }
  173. var userInfo = uni.getStorageSync('userInfo')
  174. var generateInviteCard = require('../../utils/api.js').generateInviteCard
  175. var res = await generateInviteCard('guide', familyId)
  176. var code = res.data.code
  177. this.shareData = {
  178. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为成长规划师',
  179. path: '/pages/login/login?invite_code=' + code
  180. }
  181. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  182. } catch (e) {
  183. uni.showToast({ title: e.message || '生成邀请失败', icon: 'none' })
  184. }
  185. }
  186. }
  187. }
  188. </script>
  189. <style scoped>
  190. .container {
  191. padding: 30rpx;
  192. background: #F8F8F8;
  193. min-height: 100vh;
  194. }
  195. .header {
  196. text-align: center;
  197. padding: 40rpx 0;
  198. }
  199. .title {
  200. font-size: 40rpx;
  201. font-weight: bold;
  202. color: #333;
  203. display: block;
  204. margin-bottom: 10rpx;
  205. }
  206. .subtitle {
  207. font-size: 26rpx;
  208. color: #999;
  209. }
  210. .child-card {
  211. display: flex;
  212. align-items: center;
  213. background: #fff;
  214. border-radius: 20rpx;
  215. padding: 30rpx;
  216. margin-bottom: 20rpx;
  217. }
  218. .child-info {
  219. flex: 1;
  220. }
  221. .child-name {
  222. font-size: 32rpx;
  223. font-weight: bold;
  224. color: #333;
  225. display: block;
  226. }
  227. .child-age {
  228. font-size: 24rpx;
  229. color: #999;
  230. margin-top: 6rpx;
  231. display: block;
  232. }
  233. .arrow {
  234. width: 40rpx;
  235. }
  236. .arrow-icon {
  237. font-size: 40rpx;
  238. color: #ccc;
  239. }
  240. .records-section {
  241. margin-top: 20rpx;
  242. }
  243. .section-header {
  244. margin-bottom: 20rpx;
  245. }
  246. .section-title {
  247. font-size: 30rpx;
  248. font-weight: bold;
  249. color: #333;
  250. }
  251. .filter-tabs {
  252. display: flex;
  253. gap: 16rpx;
  254. margin-bottom: 20rpx;
  255. }
  256. .filter-tab {
  257. flex: 1;
  258. text-align: center;
  259. padding: 12rpx 0;
  260. border-radius: 20rpx;
  261. background: #fff;
  262. border: 1rpx solid #E0E0E0;
  263. }
  264. .tab-active {
  265. background: #667eea;
  266. border-color: #667eea;
  267. }
  268. .tab-text {
  269. font-size: 24rpx;
  270. color: #666;
  271. }
  272. .tab-active-text {
  273. color: #fff;
  274. }
  275. .record-card {
  276. background: #fff;
  277. border-radius: 16rpx;
  278. padding: 24rpx;
  279. margin-bottom: 16rpx;
  280. }
  281. .record-header {
  282. display: flex;
  283. justify-content: space-between;
  284. align-items: center;
  285. margin-bottom: 12rpx;
  286. }
  287. .record-title {
  288. font-size: 28rpx;
  289. color: #333;
  290. font-weight: bold;
  291. flex: 1;
  292. }
  293. .record-badges {
  294. display: flex;
  295. gap: 8rpx;
  296. flex-shrink: 0;
  297. }
  298. .record-source-tag {
  299. font-size: 20rpx;
  300. padding: 4rpx 10rpx;
  301. border-radius: 8rpx;
  302. background: #f0f0ff;
  303. color: #667eea;
  304. }
  305. .record-tag {
  306. font-size: 22rpx;
  307. padding: 4rpx 12rpx;
  308. border-radius: 20rpx;
  309. }
  310. .tag-completed {
  311. background: #e8f5e9;
  312. color: #4caf50;
  313. }
  314. .tag-pending {
  315. background: #fff3e0;
  316. color: #ff9800;
  317. }
  318. .record-scores {
  319. display: flex;
  320. gap: 20rpx;
  321. }
  322. .score-item {
  323. font-size: 24rpx;
  324. color: #666;
  325. }
  326. .empty-state {
  327. text-align: center;
  328. padding: 60rpx 0;
  329. }
  330. .empty-icon {
  331. font-size: 80rpx;
  332. display: block;
  333. margin-bottom: 20rpx;
  334. }
  335. .empty-text {
  336. font-size: 28rpx;
  337. color: #999;
  338. display: block;
  339. }
  340. .empty-hint {
  341. font-size: 24rpx;
  342. color: #ccc;
  343. margin-top: 10rpx;
  344. display: block;
  345. }
  346. .footer-btn {
  347. padding: 30rpx 0;
  348. }
  349. .btn-create {
  350. width: 100%;
  351. height: 88rpx;
  352. line-height: 88rpx;
  353. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  354. color: #fff;
  355. border-radius: 44rpx;
  356. font-size: 32rpx;
  357. font-weight: bold;
  358. text-align: center;
  359. }
  360. .btn-invite-guide {
  361. width: 100%;
  362. height: 88rpx;
  363. line-height: 88rpx;
  364. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  365. color: #fff;
  366. border-radius: 44rpx;
  367. font-size: 32rpx;
  368. font-weight: bold;
  369. text-align: center;
  370. }
  371. </style>