index.vue 10 KB

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