profile.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. <template>
  2. <view class="container">
  3. <!-- 未登录 -->
  4. <view v-if="!isLoggedIn" class="login-prompt">
  5. <text class="prompt-icon">👤</text>
  6. <text class="prompt-title">登录浠艾福</text>
  7. <text class="prompt-desc">登录后查看个人资料、积分记录、能量数据与家庭管理</text>
  8. <button class="login-btn" @click="goLogin">登录 / 注册</button>
  9. <text class="skip-link" @click="goSkip">暂不登录,先逛逛 ›</text>
  10. </view>
  11. <!-- 已登录 -->
  12. <template v-else>
  13. <!-- 退出切换 -->
  14. <view class="exit-switch" v-if="isSwitchedChild" @click="onExitSwitch">
  15. <text>🔄 退出切换</text>
  16. </view>
  17. <!-- 用户身份卡片 -->
  18. <view class="user-card">
  19. <view class="user-card-left">
  20. <view class="avatar-wrap" @click="goToEditInfo">
  21. <image v-if="userInfo.avatar" class="avatar-img" :src="userInfo.avatar" mode="aspectFill" />
  22. <text v-else class="avatar-text">{{ nickname.charAt(0) || '👤' }}</text>
  23. </view>
  24. <view class="user-meta">
  25. <view class="user-name-row">
  26. <text class="nickname">{{ nickname || '未设置昵称' }}</text>
  27. <text class="role-tag">{{ roleLabel }}</text>
  28. </view>
  29. <view class="user-sub" v-if="memberLevel">
  30. <view class="level-badge" :class="'level-' + memberLevel">{{ memberLevelText }}</view>
  31. <text v-if="isLifetime" class="days-left">永久有效</text>
  32. <text v-else-if="membershipDays > 0 && membershipDays <= 30" class="days-left">剩余 {{ membershipDays }} 天</text>
  33. <view v-if="hasUpgradeSpace" class="upgrade-btn" @click="goUpgrade">
  34. <text class="upgrade-btn-text">{{ upgradeBtnText }}</text>
  35. </view>
  36. </view>
  37. <view class="user-sub" v-else>
  38. <text class="days-left">开通会员解锁更多权益</text>
  39. <view class="upgrade-btn" @click="goUpgrade">
  40. <text class="upgrade-btn-text">立即开通</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="user-card-right">
  46. <view class="points-box" @click="goToPoints">
  47. <text class="points-num">{{ totalPoints }}</text>
  48. <text class="points-label">积分</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 核心数据概览 -->
  53. <view class="stats-bar">
  54. <view class="stat-item" @click="goToTasks">
  55. <text class="stat-num">{{ pendingTasks }}</text>
  56. <text class="stat-label">待完成任务</text>
  57. </view>
  58. <view class="stat-divider"></view>
  59. <view class="stat-item" @click="goToCheckin">
  60. <text class="stat-num">{{ streakDays }}</text>
  61. <text class="stat-label">连续打卡</text>
  62. </view>
  63. <view class="stat-divider"></view>
  64. <view class="stat-item" @click="goToFamily">
  65. <text class="stat-num">{{ familyCount }}</text>
  66. <text class="stat-label">家庭成员</text>
  67. </view>
  68. <view class="stat-divider"></view>
  69. <view class="stat-item" @click="goToChallenges">
  70. <text class="stat-num">{{ activeChallenges }}</text>
  71. <text class="stat-label">进行中挑战</text>
  72. </view>
  73. </view>
  74. <!-- 商城订单快捷 -->
  75. <view class="mall-section" v-if="totalPoints > 0">
  76. <view class="mall-header" @click="goToOrders">
  77. <text class="mall-title">🛒 商城订单</text>
  78. <text class="mall-more">全部订单 ›</text>
  79. </view>
  80. <view class="mall-grid">
  81. <view class="mall-item" @click="goToOrders">
  82. <text class="mall-item-num" v-if="orderPending > 0">{{ orderPending }}</text>
  83. <text class="mall-item-num" v-else>0</text>
  84. <text class="mall-item-label">待审核</text>
  85. </view>
  86. <view class="mall-item" @click="goToOrders">
  87. <text class="mall-item-num" v-if="orderUnpaid > 0">{{ orderUnpaid }}</text>
  88. <text class="mall-item-num" v-else>0</text>
  89. <text class="mall-item-label">待付款</text>
  90. </view>
  91. <view class="mall-item" @click="goToOrders">
  92. <text class="mall-item-num" v-if="orderShipped > 0">{{ orderShipped }}</text>
  93. <text class="mall-item-num" v-else>0</text>
  94. <text class="mall-item-label">待发货</text>
  95. </view>
  96. <view class="mall-item" @click="goToOrders">
  97. <text class="mall-item-num" v-if="orderAfterSale > 0">{{ orderAfterSale }}</text>
  98. <text class="mall-item-num" v-else>0</text>
  99. <text class="mall-item-label">售后</text>
  100. </view>
  101. </view>
  102. </view>
  103. <!-- 推广中心快捷 -->
  104. <view class="mall-section" v-if="commissionBalance > 0 || referralCount > 0 || teamCount > 0">
  105. <view class="mall-header" @click="goToPromotion">
  106. <text class="mall-title">💰 推广中心</text>
  107. <text class="mall-more">进入 ›</text>
  108. </view>
  109. <view class="mall-grid">
  110. <view class="mall-item" @click="goToPromotion">
  111. <text class="mall-item-num">{{ commissionBalance }}</text>
  112. <text class="mall-item-label">可提现</text>
  113. </view>
  114. <view class="mall-item" @click="goToPromotion">
  115. <text class="mall-item-num">{{ referralCount }}</text>
  116. <text class="mall-item-label">邀请人数</text>
  117. </view>
  118. <view class="mall-item" @click="goToPromotion">
  119. <text class="mall-item-num">{{ teamCount }}</text>
  120. <text class="mall-item-label">团队人数</text>
  121. </view>
  122. </view>
  123. </view>
  124. <!-- 待办提醒 -->
  125. <view class="reminders-section" v-if="hasReminders">
  126. <view class="section-header">
  127. <text class="section-title">📌 待办提醒</text>
  128. </view>
  129. <view class="reminder-item" v-if="pendingTasks > 0" @click="goToTasks">
  130. <text class="reminder-icon">📋</text>
  131. <text class="reminder-text">有 {{ pendingTasks }} 个任务待完成</text>
  132. <text class="reminder-arrow">›</text>
  133. </view>
  134. <view class="reminder-item" v-if="activeChallenges > 0" @click="goToChallenges">
  135. <text class="reminder-icon">🔥</text>
  136. <text class="reminder-text">{{ activeChallenges }} 个挑战进行中</text>
  137. <text class="reminder-arrow">›</text>
  138. </view>
  139. <view class="reminder-item" v-if="profileProgress < 14" @click="goToEditInfo">
  140. <text class="reminder-icon">📝</text>
  141. <text class="reminder-text">个人信息待完善({{ profileProgress }}/14)</text>
  142. <text class="reminder-arrow">›</text>
  143. </view>
  144. </view>
  145. <!-- 功能菜单 -->
  146. <view class="menu-section">
  147. <!-- 家庭 -->
  148. <view class="menu-group">
  149. <view class="menu-group-title">家庭</view>
  150. <view class="menu-item" @click="goToFamily">
  151. <text class="menu-icon">👨‍👩‍👧‍👦</text>
  152. <text class="menu-text">家庭成员</text>
  153. <text class="arrow">›</text>
  154. </view>
  155. <view class="menu-item" @click="goToChildren">
  156. <text class="menu-icon">👶</text>
  157. <text class="menu-text">孩子管理</text>
  158. <text class="arrow">›</text>
  159. </view>
  160. <view class="menu-item" v-if="role === 'parent'" @click="goToAppointments">
  161. <text class="menu-icon">📅</text>
  162. <text class="menu-text">测评预约</text>
  163. <text class="arrow">›</text>
  164. </view>
  165. <view class="menu-item" @click="goToChallenges">
  166. <text class="menu-icon">🔥</text>
  167. <text class="menu-text">家庭挑战</text>
  168. <text class="arrow">›</text>
  169. </view>
  170. </view>
  171. <!-- 成长 -->
  172. <view class="menu-group">
  173. <view class="menu-group-title">成长</view>
  174. <view class="menu-item" @click="goToTasks">
  175. <text class="menu-icon">📋</text>
  176. <text class="menu-text">每日任务</text>
  177. <text class="arrow">›</text>
  178. </view>
  179. <view class="menu-item" @click="goToGrowth">
  180. <text class="menu-icon">📈</text>
  181. <text class="menu-text">成长记录</text>
  182. <text class="arrow">›</text>
  183. </view>
  184. <view class="menu-item" @click="goToReport">
  185. <text class="menu-icon">📊</text>
  186. <text class="menu-text">健康报告</text>
  187. <text class="arrow">›</text>
  188. </view>
  189. </view>
  190. <!-- 商城 -->
  191. <view class="menu-group" v-if="showServices">
  192. <view class="menu-group-title">商城</view>
  193. <view class="menu-item" @click="goToPromotion">
  194. <text class="menu-icon">💰</text>
  195. <text class="menu-text">推广中心</text>
  196. <text class="arrow">›</text>
  197. </view>
  198. <view class="menu-item" @click="goToOrders">
  199. <text class="menu-icon">🛒</text>
  200. <text class="menu-text">我的订单</text>
  201. <text class="badge" v-if="orderPending + orderUnpaid + orderShipped + orderAfterSale > 0">{{ orderPending + orderUnpaid + orderShipped + orderAfterSale }}</text>
  202. <text class="arrow">›</text>
  203. </view>
  204. <view class="menu-item" @click="goToCart">
  205. <text class="menu-icon">🛍️</text>
  206. <text class="menu-text">购物车</text>
  207. <text class="badge" v-if="cartCount > 0">{{ cartCount }}</text>
  208. <text class="arrow">›</text>
  209. </view>
  210. <view class="menu-item" @click="goToCoupons">
  211. <text class="menu-icon">🎫</text>
  212. <text class="menu-text">优惠券</text>
  213. <text class="arrow">›</text>
  214. </view>
  215. </view>
  216. <!-- 更多 -->
  217. <view class="menu-group">
  218. <view class="menu-group-title">更多</view>
  219. <view class="menu-item" v-if="role === 'parent'" @click="showInviteActionSheet">
  220. <text class="menu-icon">📨</text>
  221. <text class="menu-text">邀请加入</text>
  222. <text class="arrow">›</text>
  223. </view>
  224. <view class="menu-item" @click="goToSettings">
  225. <text class="menu-icon">⚙️</text>
  226. <text class="menu-text">设置</text>
  227. <text class="arrow">›</text>
  228. </view>
  229. <view class="menu-item" @click="logout">
  230. <text class="menu-icon">🚪</text>
  231. <text class="menu-text">退出登录</text>
  232. <text class="arrow">›</text>
  233. </view>
  234. </view>
  235. </view>
  236. </template>
  237. <AIFloatingAvatar />
  238. </view>
  239. </template>
  240. <script>
  241. import AIFloatingAvatar from '../../components/AIFloatingAvatar.vue'
  242. import {
  243. getChildren, getVisibleFamilyMembers,
  244. getTodayTasksByCategory, getChallengeList, getMyMembership,
  245. verifyPassword, getPointsBalance, getUserInfo,
  246. cartCount, getOrderCounts, getCommissionSummary, getReferralSummary
  247. } from '../../utils/api.js'
  248. export default {
  249. components: { AIFloatingAvatar },
  250. data() {
  251. return {
  252. nickname: '',
  253. role: 'parent',
  254. isSwitchedChild: false,
  255. userInfo: {},
  256. memberLevel: null,
  257. membershipDays: 0,
  258. totalPoints: 0,
  259. pendingTasks: 0,
  260. streakDays: 0,
  261. familyCount: 0,
  262. activeChallenges: 0,
  263. profileProgress: 0,
  264. // 商城
  265. cartCount: 0,
  266. orderPending: 0,
  267. orderUnpaid: 0,
  268. orderShipped: 0,
  269. orderAfterSale: 0,
  270. // 推广中心
  271. commissionBalance: 0,
  272. referralCount: 0,
  273. teamCount: 0
  274. }
  275. },
  276. computed: {
  277. isLoggedIn() {
  278. return !!uni.getStorageSync('token')
  279. },
  280. roleLabel() {
  281. var map = { parent: '家长', child: '孩子', teacher: '规划师' }
  282. return map[this.role] || '用户'
  283. },
  284. memberLevelText() {
  285. var map = { FREE: '免费用户', FAMILY: '家庭会员', PREMIUM: '高级会员', LIFETIME: '终身会员' }
  286. return map[this.memberLevel] || this.memberLevel || ''
  287. },
  288. isLifetime() {
  289. return this.memberLevel === 'LIFETIME'
  290. },
  291. // 有升级空间:FREE(开通) / FAMILY(升PREMIUM);PREMIUM已是最高可购买等级,LIFETIME永久有效
  292. hasUpgradeSpace() {
  293. return this.memberLevel === 'FREE' || this.memberLevel === 'FAMILY'
  294. },
  295. upgradeBtnText() {
  296. return this.memberLevel === 'FAMILY' ? '升级' : '立即开通'
  297. },
  298. hasReminders() {
  299. return this.pendingTasks > 0 || this.activeChallenges > 0 || this.profileProgress < 14
  300. }
  301. },
  302. onShow() {
  303. if (!this.isLoggedIn) {
  304. // 未登录:不调用任何需登录接口,仅显示登录引导
  305. return
  306. }
  307. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  308. if (role === 'teacher') {
  309. uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
  310. return
  311. }
  312. this.role = role
  313. this.isSwitchedChild = uni.getStorageSync('isSwitchedChild') || false
  314. this.nickname = (uni.getStorageSync('userInfo') || {}).nickname || ''
  315. this.loadAllData()
  316. },
  317. methods: {
  318. loadAllData() {
  319. this.loadUserInfo()
  320. this.loadMembership()
  321. this.loadPoints()
  322. this.loadFamily()
  323. this.loadTasks()
  324. this.loadChallenges()
  325. this.loadOrderCounts()
  326. this.loadCartCount()
  327. this.loadPromotion()
  328. },
  329. loadUserInfo() {
  330. var self = this
  331. getUserInfo().then(function(res) {
  332. if (res && res.code === 200 && res.data) {
  333. self.userInfo = res.data
  334. if (!self.nickname) self.nickname = res.data.nickname || ''
  335. // 个人信息完整度:统计 14 个字段(与 user-edit.vue 表单一致)
  336. var d = res.data
  337. var fields = [
  338. d.avatar, d.nickname, d.realName, d.gender, d.idCard,
  339. d.birthday, d.birthHour, d.ethnicity, d.bloodType,
  340. d.highestEducation, d.maritalStatus, d.hobbies, d.dietPreferences,
  341. d.address
  342. ]
  343. var count = 0
  344. fields.forEach(function(v) {
  345. if (v !== undefined && v !== null && String(v).trim() !== '') {
  346. count += 1
  347. }
  348. })
  349. self.profileProgress = count
  350. }
  351. }).catch(function() {})
  352. },
  353. loadMembership() {
  354. var self = this
  355. getMyMembership().then(function(res) {
  356. if (res && res.data) {
  357. self.memberLevel = res.data.memberLevel || res.data.levelCode || null
  358. self.membershipDays = res.data.membershipDays || res.data.daysRemaining || 0
  359. }
  360. }).catch(function() {})
  361. },
  362. loadPoints() {
  363. var self = this
  364. var memberId = uni.getStorageSync('currentChildId') || uni.getStorageSync('userId')
  365. if (!memberId) return
  366. getPointsBalance(memberId).then(function(res) {
  367. if (res && res.data) {
  368. self.totalPoints = res.data.totalPoints || res.data.points || 0
  369. }
  370. }).catch(function() {})
  371. },
  372. loadFamily() {
  373. var self = this
  374. var childrenRes = getChildren()
  375. var membersRes = getVisibleFamilyMembers()
  376. Promise.all([childrenRes, membersRes]).then(function(results) {
  377. var children = results[0].data || []
  378. var members = results[1].data || []
  379. self.familyCount = members.length || children.length
  380. self.streakDays = parseInt(uni.getStorageSync('streakDays') || 0)
  381. }).catch(function() {
  382. self.familyCount = 0
  383. })
  384. },
  385. loadTasks() {
  386. var self = this
  387. var memberId = uni.getStorageSync('currentChildId') || uni.getStorageSync('userId')
  388. if (!memberId) return
  389. if (self.role === 'child' && memberId) {
  390. getTodayTasksByCategory(memberId, 'action').then(function(res) {
  391. if (res && res.data) {
  392. self.pendingTasks = Array.isArray(res.data) ? res.data.length : 0
  393. }
  394. }).catch(function() {})
  395. }
  396. self.pendingTasks = parseInt(uni.getStorageSync('pendingTaskCount') || 0)
  397. },
  398. loadChallenges() {
  399. var self = this
  400. getChallengeList({}).then(function(res) {
  401. if (res && res.data) {
  402. self.activeChallenges = Array.isArray(res.data) ? res.data.length : 0
  403. }
  404. }).catch(function() {})
  405. },
  406. loadOrderCounts() {
  407. var self = this
  408. getOrderCounts().then(function(res) {
  409. if (res && res.data) {
  410. self.orderPending = res.data.pending || 0
  411. self.orderUnpaid = res.data.unpaid || res.data.paid || 0
  412. self.orderShipped = res.data.shipped || 0
  413. self.orderAfterSale = res.data.refunding || res.data.afterSale || 0
  414. }
  415. }).catch(function() {})
  416. },
  417. loadCartCount() {
  418. var self = this
  419. cartCount().then(function(res) {
  420. if (res && res.data != null) {
  421. self.cartCount = res.data || 0
  422. }
  423. }).catch(function() {})
  424. },
  425. loadPromotion() {
  426. var self = this
  427. getCommissionSummary().then(function(res) {
  428. if (res && res.data) {
  429. self.commissionBalance = res.data.availableAmount || res.data.balance || 0
  430. }
  431. }).catch(function() {})
  432. getReferralSummary().then(function(res) {
  433. if (res && res.data) {
  434. self.referralCount = res.data.totalCount || res.data.count || 0
  435. }
  436. }).catch(function() {})
  437. },
  438. getDimColor: function(code) {
  439. var map = {
  440. body: '#FF8C42', mind: '#FF6B9D', wisdom: '#6366F1',
  441. action: '#10B981', wealth: '#F59E0B'
  442. }
  443. return map[code] || '#999'
  444. },
  445. goLogin: function() {
  446. uni.navigateTo({ url: '/pages/login/login' })
  447. },
  448. goSkip: function() {
  449. uni.switchTab({ url: '/pages/index-home/index' })
  450. },
  451. goToEditInfo: function() {
  452. uni.navigateTo({ url: '/pages/user-edit/user-edit' })
  453. },
  454. goToPoints: function() {
  455. uni.navigateTo({ url: '/pages/points/points' })
  456. },
  457. goToTasks: function() {
  458. uni.navigateTo({ url: '/pages/tasks/tasks' })
  459. },
  460. goToCheckin: function() {
  461. uni.navigateTo({ url: '/pages/health/daily-checkin' })
  462. },
  463. goToFamily: function() {
  464. uni.navigateTo({ url: '/pages/profile-extra/family-members' })
  465. },
  466. goToChildren: function() {
  467. uni.navigateTo({ url: '/pages/profile-extra/children' })
  468. },
  469. goToAppointments: function() {
  470. uni.navigateTo({ url: '/pages/parent/appointments' })
  471. },
  472. goToChallenges: function() {
  473. uni.navigateTo({ url: '/pages/health/challenge-manage' })
  474. },
  475. goToGrowth: function() {
  476. uni.navigateTo({ url: '/pages/growth-main/index' })
  477. },
  478. goToReport: function() {
  479. uni.navigateTo({ url: '/pages/profile/report-management' })
  480. },
  481. goToMembership: function() {
  482. uni.navigateTo({ url: '/pages/membership/index' })
  483. },
  484. goUpgrade: function() {
  485. uni.navigateTo({ url: '/pages/membership/upgrade' })
  486. },
  487. goToPromotion: function() {
  488. uni.navigateTo({ url: '/pages/promotion/index' })
  489. },
  490. goToCart: function() {
  491. uni.navigateTo({ url: '/pages/shop/cart/cart' })
  492. },
  493. goToOrders: function() {
  494. uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
  495. },
  496. goToCoupons: function() {
  497. uni.navigateTo({ url: '/pages/profile-extra/coupons' })
  498. },
  499. goToSettings: function() {
  500. uni.showActionSheet({
  501. itemList: ['设置密码', '隐私设置', '关于浠艾福'],
  502. success: function(res) {
  503. if (res.tapIndex === 0) {
  504. uni.navigateTo({ url: '/pages/profile/settings' })
  505. }
  506. }
  507. })
  508. },
  509. onSwitchMode: function() {
  510. var self = this
  511. if (self.role === 'child') {
  512. uni.showModal({
  513. title: '验证密码',
  514. content: '请输入家长密码',
  515. editable: true,
  516. success: function(res) {
  517. if (res.confirm && res.content) {
  518. verifyPassword(res.content).then(function(result) {
  519. if (result.code === 200) {
  520. self.doSwitchMode()
  521. } else {
  522. uni.showToast({ title: '密码错误', icon: 'none' })
  523. }
  524. }).catch(function() {
  525. uni.showToast({ title: '验证失败', icon: 'none' })
  526. })
  527. }
  528. }
  529. })
  530. } else {
  531. this.doSwitchMode()
  532. }
  533. },
  534. doSwitchMode: function() {
  535. var self = this
  536. getChildren().then(function(res) {
  537. var children = res.data || []
  538. if (children.length === 0) {
  539. uni.showModal({
  540. title: '提示',
  541. content: '您还没有添加孩子,请先在家庭成员中添加',
  542. success: function(r) { if (r.confirm) uni.navigateTo({ url: '/pages/profile-extra/family-members' }) }
  543. })
  544. return
  545. }
  546. if (children.length === 1) {
  547. self.$store.commit('switchToChild', children[0].id)
  548. self.role = 'child'
  549. self.isSwitchedChild = true
  550. uni.showToast({ title: '已切换为孩子模式', icon: 'success' })
  551. return
  552. }
  553. uni.showActionSheet({
  554. itemList: children.map(function(c) { return c.nickname }),
  555. success: function(res) {
  556. var sel = children[res.tapIndex]
  557. self.$store.commit('switchToChild', sel.id)
  558. self.role = 'child'
  559. self.isSwitchedChild = true
  560. uni.showToast({ title: '已切换为' + sel.nickname + '模式', icon: 'success' })
  561. }
  562. })
  563. }).catch(function() {})
  564. },
  565. onExitSwitch: function() {
  566. var self = this
  567. uni.showModal({
  568. title: '退出切换',
  569. content: '请输入家长密码以确认退出',
  570. editable: true,
  571. success: function(res) {
  572. if (res.confirm && res.content) {
  573. verifyPassword(res.content).then(function(result) {
  574. if (result.code === 200) {
  575. self.$store.commit('switchBackToParent')
  576. self.isSwitchedChild = false
  577. self.role = 'parent'
  578. uni.showToast({ title: '已退出切换', icon: 'success' })
  579. uni.reLaunch({ url: '/pages/index-home/index' })
  580. } else {
  581. uni.showToast({ title: '密码错误', icon: 'none' })
  582. }
  583. }).catch(function() {
  584. uni.showToast({ title: '验证失败', icon: 'none' })
  585. })
  586. }
  587. }
  588. })
  589. },
  590. showInviteActionSheet: function() {
  591. var self = this
  592. var ui = uni.getStorageSync('userInfo') || {}
  593. var items = ['👨‍👩‍👧‍👦 邀请家人', '👨‍🏫 邀请成长规划师']
  594. uni.showActionSheet({
  595. itemList: items,
  596. success: function(res) {
  597. var type = res.tapIndex === 0 ? 'family' : 'guide'
  598. var title = (ui.nickname || '家人') + ' 邀请你加入家庭'
  599. var path = type === 'guide'
  600. ? '/pages/login/login?invite_type=guide'
  601. : '/pages/login/login?invite_type=family'
  602. self.$emit('invite-generate', { title: title, path: path, imageUrl: '/static/invite-card.png' })
  603. uni.showToast({ title: '点击右上角转发', icon: 'none' })
  604. }
  605. })
  606. },
  607. logout: function() {
  608. uni.showModal({
  609. title: '确认退出',
  610. content: '确定要退出登录吗?',
  611. success: function(res) {
  612. if (res.confirm) {
  613. this.$store.commit('logout')
  614. uni.reLaunch({ url: '/pages/index-home/index' })
  615. }
  616. }.bind(this)
  617. })
  618. }
  619. }
  620. }
  621. </script>
  622. <style scoped>
  623. .container {
  624. min-height: 100vh;
  625. background: #f5f7fa;
  626. padding-bottom: 120rpx;
  627. }
  628. /* 登录 */
  629. .login-prompt {
  630. display: flex;
  631. flex-direction: column;
  632. align-items: center;
  633. padding: 200rpx 60rpx;
  634. }
  635. .prompt-icon { font-size: 100rpx; margin-bottom: 30rpx; }
  636. .prompt-title { font-size: 40rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; }
  637. .prompt-desc { font-size: 26rpx; color: #999; margin-bottom: 20rpx; }
  638. .login-btn {
  639. background: linear-gradient(135deg, #667eea, #764ba2);
  640. color: #fff;
  641. border-radius: 50rpx;
  642. font-size: 30rpx;
  643. padding: 24rpx 80rpx;
  644. }
  645. .skip-link {
  646. font-size: 26rpx;
  647. color: #999;
  648. margin-top: 24rpx;
  649. text-decoration: underline;
  650. }
  651. /* 退出切换 */
  652. .exit-switch {
  653. margin: 0 30rpx 16rpx;
  654. background: linear-gradient(135deg, #667eea, #764ba2);
  655. color: #fff;
  656. padding: 16rpx;
  657. border-radius: 12rpx;
  658. text-align: center;
  659. font-size: 26rpx;
  660. }
  661. /* 用户卡片 */
  662. .user-card {
  663. margin: 30rpx;
  664. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  665. border-radius: 24rpx;
  666. padding: 36rpx 32rpx;
  667. display: flex;
  668. justify-content: space-between;
  669. align-items: center;
  670. box-shadow: 0 8rpx 32rpx rgba(102,126,234,0.3);
  671. }
  672. .user-card-left {
  673. display: flex;
  674. align-items: center;
  675. flex: 1;
  676. }
  677. .avatar-wrap {
  678. width: 110rpx;
  679. height: 110rpx;
  680. border-radius: 50%;
  681. background: rgba(255,255,255,0.2);
  682. display: flex;
  683. align-items: center;
  684. justify-content: center;
  685. margin-right: 24rpx;
  686. overflow: hidden;
  687. border: 4rpx solid rgba(255,255,255,0.3);
  688. }
  689. .avatar-img {
  690. width: 110rpx;
  691. height: 110rpx;
  692. border-radius: 50%;
  693. }
  694. .avatar-text {
  695. font-size: 48rpx;
  696. color: #fff;
  697. }
  698. .user-meta { flex: 1; }
  699. .user-name-row {
  700. display: flex;
  701. align-items: center;
  702. gap: 12rpx;
  703. margin-bottom: 8rpx;
  704. }
  705. .nickname {
  706. font-size: 36rpx;
  707. font-weight: bold;
  708. color: #fff;
  709. }
  710. .role-tag {
  711. font-size: 22rpx;
  712. background: rgba(255,255,255,0.2);
  713. color: #fff;
  714. padding: 4rpx 16rpx;
  715. border-radius: 20rpx;
  716. }
  717. .user-sub {
  718. display: flex;
  719. align-items: center;
  720. gap: 12rpx;
  721. }
  722. .level-badge {
  723. font-size: 24rpx;
  724. padding: 8rpx 22rpx;
  725. border-radius: 24rpx;
  726. font-weight: bold;
  727. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.2);
  728. border: 2rpx solid rgba(255,255,255,0.35);
  729. display: flex;
  730. align-items: center;
  731. gap: 6rpx;
  732. box-sizing: border-box;
  733. height: 44rpx;
  734. }
  735. .level-badge::before {
  736. content: '👑';
  737. font-size: 20rpx;
  738. }
  739. .level-FREE { background: linear-gradient(135deg, #9CA3AF, #6B7280); color: #fff; }
  740. .level-FREE::before { content: ''; }
  741. .level-FAMILY { background: linear-gradient(135deg, #F59E0B, #D97706); color: #fff; }
  742. .level-PREMIUM { background: linear-gradient(135deg, #6366F1, #4F46E5); color: #fff; }
  743. .level-LIFETIME {
  744. background: linear-gradient(135deg, #EC4899, #DB2777);
  745. color: #fff;
  746. box-shadow: 0 4rpx 16rpx rgba(236,72,153,0.45);
  747. border-color: rgba(255,255,255,0.55);
  748. }
  749. .days-left {
  750. font-size: 22rpx;
  751. color: rgba(255,255,255,0.85);
  752. }
  753. .upgrade-btn {
  754. background: rgba(255,255,255,0.22);
  755. border: 2rpx solid rgba(255,255,255,0.6);
  756. border-radius: 22rpx;
  757. padding: 8rpx 24rpx;
  758. flex-shrink: 0;
  759. box-sizing: border-box;
  760. height: 44rpx;
  761. display: flex;
  762. align-items: center;
  763. }
  764. .upgrade-btn-text {
  765. font-size: 22rpx;
  766. font-weight: bold;
  767. color: #fff;
  768. line-height: 1;
  769. }
  770. .user-card-right {
  771. display: flex;
  772. flex-direction: column;
  773. align-items: center;
  774. gap: 16rpx;
  775. }
  776. .points-box {
  777. text-align: center;
  778. background: rgba(255,255,255,0.15);
  779. padding: 16rpx 24rpx;
  780. border-radius: 16rpx;
  781. }
  782. /* 数据概览 */
  783. .stats-bar {
  784. margin: 0 30rpx 20rpx;
  785. background: #fff;
  786. border-radius: 20rpx;
  787. display: flex;
  788. align-items: center;
  789. padding: 28rpx 0;
  790. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  791. }
  792. .stat-item {
  793. flex: 1;
  794. display: flex;
  795. flex-direction: column;
  796. align-items: center;
  797. gap: 8rpx;
  798. }
  799. .stat-num {
  800. font-size: 40rpx;
  801. font-weight: bold;
  802. color: #667eea;
  803. }
  804. .stat-label {
  805. font-size: 24rpx;
  806. color: #999;
  807. }
  808. .stat-divider {
  809. width: 1rpx;
  810. height: 60rpx;
  811. background: #f0f0f0;
  812. }
  813. /* 待办提醒 */
  814. .reminders-section {
  815. margin: 0 30rpx 20rpx;
  816. }
  817. .reminder-item {
  818. background: #fff;
  819. border-radius: 16rpx;
  820. padding: 24rpx 28rpx;
  821. margin-bottom: 12rpx;
  822. display: flex;
  823. align-items: center;
  824. gap: 16rpx;
  825. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  826. }
  827. .reminder-icon { font-size: 36rpx; }
  828. .reminder-text { flex: 1; font-size: 28rpx; color: #333; }
  829. .reminder-arrow { font-size: 32rpx; color: #ccc; }
  830. /* 菜单 */
  831. .menu-section {
  832. margin: 0 30rpx;
  833. }
  834. .menu-group {
  835. background: #fff;
  836. border-radius: 20rpx;
  837. margin-bottom: 20rpx;
  838. overflow: hidden;
  839. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  840. }
  841. .menu-group-title {
  842. padding: 16rpx 28rpx 8rpx;
  843. font-size: 22rpx;
  844. color: #999;
  845. }
  846. .menu-item {
  847. display: flex;
  848. align-items: center;
  849. padding: 26rpx 28rpx;
  850. border-bottom: 1rpx solid #f5f5f5;
  851. }
  852. .menu-item:last-child { border-bottom: none; }
  853. .menu-icon { font-size: 36rpx; margin-right: 16rpx; }
  854. .menu-text { flex: 1; font-size: 28rpx; color: #333; }
  855. .arrow { font-size: 32rpx; color: #ccc; }
  856. .badge {
  857. background: #FF4D4F;
  858. color: #fff;
  859. font-size: 22rpx;
  860. padding: 2rpx 12rpx;
  861. border-radius: 20rpx;
  862. margin-right: 12rpx;
  863. min-width: 36rpx;
  864. text-align: center;
  865. }
  866. .mall-section {
  867. margin: 0 30rpx 20rpx;
  868. background: #fff;
  869. border-radius: 20rpx;
  870. overflow: hidden;
  871. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  872. }
  873. .mall-header {
  874. display: flex;
  875. justify-content: space-between;
  876. align-items: center;
  877. padding: 24rpx 28rpx 16rpx;
  878. border-bottom: 1rpx solid #f5f5f5;
  879. }
  880. .mall-title { font-size: 30rpx; font-weight: bold; color: #333; }
  881. .mall-more { font-size: 24rpx; color: #999; }
  882. .mall-grid { display: flex; padding: 20rpx 16rpx; }
  883. .mall-item {
  884. flex: 1;
  885. display: flex;
  886. flex-direction: column;
  887. align-items: center;
  888. gap: 8rpx;
  889. padding: 16rpx 0;
  890. }
  891. .mall-item-num { font-size: 36rpx; font-weight: bold; color: #F97316; }
  892. .mall-item-label { font-size: 22rpx; color: #999; }
  893. </style>