index.vue 10 KB

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