index.vue 10 KB

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