index.vue 10 KB

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