profile.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. <template>
  2. <view class="container">
  3. <!-- ===== 未登录状态 ===== -->
  4. <view v-if="!isLoggedIn" class="login-prompt">
  5. <view class="prompt-icon">👤</view>
  6. <text class="prompt-title">登录浠艾福</text>
  7. <text class="prompt-desc">登录后可查看个人资料、积分记录等</text>
  8. <button class="login-btn" @click="goLogin">登录 / 注册</button>
  9. </view>
  10. <!-- ===== 已登录状态 ===== -->
  11. <template v-else>
  12. <!-- 品牌头部 -->
  13. <PageBanner theme="wealth"
  14. tagline="丰盈内心,富足生活,厚德载物"
  15. quote="" />
  16. <!-- 富沛能量值 -->
  17. <view class="wealth-energy-header" v-if="isLoggedIn && wealthEnergy > 0">
  18. <text class="energy-header-icon">💧</text>
  19. <text class="energy-header-value">{{ wealthEnergy }}</text>
  20. <text class="energy-header-label">富沛能量</text>
  21. <text class="energy-header-trend" v-if="energyTrend > 0">↑较上周+{{ energyTrend }}</text>
  22. </view>
  23. <!-- 退出切换按钮(仅家长切换到孩子状态时显示) -->
  24. <view class="exit-switch" v-if="isSwitchedChild" @click="exitSwitch">
  25. <text>🔄 退出切换</text>
  26. </view>
  27. <view class="user-card">
  28. <view class="avatar">👤</view>
  29. <view class="user-info">
  30. <view class="nickname">{{ nickname || '未设置昵称' }}</view>
  31. <view class="role">{{ role === 'parent' ? '家长模式' : (role === 'child' ? '孩子模式' : '成长规划师模式') }}</view>
  32. <view class="system-points" v-if="role === 'parent' && children.length > 0">🏅 系统积分: {{ children[0].systemPoints || 0 }}</view>
  33. <view class="wealth-energy-row" v-if="wealthEnergy > 0">
  34. <text class="wealth-energy-icon">💧</text>
  35. <text class="wealth-energy-value">富沛能量: {{ wealthEnergy }}</text>
  36. <text class="wealth-energy-trend" v-if="energyTrend > 0"> ↑较上周+{{ energyTrend }}</text>
  37. </view>
  38. </view>
  39. <!-- 切换按钮仅在非切换状态下显示 -->
  40. <button class="btn-switch" v-if="!isSwitchedChild" @click="switchMode">切换</button>
  41. </view>
  42. <!-- 行动数据 -->
  43. <view class="section">
  44. <view class="section-header">
  45. <text class="section-title">🎯 行动数据</text>
  46. </view>
  47. <view class="wealth-card">
  48. <view class="wealth-item">
  49. <text class="wealth-value">{{ actionData.taskCount }}</text>
  50. <text class="wealth-label">完成任务</text>
  51. </view>
  52. <view class="wealth-divider"></view>
  53. <view class="wealth-item">
  54. <text class="wealth-value">{{ actionData.purchaseCount }}</text>
  55. <text class="wealth-label">购买商品</text>
  56. </view>
  57. <view class="wealth-divider"></view>
  58. <view class="wealth-item">
  59. <text class="wealth-value">{{ actionData.activityCount }}</text>
  60. <text class="wealth-label">参加活动</text>
  61. </view>
  62. <view class="wealth-divider"></view>
  63. <view class="wealth-item">
  64. <text class="wealth-value">{{ actionData.courseCount }}</text>
  65. <text class="wealth-label">学习课程</text>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 财富数据(推广收益) -->
  70. <view class="section">
  71. <view class="section-header">
  72. <text class="section-title">💰 财富数据</text>
  73. <text class="section-more" @click="goToPromotion">全部 ›</text>
  74. </view>
  75. <view class="wealth-card">
  76. <view class="wealth-item">
  77. <text class="wealth-value">{{ formatPriceWithSymbol(wealthData.totalEarnings) }}</text>
  78. <text class="wealth-label">累计收益</text>
  79. </view>
  80. <view class="wealth-divider"></view>
  81. <view class="wealth-item">
  82. <text class="wealth-value">{{ formatPriceWithSymbol(wealthData.availableAmount) }}</text>
  83. <text class="wealth-label">可提现</text>
  84. </view>
  85. <view class="wealth-divider"></view>
  86. <view class="wealth-item">
  87. <text class="wealth-value">{{ wealthData.referralCount }}</text>
  88. <text class="wealth-label">邀请人数</text>
  89. </view>
  90. </view>
  91. <view class="referral-code-bar" @click="copyReferralCode" v-if="wealthData.referralCode">
  92. <text class="referral-code-label">邀请码</text>
  93. <text class="referral-code-value">{{ wealthData.referralCode }}</text>
  94. <text class="referral-code-copy">复制</text>
  95. </view>
  96. </view>
  97. <!-- 成就徽章 -->
  98. <view class="section">
  99. <view class="section-header">
  100. <text class="section-title">🏅 成就徽章</text>
  101. <text class="section-more" @click="goAllBadges">全部 ›</text>
  102. </view>
  103. <view class="badge-grid">
  104. <view class="badge-item" v-for="badge in badges" :key="badge.id">
  105. <view :class="['badge-icon-wrap', badge.unlocked ? 'unlocked' : 'locked']">
  106. <text class="badge-icon">{{ badge.icon }}</text>
  107. </view>
  108. <text class="badge-name">{{ badge.name }}</text>
  109. </view>
  110. </view>
  111. </view>
  112. <!-- 成长报告 -->
  113. <view class="section">
  114. <view class="section-header">
  115. <text class="section-title">📈 成长报告</text>
  116. <text class="section-more" @click="goGrowthReport">查看 ›</text>
  117. </view>
  118. <view class="report-card" @click="goGrowthReport">
  119. <view class="report-stat-item">
  120. <text class="report-stat">{{ growthReport.monthActiveDays || 0 }}天</text>
  121. <text class="report-label">本月活跃</text>
  122. </view>
  123. <view class="report-divider"></view>
  124. <view class="report-stat-item">
  125. <text class="report-stat">{{ growthReport.totalTasks || 0 }}</text>
  126. <text class="report-label">累计任务</text>
  127. </view>
  128. <view class="report-divider"></view>
  129. <view class="report-stat-item">
  130. <text class="report-stat">{{ growthReport.completionRate || 0 }}%</text>
  131. <text class="report-label">完成率</text>
  132. </view>
  133. </view>
  134. </view>
  135. <view class="menu-list">
  136. <!-- ===== 个人 ===== -->
  137. <view class="menu-group">
  138. <view class="menu-group-title">── 个人 ──</view>
  139. <view class="menu-item" @click="goToEditInfo">
  140. <text>📝 修改个人资料</text>
  141. <text class="arrow">›</text>
  142. </view>
  143. <view class="menu-item" v-if="role === 'parent'" @click="goToChildren">
  144. <text>👶 我的孩子</text>
  145. <text class="arrow">›</text>
  146. </view>
  147. <view class="menu-item" v-if="role === 'parent'" @click="goToFamilyMembers">
  148. <text>👨‍👩‍👧‍👦 家庭成员</text>
  149. <text class="arrow">›</text>
  150. </view>
  151. </view>
  152. <!-- ===== 财富 ===== -->
  153. <view class="menu-group">
  154. <view class="menu-group-title">── 财富 ──</view>
  155. <view class="menu-item" @click="goToPromotion">
  156. <text>📢 推广中心</text>
  157. <text class="arrow">›</text>
  158. </view>
  159. <view class="menu-item" @click="goToPointsLogs">
  160. <text>📊 积分记录</text>
  161. <text class="arrow">›</text>
  162. </view>
  163. </view>
  164. <!-- ===== 服务 ===== -->
  165. <view class="menu-group">
  166. <view class="menu-group-title">── 服务 ──</view>
  167. <view class="menu-item" @click="goToMembership">
  168. <text>👑 会员中心</text>
  169. <text class="arrow">›</text>
  170. </view>
  171. <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
  172. <text>🏪 服务商中心</text>
  173. <text class="arrow">›</text>
  174. </view>
  175. <view class="menu-item" @click="goToOrders">
  176. <text>🛒 订单管理</text>
  177. <text class="arrow">›</text>
  178. </view>
  179. </view>
  180. <!-- ===== 设置 ===== -->
  181. <view class="menu-group">
  182. <view class="menu-group-title">── 设置 ──</view>
  183. <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
  184. <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
  185. <text class="arrow">›</text>
  186. </view>
  187. <view class="menu-item menu-item-switch" v-if="role === 'parent'">
  188. <text>👁 对家庭成员可见</text>
  189. <switch :checked="showToFamily === 1" @change="onShowToFamilyChange" color="#5B9BD5" />
  190. </view>
  191. <view class="menu-item" @click="showInviteActionSheet">
  192. <text>📨 邀请加入</text>
  193. <text class="arrow">›</text>
  194. </view>
  195. <view class="menu-item" @click="logout">
  196. <text>🚪 退出登录</text>
  197. <text class="arrow">›</text>
  198. </view>
  199. </view>
  200. </view>
  201. <!-- 设置/重置密码弹窗 -->
  202. <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
  203. <view class="modal" @click.stop>
  204. <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
  205. <view class="form-item" v-if="hasPassword">
  206. <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
  207. </view>
  208. <view class="form-item">
  209. <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
  210. </view>
  211. <view class="form-item">
  212. <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
  213. </view>
  214. <view class="modal-btns">
  215. <button @click="showPasswordModal = false">取消</button>
  216. <button class="btn-primary" @click="savePassword">确定</button>
  217. </view>
  218. </view>
  219. </view>
  220. </template>
  221. </view>
  222. </template>
  223. <script>
  224. import PageBanner from '../../components/PageBanner.vue'
  225. import { setPassword, verifyPassword, getChildren, vendorStatus, getEnergyOverview, getUserActionStats, getReferralCode, getReferralSummary, getCommissionSummary, updateMemberVisibility, getVisibleFamilyMembers, getUserBadges, getGrowthReport } from '../../utils/api.js'
  226. export default {
  227. components: { PageBanner },
  228. data() {
  229. return {
  230. nickname: '',
  231. role: 'parent',
  232. hasPassword: false,
  233. showPasswordModal: false,
  234. oldPassword: '',
  235. newPassword: '',
  236. confirmPassword: '',
  237. children: [],
  238. isSwitchedChild: false,
  239. shareData: null,
  240. isVendor: false,
  241. showToFamily: 1,
  242. totalEnergy: null,
  243. wealthEnergy: 0,
  244. energyTrend: 0,
  245. badgesLoaded: false,
  246. badges: [
  247. { id: 1, icon: '\u{1F3C6}', name: '连续7天', unlocked: false },
  248. { id: 2, icon: '\u{2B50}', name: '积分达人', unlocked: false },
  249. { id: 3, icon: '\u{1F525}', name: '执行之星', unlocked: false },
  250. { id: 4, icon: '\u{1F31F}', name: '学习先锋', unlocked: false }
  251. ],
  252. actionData: {
  253. purchaseCount: 0,
  254. activityCount: 0,
  255. taskCount: 0,
  256. courseCount: 0
  257. },
  258. wealthData: {
  259. totalEarnings: '0.00',
  260. availableAmount: '0.00',
  261. referralCount: 0,
  262. referralCode: ''
  263. },
  264. growthReport: {
  265. monthActiveDays: 0,
  266. totalTasks: 0,
  267. completionRate: 0
  268. }
  269. }
  270. },
  271. computed: {
  272. isLoggedIn() {
  273. return !!uni.getStorageSync('token')
  274. }
  275. },
  276. onShareAppMessage() {
  277. if (this.shareData) {
  278. return {
  279. title: this.shareData.title,
  280. path: this.shareData.path,
  281. imageUrl: '/static/invite-card.png'
  282. }
  283. }
  284. },
  285. onShow() {
  286. if (!uni.getStorageSync('token')) return
  287. const currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  288. if (currentRole === 'teacher') {
  289. uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
  290. return
  291. }
  292. var userInfo = uni.getStorageSync('userInfo')
  293. this.nickname = this.$store.state.nickname || (userInfo && userInfo.nickname) || ''
  294. // 使用 currentRole(视图角色),而非 role(实际角色)
  295. this.role = currentRole
  296. this.hasPassword = !!uni.getStorageSync('passwordSet')
  297. // 获取切换标记
  298. this.isSwitchedChild = uni.getStorageSync('isSwitchedChild') || false
  299. this.loadChildren()
  300. this.loadShowToFamily()
  301. this.checkVendorStatus()
  302. this.loadEnergyData()
  303. this.loadBadges()
  304. this.loadGrowthReport()
  305. this.loadActionData()
  306. this.loadWealthData()
  307. },
  308. methods: {
  309. goLogin() {
  310. uni.navigateTo({ url: '/pages/login/login' })
  311. },
  312. async loadChildren() {
  313. try {
  314. const res = await getChildren()
  315. this.children = res.data || []
  316. } catch (e) {
  317. console.error('获取孩子列表失败', e)
  318. }
  319. },
  320. async loadShowToFamily() {
  321. try {
  322. var uid = this.$store.state.userId || uni.getStorageSync('userId')
  323. var res = await getVisibleFamilyMembers()
  324. var members = res.data || []
  325. var self = members.find(function(m) { return m.id == uid })
  326. if (self) {
  327. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  328. }
  329. } catch (e) {
  330. console.error('获取可见性设置失败', e)
  331. }
  332. },
  333. goToEditInfo() {
  334. uni.navigateTo({ url: '/pages/user-edit/user-edit' })
  335. },
  336. goToChildren() {
  337. uni.navigateTo({ url: '/pages/profile/children' })
  338. },
  339. goToFamilyMembers() {
  340. uni.navigateTo({ url: '/pages/profile/family-members' })
  341. },
  342. goToPointsLogs() {
  343. uni.navigateTo({ url: '/pages/points/points' })
  344. },
  345. async onShowToFamilyChange(e) {
  346. var val = e.detail.value ? 1 : 0
  347. var uid = this.$store.state.userId || uni.getStorageSync('userId')
  348. try {
  349. await updateMemberVisibility(uid, 'parent', val)
  350. this.showToFamily = val
  351. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  352. } catch (e) {
  353. console.error('更新可见性失败', e)
  354. uni.showToast({ title: '操作失败', icon: 'none' })
  355. }
  356. },
  357. switchMode() {
  358. if (this.role === 'child') {
  359. this.verifyPasswordForSwitch(() => {
  360. this.doSwitchMode()
  361. })
  362. } else {
  363. this.doSwitchMode()
  364. }
  365. },
  366. doSwitchMode() {
  367. const newRole = this.role === 'parent' ? 'child' : 'parent'
  368. if (newRole === 'child') {
  369. if (this.children.length === 0) {
  370. this.loadChildren()
  371. }
  372. if (this.children.length === 0) {
  373. uni.showModal({
  374. title: '提示',
  375. content: '您还没有添加孩子,是否现在去添加?',
  376. success: (res) => {
  377. if (res.confirm) {
  378. uni.navigateTo({ url: '/pages/profile/create-child' })
  379. }
  380. }
  381. })
  382. return
  383. }
  384. if (this.children.length === 1) {
  385. this.$store.commit('switchToChild', this.children[0].id)
  386. this.role = newRole
  387. uni.showToast({ title: '已切换为孩子模式', icon: 'success' })
  388. return
  389. }
  390. uni.showActionSheet({
  391. itemList: this.children.map(c => c.nickname),
  392. success: (res) => {
  393. const selectedChild = this.children[res.tapIndex]
  394. this.$store.commit('switchToChild', selectedChild.id)
  395. this.role = newRole
  396. uni.showToast({ title: `已切换为${selectedChild.nickname}模式`, icon: 'success' })
  397. }
  398. })
  399. return
  400. }
  401. this.$store.commit('switchBackToParent')
  402. this.role = newRole
  403. uni.showToast({ title: `已切换为${newRole === 'parent' ? '家长' : '孩子'}模式`, icon: 'success' })
  404. },
  405. verifyPasswordForSwitch(callback) {
  406. uni.showModal({
  407. title: '验证密码',
  408. content: '请输入家长密码',
  409. editable: true,
  410. success: async (res) => {
  411. if (res.confirm && res.content) {
  412. try {
  413. const result = await verifyPassword(res.content)
  414. if (result.code === 200) {
  415. callback && callback()
  416. } else {
  417. uni.showToast({ title: '密码错误', icon: 'none' })
  418. }
  419. } catch (e) {
  420. uni.showToast({ title: '验证失败', icon: 'none' })
  421. }
  422. }
  423. }
  424. })
  425. },
  426. async savePassword() {
  427. if (this.newPassword.length !== 6) {
  428. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  429. return
  430. }
  431. if (this.newPassword !== this.confirmPassword) {
  432. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  433. return
  434. }
  435. if (this.hasPassword && this.oldPassword.length !== 6) {
  436. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  437. return
  438. }
  439. try {
  440. if (this.hasPassword) {
  441. const verifyRes = await verifyPassword(this.oldPassword)
  442. if (verifyRes.code !== 200) {
  443. uni.showToast({ title: '旧密码错误', icon: 'none' })
  444. return
  445. }
  446. }
  447. await setPassword(this.newPassword)
  448. uni.setStorageSync('passwordSet', true)
  449. this.hasPassword = true
  450. uni.showToast({ title: '密码设置成功', icon: 'success' })
  451. this.showPasswordModal = false
  452. this.oldPassword = ''
  453. this.newPassword = ''
  454. this.confirmPassword = ''
  455. } catch (e) {
  456. console.error('设置密码失败', e)
  457. }
  458. },
  459. logout() {
  460. uni.showModal({
  461. title: '确认退出',
  462. content: '确定要退出登录吗?',
  463. success: (res) => {
  464. if (res.confirm) {
  465. this.$store.commit('logout')
  466. // 退出后返回首页 Tab(预登录状态,5 个底签可见)
  467. uni.reLaunch({ url: '/pages/index/index' })
  468. }
  469. }
  470. })
  471. },
  472. showInviteActionSheet: function() {
  473. var familyId = uni.getStorageSync('familyId')
  474. var userInfo = uni.getStorageSync('userInfo')
  475. if (!familyId) {
  476. uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
  477. return
  478. }
  479. var items = ['👨‍👩‍👧‍👦 邀请家人', '👨‍🏫 邀请成长规划师']
  480. var types = ['family', 'guide']
  481. uni.showActionSheet({
  482. itemList: items,
  483. success: function(res) {
  484. this.inviteGenerate(types[res.tapIndex], familyId, userInfo)
  485. }.bind(this),
  486. fail: function() {}
  487. })
  488. },
  489. inviteGenerate: function(type, familyId, userInfo) {
  490. try {
  491. var inviteTypes = {
  492. family: { title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭', path: '/pages/login/login?invite_type=family' },
  493. guide: { title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师', path: '/pages/login/login?invite_type=guide' }
  494. }
  495. var config = inviteTypes[type] || inviteTypes.family
  496. this.shareData = {
  497. title: config.title,
  498. path: config.path + '&invite_code=',
  499. imageUrl: '/static/invite-card.png'
  500. }
  501. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  502. } catch (e) {
  503. uni.showToast({ title: e.message || '邀请失败', icon: 'none' })
  504. }
  505. },
  506. goToMembership() {
  507. uni.showToast({ title: '即将上线', icon: 'none' })
  508. },
  509. goToVendorCenter() {
  510. uni.navigateTo({ url: '/pages/vendor/center' })
  511. },
  512. goToOrders() {
  513. uni.showToast({ title: '即将上线', icon: 'none' })
  514. },
  515. goToPromotion() {
  516. uni.navigateTo({ url: '/pages/promotion/index' })
  517. },
  518. loadEnergyData: function() {
  519. var childId = uni.getStorageSync('currentChildId') || null
  520. if (!childId) {
  521. if (this.children.length > 0) {
  522. childId = this.children[0].id
  523. }
  524. }
  525. if (!childId) return
  526. try {
  527. getEnergyOverview(childId).then(function(res) {
  528. if (res && res.data) {
  529. this.totalEnergy = res.data.totalEnergy || 0
  530. var dims = res.data.dimensions
  531. if (dims && dims.length > 0) {
  532. for (var i = 0; i < dims.length; i++) {
  533. if (dims[i].code === 'wealth') {
  534. this.wealthEnergy = dims[i].score || 0
  535. break
  536. }
  537. }
  538. }
  539. }
  540. }.bind(this))
  541. } catch (e) { console.log('获取能量概览失败', e) }
  542. },
  543. loadBadges: function() {
  544. var childId = uni.getStorageSync('currentChildId') || null
  545. if (!childId && this.children.length > 0) {
  546. childId = this.children[0].id
  547. }
  548. var defaultBadges = [
  549. { id: 1, icon: '\u{1F3C6}', name: '连续7天', unlocked: false },
  550. { id: 2, icon: '\u{2B50}', name: '积分达人', unlocked: false },
  551. { id: 3, icon: '\u{1F525}', name: '执行之星', unlocked: false },
  552. { id: 4, icon: '\u{1F31F}', name: '学习先锋', unlocked: false },
  553. { id: 5, icon: '\u{1F4AA}', name: '体能达人', unlocked: false },
  554. { id: 6, icon: '\u{1F9E0}', name: '心智成长', unlocked: false },
  555. { id: 7, icon: '\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}', name: '家庭之星', unlocked: false },
  556. { id: 8, icon: '\u{1F4DA}', name: '阅读达人', unlocked: false },
  557. { id: 9, icon: '\u{1F3AF}', name: '全能冠军', unlocked: false }
  558. ]
  559. if (childId) {
  560. try {
  561. getUserBadges(childId).then(function(res) {
  562. if (res.code === 200 && res.data && res.data.length > 0) {
  563. var list = []
  564. for (var i = 0; i < res.data.length; i++) {
  565. var item = res.data[i]
  566. var b = item.badge || {}
  567. list.push({
  568. id: b.id || i + 1,
  569. icon: b.icon || '\u{2B50}',
  570. name: b.name || '未知勋章',
  571. unlocked: true
  572. })
  573. }
  574. while (list.length < 9) {
  575. var idx = list.length
  576. list.push({
  577. id: defaultBadges[idx].id,
  578. icon: defaultBadges[idx].icon,
  579. name: defaultBadges[idx].name,
  580. unlocked: false
  581. })
  582. }
  583. this.badges = list.slice(0, 9)
  584. this.badgesLoaded = true
  585. return
  586. }
  587. this.loadBadgesLocal(defaultBadges)
  588. }.bind(this)).catch(function() {
  589. this.loadBadgesLocal(defaultBadges)
  590. }.bind(this))
  591. } catch (e) {
  592. this.loadBadgesLocal(defaultBadges)
  593. }
  594. } else {
  595. this.loadBadgesLocal(defaultBadges)
  596. }
  597. },
  598. loadBadgesLocal: function(defaultBadges) {
  599. var streakDays = parseInt(uni.getStorageSync('streakDays') || 0)
  600. var totalPoints = parseInt(uni.getStorageSync('totalPoints') || 0)
  601. var completedTasks = parseInt(uni.getStorageSync('completedTasks') || 0)
  602. var badges = JSON.parse(JSON.stringify(defaultBadges))
  603. if (streakDays >= 7) badges[0].unlocked = true
  604. if (totalPoints >= 1000) badges[1].unlocked = true
  605. if (completedTasks >= 50) badges[2].unlocked = true
  606. if (totalPoints >= 500) badges[3].unlocked = true
  607. if (streakDays >= 30) badges[4].unlocked = true
  608. if (completedTasks >= 100) badges[8].unlocked = true
  609. this.badges = badges
  610. this.badgesLoaded = true
  611. },
  612. loadGrowthReport: function() {
  613. var childId = uni.getStorageSync('currentChildId') || null
  614. if (!childId && this.children.length > 0) {
  615. childId = this.children[0].id
  616. }
  617. if (!childId) {
  618. this.loadGrowthReportLocal()
  619. return
  620. }
  621. try {
  622. getGrowthReport(childId).then(function(res) {
  623. if (res.code === 200 && res.data) {
  624. var d = res.data
  625. this.growthReport.monthActiveDays = d.monthActiveDays || d.activeDays || 0
  626. this.growthReport.totalTasks = (d.taskStats && d.taskStats.total) || d.totalTasks || 0
  627. this.growthReport.completionRate = (d.taskStats && d.taskStats.completionRate) || d.completionRate || 0
  628. } else {
  629. this.loadGrowthReportLocal()
  630. }
  631. }.bind(this)).catch(function() {
  632. this.loadGrowthReportLocal()
  633. }.bind(this))
  634. } catch (e) {
  635. this.loadGrowthReportLocal()
  636. }
  637. },
  638. loadGrowthReportLocal: function() {
  639. var streakDays = parseInt(uni.getStorageSync('streakDays') || 0)
  640. var completedTasks = parseInt(uni.getStorageSync('completedTasks') || 0)
  641. this.growthReport.monthActiveDays = streakDays > 0 ? Math.min(streakDays, 30) : 0
  642. this.growthReport.totalTasks = completedTasks || 0
  643. this.growthReport.completionRate = 85
  644. },
  645. async loadActionData() {
  646. try {
  647. const res = await getUserActionStats()
  648. if (res.code === 200 && res.data) {
  649. this.actionData.purchaseCount = res.data.purchaseCount || 0
  650. this.actionData.activityCount = res.data.activityCount || 0
  651. this.actionData.taskCount = res.data.taskCount || 0
  652. this.actionData.courseCount = res.data.courseCount || 0
  653. }
  654. } catch (e) {
  655. // Fallback to local computed stats
  656. this.actionData.taskCount = parseInt(uni.getStorageSync('completedTasks') || 0)
  657. console.log('获取行动统计失败,使用本地数据', e)
  658. }
  659. },
  660. async loadWealthData() {
  661. try {
  662. const codeRes = await getReferralCode()
  663. if (codeRes.data) {
  664. this.wealthData.referralCode = codeRes.data.referralCode || codeRes.data.code || ''
  665. }
  666. } catch (e) { console.log('获取邀请码失败', e) }
  667. try {
  668. const summaryRes = await getReferralSummary()
  669. if (summaryRes.data) {
  670. this.wealthData.totalEarnings = summaryRes.data.totalEarnings || '0.00'
  671. this.wealthData.referralCount = summaryRes.data.referredCount || summaryRes.data.totalCount || 0
  672. }
  673. } catch (e) { console.log('获取邀请统计失败', e) }
  674. try {
  675. const comRes = await getCommissionSummary()
  676. if (comRes.data) {
  677. this.wealthData.availableAmount = comRes.data.availableAmount || '0.00'
  678. }
  679. } catch (e) { console.log('获取佣金总览失败', e) }
  680. },
  681. copyReferralCode() {
  682. if (!this.wealthData.referralCode) return
  683. uni.setClipboardData({
  684. data: this.wealthData.referralCode,
  685. success: () => { uni.showToast({ title: '邀请码已复制', icon: 'success' }) }
  686. })
  687. },
  688. goAllBadges() {
  689. uni.showToast({ title: '即将上线', icon: 'none' })
  690. },
  691. goGrowthReport() {
  692. var childId = uni.getStorageSync('currentChildId') || ''
  693. uni.navigateTo({ url: '/pages/growth/report?childId=' + childId })
  694. },
  695. async checkVendorStatus() {
  696. try {
  697. const res = await vendorStatus()
  698. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  699. } catch (e) {
  700. this.isVendor = false
  701. }
  702. },
  703. exitSwitch() {
  704. if (!this.isSwitchedChild) return
  705. uni.showModal({
  706. title: '退出切换',
  707. content: '请输入家长密码以确认退出',
  708. editable: true,
  709. success: async (res) => {
  710. if (res.confirm && res.content) {
  711. try {
  712. const verifyResult = await verifyPassword(res.content)
  713. if (verifyResult.code === 200) {
  714. this.$store.commit('switchBackToParent')
  715. this.isSwitchedChild = false
  716. this.role = 'parent'
  717. uni.showToast({ title: '已退出切换', icon: 'success' })
  718. // 刷新首页
  719. uni.reLaunch({ url: '/pages/index/index' })
  720. } else {
  721. uni.showToast({ title: '密码错误', icon: 'none' })
  722. }
  723. } catch (e) {
  724. uni.showToast({ title: '验证失败', icon: 'none' })
  725. }
  726. }
  727. }
  728. })
  729. }
  730. }
  731. }
  732. </script>
  733. <style scoped>
  734. .container {
  735. min-height: 100vh;
  736. background: #f5f7fa;
  737. padding-bottom: 120rpx;
  738. }
  739. /* ===== 通用区块 ===== */
  740. .section {
  741. margin: 20rpx 30rpx;
  742. }
  743. .section-header {
  744. display: flex;
  745. justify-content: space-between;
  746. align-items: center;
  747. margin-bottom: 20rpx;
  748. }
  749. .section-title {
  750. font-size: 30rpx;
  751. font-weight: bold;
  752. color: #333;
  753. }
  754. .section-more {
  755. font-size: 24rpx;
  756. color: #999;
  757. }
  758. /* ===== 推广邀请码 ===== */
  759. .referral-code-bar {
  760. display: flex;
  761. align-items: center;
  762. background: #fff;
  763. border-radius: 16rpx;
  764. padding: 20rpx 24rpx;
  765. margin-top: 16rpx;
  766. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  767. }
  768. .referral-code-label {
  769. font-size: 26rpx;
  770. color: #999;
  771. margin-right: 16rpx;
  772. }
  773. .referral-code-value {
  774. flex: 1;
  775. font-size: 28rpx;
  776. font-weight: bold;
  777. color: #F97316;
  778. letter-spacing: 4rpx;
  779. }
  780. .referral-code-copy {
  781. font-size: 24rpx;
  782. color: #5B9BD5;
  783. padding: 4rpx 16rpx;
  784. border: 1rpx solid #5B9BD5;
  785. border-radius: 8rpx;
  786. }
  787. /* ===== 行动数据(推广收益) ===== */
  788. .wealth-card {
  789. background: #fff;
  790. border-radius: 20rpx;
  791. padding: 30rpx 20rpx;
  792. display: flex;
  793. align-items: center;
  794. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  795. }
  796. .wealth-item {
  797. flex: 1;
  798. display: flex;
  799. flex-direction: column;
  800. align-items: center;
  801. }
  802. .wealth-value {
  803. font-size: 40rpx;
  804. font-weight: bold;
  805. color: #F97316;
  806. }
  807. .wealth-label {
  808. font-size: 24rpx;
  809. color: #999;
  810. margin-top: 8rpx;
  811. }
  812. .wealth-divider {
  813. width: 1rpx;
  814. height: 60rpx;
  815. background: #f0f0f0;
  816. }
  817. /* ===== 成就徽章 ===== */
  818. .badge-grid {
  819. display: flex;
  820. flex-direction: row;
  821. flex-wrap: wrap;
  822. background: #fff;
  823. border-radius: 20rpx;
  824. padding: 24rpx 16rpx;
  825. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  826. justify-content: flex-start;
  827. }
  828. .badge-item {
  829. display: flex;
  830. flex-direction: column;
  831. align-items: center;
  832. width: 33.33%;
  833. margin-bottom: 20rpx;
  834. }
  835. .badge-icon-wrap {
  836. width: 72rpx;
  837. height: 72rpx;
  838. border-radius: 50%;
  839. display: flex;
  840. align-items: center;
  841. justify-content: center;
  842. margin-bottom: 8rpx;
  843. }
  844. .badge-icon-wrap.unlocked {
  845. background: linear-gradient(135deg, #FBBF24, #F97316);
  846. }
  847. .badge-icon-wrap.locked {
  848. background: #f0f0f0;
  849. opacity: 0.5;
  850. }
  851. .badge-icon {
  852. font-size: 36rpx;
  853. }
  854. .badge-name {
  855. font-size: 22rpx;
  856. color: #666;
  857. }
  858. /* ===== 成长报告 ===== */
  859. .report-card {
  860. background: #fff;
  861. border-radius: 20rpx;
  862. padding: 30rpx 20rpx;
  863. display: flex;
  864. align-items: center;
  865. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  866. }
  867. .report-stat-item {
  868. flex: 1;
  869. display: flex;
  870. flex-direction: column;
  871. align-items: center;
  872. }
  873. .report-stat {
  874. font-size: 36rpx;
  875. font-weight: bold;
  876. color: #5B9BD5;
  877. }
  878. .report-label {
  879. font-size: 22rpx;
  880. color: #999;
  881. margin-top: 6rpx;
  882. }
  883. .report-divider {
  884. width: 1rpx;
  885. height: 50rpx;
  886. background: #f0f0f0;
  887. }
  888. /* ===== 富沛能量值条 ===== */
  889. .wealth-energy-header {
  890. background: linear-gradient(135deg, #42A5F5, #64B5F6);
  891. padding: 16rpx 30rpx;
  892. display: flex;
  893. flex-direction: row;
  894. align-items: center;
  895. }
  896. .energy-header-icon {
  897. font-size: 36rpx;
  898. margin-right: 12rpx;
  899. }
  900. .energy-header-value {
  901. font-size: 40rpx;
  902. font-weight: bold;
  903. color: #fff;
  904. margin-right: 12rpx;
  905. }
  906. .energy-header-label {
  907. font-size: 26rpx;
  908. color: #D6EAF8;
  909. margin-right: auto;
  910. }
  911. .energy-header-trend {
  912. font-size: 24rpx;
  913. color: #4ADE80;
  914. font-weight: 500;
  915. }
  916. .user-card {
  917. background: linear-gradient(135deg, #5B9BD5 0%, #3A7CC4 100%);
  918. border-radius: 20rpx;
  919. padding: 40rpx;
  920. display: flex;
  921. align-items: center;
  922. color: #fff;
  923. }
  924. .avatar {
  925. font-size: 80rpx;
  926. margin-right: 30rpx;
  927. }
  928. .user-info {
  929. flex: 1;
  930. }
  931. .nickname {
  932. font-size: 36rpx;
  933. font-weight: bold;
  934. }
  935. .role {
  936. font-size: 24rpx;
  937. opacity: 0.8;
  938. }
  939. .system-points {
  940. font-size: 22rpx;
  941. color: #D6EAF8;
  942. margin-top: 8rpx;
  943. font-weight: 500;
  944. }
  945. .wealth-energy-row {
  946. display: flex;
  947. flex-direction: row;
  948. align-items: center;
  949. margin-top: 8rpx;
  950. }
  951. .wealth-energy-icon {
  952. font-size: 24rpx;
  953. margin-right: 8rpx;
  954. }
  955. .wealth-energy-value {
  956. font-size: 24rpx;
  957. color: #D6EAF8;
  958. font-weight: 500;
  959. }
  960. .wealth-energy-row .wealth-energy-trend {
  961. font-size: 22rpx;
  962. color: #4ADE80;
  963. margin-left: 8rpx;
  964. }
  965. .btn-switch {
  966. background: rgba(255, 255, 255, 0.2);
  967. color: #fff;
  968. font-size: 24rpx;
  969. padding: 10rpx 20rpx;
  970. border-radius: 20rpx;
  971. }
  972. /* ===== 功能菜单分组 ===== */
  973. .menu-group {
  974. margin-top: 20rpx;
  975. }
  976. .menu-group-title {
  977. font-size: 24rpx;
  978. color: #ccc;
  979. text-align: center;
  980. padding: 12rpx 0;
  981. letter-spacing: 4rpx;
  982. }
  983. .menu-list {
  984. margin-top: 30rpx;
  985. background: #fff;
  986. border-radius: 16rpx;
  987. }
  988. .menu-item {
  989. padding: 30rpx;
  990. border-bottom: 1rpx solid #f0f0f0;
  991. display: flex;
  992. justify-content: space-between;
  993. font-size: 28rpx;
  994. }
  995. .menu-item:last-child {
  996. border-bottom: none;
  997. }
  998. .arrow {
  999. color: #ccc;
  1000. font-size: 32rpx;
  1001. }
  1002. .menu-item-btn {
  1003. display: flex;
  1004. justify-content: space-between;
  1005. align-items: center;
  1006. width: 100%;
  1007. padding: 28rpx 24rpx;
  1008. border: none;
  1009. background: transparent;
  1010. font-size: 28rpx;
  1011. color: #333;
  1012. }
  1013. .menu-item-btn::after { border: none; }
  1014. .menu-item-switch {
  1015. align-items: center;
  1016. }
  1017. .modal-mask {
  1018. position: fixed;
  1019. top: 0;
  1020. left: 0;
  1021. right: 0;
  1022. bottom: 0;
  1023. background: rgba(0, 0, 0, 0.5);
  1024. display: flex;
  1025. align-items: center;
  1026. justify-content: center;
  1027. }
  1028. .modal {
  1029. background: #fff;
  1030. border-radius: 20rpx;
  1031. padding: 40rpx;
  1032. width: 80%;
  1033. }
  1034. .modal-title {
  1035. font-size: 32rpx;
  1036. font-weight: bold;
  1037. margin-bottom: 30rpx;
  1038. text-align: center;
  1039. }
  1040. .form-item {
  1041. margin-bottom: 20rpx;
  1042. }
  1043. .form-item input {
  1044. border: 1rpx solid #ddd;
  1045. border-radius: 10rpx;
  1046. padding: 20rpx;
  1047. font-size: 28rpx;
  1048. }
  1049. .modal-btns {
  1050. display: flex;
  1051. gap: 20rpx;
  1052. margin-top: 30rpx;
  1053. }
  1054. .modal-btns button {
  1055. flex: 1;
  1056. }
  1057. /* ===== 未登录提示 ===== */
  1058. .login-prompt {
  1059. display: flex;
  1060. flex-direction: column;
  1061. align-items: center;
  1062. justify-content: center;
  1063. min-height: 80vh;
  1064. padding: 60rpx;
  1065. }
  1066. .prompt-icon {
  1067. font-size: 120rpx;
  1068. margin-bottom: 30rpx;
  1069. width: 160rpx;
  1070. height: 160rpx;
  1071. line-height: 160rpx;
  1072. text-align: center;
  1073. background: #f5f5f5;
  1074. border-radius: 50%;
  1075. }
  1076. .prompt-title {
  1077. font-size: 36rpx;
  1078. font-weight: bold;
  1079. color: #333;
  1080. margin-bottom: 16rpx;
  1081. }
  1082. .prompt-desc {
  1083. font-size: 26rpx;
  1084. color: #999;
  1085. text-align: center;
  1086. margin-bottom: 40rpx;
  1087. }
  1088. .login-prompt .login-btn {
  1089. width: 60%;
  1090. height: 80rpx;
  1091. line-height: 80rpx;
  1092. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  1093. color: #fff;
  1094. font-size: 30rpx;
  1095. font-weight: bold;
  1096. border-radius: 40rpx;
  1097. text-align: center;
  1098. border: none;
  1099. }
  1100. .login-prompt .login-btn::after {
  1101. border: none;
  1102. }
  1103. </style>