| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- <template>
- <view class="container">
- <!-- TabTransition overlay -->
- <tab-transition v-if="showTabTransition" dimCode="wealth" />
- <!-- 品牌头部(始终显示) -->
- <PageBanner theme="wealth"
- tagline="利他创富 · 价值共享"
- quote="富足源于利他与坚持" />
- <!-- 游客专属区块 -->
- <template v-if="!isLoggedIn">
- <LoginGuideCard
- title="登录后查看财富能量详情"
- :items="[
- '查看家庭财富能量与子维度评分',
- '查看专属财富商品和活动推荐',
- '查看创客中心和推广收益'
- ]" />
- </template>
- <!-- 登录后:五维能量条 -->
- <FamilyEnergyBar
- v-if="isLoggedIn"
- dimensionCode="wealth"
- :sandboxData="sandboxData"
- :dualDimension="dualDimension" />
- <!-- 退出切换按钮 -->
- <view class="exit-switch" v-if="isLoggedIn && isSwitchedChild" @click="exitSwitch">
- <text>🔄 退出切换</text>
- </view>
- <!-- 切换按钮(家长模式 + 未切换状态) -->
- <view class="switch-section" v-if="isLoggedIn && role === 'parent' && !isSwitchedChild">
- <button class="btn-switch" @click="onSwitchMode">切换到孩子视角</button>
- </view>
- <!-- 财富子维度卡片 -->
- <view class="section" v-if="isLoggedIn">
- <view class="section-header">
- <text class="section-title">💎 财富子维度</text>
- </view>
- <!-- 家长版 -->
- <view class="sub-dim-grid" v-if="role === 'parent'">
- <view class="sub-dim-card" @click="goToIncome">
- <text class="sub-dim-score">{{ wealthIncome || '-' }}</text>
- <text class="sub-dim-label">金钱收入</text>
- <text class="sub-dim-desc">累计佣金</text>
- </view>
- <view class="sub-dim-card" @click="goToAchievements">
- <text class="sub-dim-score">{{ wealthAchievement || '-' }}</text>
- <text class="sub-dim-label">个人成就</text>
- <text class="sub-dim-desc">认证成就</text>
- </view>
- <view class="sub-dim-card" @click="goToNetwork">
- <text class="sub-dim-score">{{ wealthNetwork || '-' }}</text>
- <text class="sub-dim-label">资源网络</text>
- <text class="sub-dim-desc">推荐关系</text>
- </view>
- </view>
- <!-- 孩子版 -->
- <view class="sub-dim-grid" v-else>
- <view class="sub-dim-card" @click="childSubDimClick('education')">
- <text class="sub-dim-score">{{ wealthEducation || '-' }}</text>
- <text class="sub-dim-label">学业成绩</text>
- <text class="sub-dim-desc">测评综合</text>
- </view>
- <view class="sub-dim-card" @click="childSubDimClick('social')">
- <text class="sub-dim-score">{{ wealthSocial || '-' }}</text>
- <text class="sub-dim-label">社交筹码</text>
- <text class="sub-dim-desc">活动参与</text>
- </view>
- <view class="sub-dim-card" @click="childSubDimClick('points')">
- <text class="sub-dim-score">{{ wealthPoints || '-' }}</text>
- <text class="sub-dim-label">规则博弈</text>
- <text class="sub-dim-desc">积分效率</text>
- </view>
- </view>
- </view>
- <!-- 财富数据(仅家长) -->
- <view class="section" v-if="isLoggedIn && role === 'parent'">
- <view class="section-header">
- <text class="section-title">💰 财富数据</text>
- </view>
- <view class="wealth-card">
- <view class="wealth-item">
- <text class="wealth-value">{{ wealthData.totalEarnings || 0 }}</text>
- <text class="wealth-label">累计收益</text>
- </view>
- <view class="wealth-divider"></view>
- <view class="wealth-item">
- <text class="wealth-value">{{ wealthData.availableAmount || 0 }}</text>
- <text class="wealth-label">可提现</text>
- </view>
- <view class="wealth-divider"></view>
- <view class="wealth-item">
- <text class="wealth-value">{{ wealthData.referralCount || 0 }}</text>
- <text class="wealth-label">邀请人数</text>
- </view>
- </view>
- <!-- 邀请码复制 -->
- <view class="referral-code-bar" v-if="wealthData.referralCode" @click="copyReferralCode">
- <text class="referral-code-label">我的邀请码</text>
- <text class="referral-code-value">{{ wealthData.referralCode }}</text>
- <text class="referral-code-copy">复制</text>
- </view>
- </view>
- <!-- 增值服务入口 -->
- <view class="section" v-if="isLoggedIn">
- <view class="section-header">
- <text class="section-title">🚀 增值服务</text>
- </view>
- <view class="service-grid">
- <view class="service-item" @click="goToCheckin">
- <text class="service-icon">📝</text>
- <text class="service-label">记账打卡</text>
- </view>
- <view class="service-item" @click="goToInsurancePlanning">
- <text class="service-icon">📊</text>
- <text class="service-label">保险规划</text>
- </view>
- <view class="service-item" @click="goToCreator">
- <text class="service-icon">🎨</text>
- <text class="service-label">创客中心</text>
- </view>
- <view class="service-item" @click="goToInsuranceList">
- <text class="service-icon">🛡️</text>
- <text class="service-label">保单管理</text>
- </view>
- </view>
- </view>
- <!-- 维度活动 -->
- <DimensionActivities
- dimensionCode="wealth"
- :activities="dimensionActivities"
- :isLoggedIn="isLoggedIn"
- @activityClick="goActivityDetail"
- @moreActivities="goMoreActivities" />
- <!-- 商品推荐 -->
- <DimensionProductList
- v-if="isLoggedIn"
- dimensionCode="wealth"
- :familyId="activeChildId"
- title="为你推荐" />
- <!-- 推荐阅读 -->
- <DimensionArticles
- dimensionCode="wealth"
- :articles="wealthArticles"
- :isLoggedIn="isLoggedIn"
- @articleClick="goArticleDetail"
- @moreArticles="goMoreArticles" />
- <!-- 底部占位 -->
- <view class="bottom-spacer"></view>
- <AIFloatingAvatar />
- </view>
- </template>
- <script>
- import TabTransition from '../../components/tab-transition.vue'
- import PageBanner from '../../components/PageBanner.vue'
- import DimensionProductList from '../../components/DimensionProductList.vue'
- import DimensionActivities from '../../components/DimensionActivities.vue'
- import DimensionArticles from '../../components/DimensionArticles.vue'
- import FamilyEnergyBar from '../../components/FamilyEnergyBar.vue'
- import LoginGuideCard from '../../components/LoginGuideCard.vue'
- import AIFloatingAvatar from '../../components/AIFloatingAvatar.vue'
- import {
- verifyPassword,
- getChildren,
- getWealthDetail,
- getReferralCode,
- getReferralSummary,
- getCommissionSummary,
- getFamilyEnergySandbox,
- getEnergyOverview,
- getActivityList,
- getFeaturedArticles
- } from '../../utils/api.js'
- export default {
- components: {
- TabTransition,
- PageBanner,
- DimensionProductList,
- DimensionActivities,
- DimensionArticles,
- FamilyEnergyBar,
- LoginGuideCard,
- AIFloatingAvatar
- },
- data() {
- return {
- showTabTransition: true,
- isLoggedIn: false,
- role: 'parent',
- isSwitchedChild: false,
- nickname: '',
- // 五维评分
- bodyScore: 0,
- mindScore: 0,
- wisdomScore: 0,
- actionScore: 0,
- wealthScore: 0,
- // 子维度 - parent
- wealthIncome: null,
- wealthAchievement: null,
- wealthNetwork: null,
- // 子维度 - child
- wealthEducation: null,
- wealthSocial: null,
- wealthPoints: null,
- // 财富数据
- wealthData: {
- totalEarnings: 0,
- availableAmount: 0,
- referralCount: 0,
- referralCode: ''
- },
- children: [],
- // 能量条相关
- sandboxData: null,
- dualDimension: null,
- // 维度活动和文章
- dimensionActivities: [],
- wealthArticles: []
- }
- },
- computed: {
- activeChildId() {
- if (this.role === 'child') {
- return uni.getStorageSync('currentChildId')
- }
- return ''
- }
- },
- onShow() {
- this.showTabTransition = true
- this.isLoggedIn = !!uni.getStorageSync('token')
- if (!this.isLoggedIn) {
- this._watchPageReady()
- return
- }
- var currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
- if (currentRole === 'teacher') {
- uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
- return
- }
- this.role = currentRole
- this.isSwitchedChild = uni.getStorageSync('isSwitchedChild') || false
- var userInfo = uni.getStorageSync('userInfo')
- this.nickname = (userInfo && userInfo.nickname) || ''
- this.loadChildren()
- this.loadWealthDetail()
- this.loadWealthData()
- this.loadSandboxData()
- // 游客也能浏览活动和文章
- this.loadDimensionActivities()
- this.loadFeaturedArticles()
- this._watchPageReady()
- },
- methods: {
- _watchPageReady() {
- var self = this
- this.$nextTick(function() {
- self.showTabTransition = false
- })
- setTimeout(function() {
- self.showTabTransition = false
- }, 2000)
- },
- async loadChildren() {
- try {
- var res = await getChildren()
- this.children = res.data || []
- } catch (e) {
- console.error('获取孩子列表失败', e)
- }
- },
- async loadWealthDetail() {
- var memberId = null
- var memberType = this.role
- if (this.role === 'child') {
- memberId = uni.getStorageSync('currentChildId')
- if (!memberId && this.children.length > 0) {
- memberId = this.children[0].id
- }
- } else {
- memberId = uni.getStorageSync('userId')
- }
- if (!memberId) return
- try {
- var res = await getWealthDetail(memberId, memberType)
- if (res && res.data) {
- var d = res.data
- this.wealthScore = d.wealthScore || 0
- if (memberType === 'parent') {
- this.wealthIncome = d.wealthIncome
- this.wealthAchievement = d.wealthAchievement
- this.wealthNetwork = d.wealthNetwork
- } else {
- this.wealthEducation = d.wealthEducation
- this.wealthSocial = d.wealthSocial
- this.wealthPoints = d.wealthPoints
- }
- }
- } catch (e) {
- console.error('获取富维度详情失败', e)
- }
- },
- async loadWealthData() {
- if (this.role !== 'parent') return
- try {
- var codeRes = await getReferralCode()
- if (codeRes && codeRes.code === 200 && codeRes.data) {
- this.wealthData.referralCode = codeRes.data.code || codeRes.data || ''
- }
- } catch (e) {
- console.error('获取邀请码失败', e)
- }
- try {
- var summaryRes = await getReferralSummary()
- if (summaryRes && summaryRes.code === 200 && summaryRes.data) {
- this.wealthData.referralCount = summaryRes.data.totalCount || summaryRes.data.count || 0
- }
- } catch (e) {
- console.error('获取邀请统计失败', e)
- }
- try {
- var commissionRes = await getCommissionSummary()
- if (commissionRes && commissionRes.code === 200 && commissionRes.data) {
- this.wealthData.totalEarnings = commissionRes.data.totalEarnings || 0
- this.wealthData.availableAmount = commissionRes.data.availableAmount || 0
- }
- } catch (e) {
- console.error('获取佣金统计失败', e)
- }
- },
- loadSandboxData() {
- var self = this
- getFamilyEnergySandbox().then(function(res) {
- if (res && res.data) {
- self.sandboxData = res.data
- }
- }).catch(function(e) {
- console.log('获取沙盘数据失败', e)
- })
- // 加载双维度(财富与关系)
- var childId = this.activeChildId
- if (childId) {
- getEnergyOverview(childId).then(function(res) {
- if (res && res.data && res.data.dimensions) {
- var dims = res.data.dimensions
- for (var i = 0; i < dims.length; i++) {
- if (dims[i].code === 'wealth') {
- self.dualDimension = dims[i]
- break
- }
- }
- }
- }).catch(function(e) {
- console.log('获取能量概览失败', e)
- })
- }
- },
- loadDimensionActivities() {
- var self = this
- getActivityList({ dimensionCode: 'wealth', page: 1, size: 3 }).then(function(res) {
- if (res && res.data) {
- var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
- self.dimensionActivities = list.slice(0, 3)
- }
- }).catch(function() { self.dimensionActivities = [] })
- },
- loadFeaturedArticles() {
- var self = this
- getFeaturedArticles({ size: 5 }).then(function(res) {
- if (res && res.code === 200 && res.data) {
- var gradientColors = [
- 'linear-gradient(135deg, #F59E0B, #FBBF24)',
- 'linear-gradient(135deg, #42A5F5, #64B5F6)',
- 'linear-gradient(135deg, #FF8C42, #FFB074)',
- 'linear-gradient(135deg, #FF6B9D, #FF9DBD)',
- 'linear-gradient(135deg, #6366F1, #818CF8)'
- ]
- var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
- self.wealthArticles = list.map(function(item, index) {
- return {
- id: item.id,
- category: item.categoryName || '财富创富',
- categoryColor: gradientColors[index % gradientColors.length],
- title: item.title || '',
- summary: item.summary || '',
- dimensionWeights: item.dimensionWeights || null,
- views: item.viewCount ? String(item.viewCount) : '0',
- date: item.publishedAt ? item.publishedAt.slice(0, 10) : ''
- }
- })
- }
- }).catch(function() {})
- },
- copyReferralCode() {
- if (!this.wealthData.referralCode) return
- uni.setClipboardData({
- data: this.wealthData.referralCode,
- success: function() {
- uni.showToast({ title: '邀请码已复制', icon: 'success' })
- }
- })
- },
- onSwitchMode() {
- if (this.role === 'child') {
- this.exitSwitch()
- return
- }
- // parent → switch to child
- if (this.children.length === 0) {
- this.loadChildren()
- if (this.children.length === 0) {
- uni.showModal({
- title: '提示',
- content: '您还没有添加孩子,是否现在去添加?',
- success: function(res) {
- if (res.confirm) {
- uni.navigateTo({ url: '/pages/profile-extra/create-child' })
- }
- }
- })
- return
- }
- }
- if (this.children.length === 1) {
- this.$store.commit('switchToChild', this.children[0].id)
- this.role = 'child'
- this.isSwitchedChild = true
- uni.showToast({ title: '已切换为孩子模式', icon: 'success' })
- return
- }
- var self = this
- uni.showActionSheet({
- itemList: this.children.map(function(c) { return c.nickname }),
- success: function(res) {
- var selectedChild = self.children[res.tapIndex]
- self.$store.commit('switchToChild', selectedChild.id)
- self.role = 'child'
- self.isSwitchedChild = true
- uni.showToast({ title: '已切换为' + selectedChild.nickname + '模式', icon: 'success' })
- }
- })
- },
- exitSwitch() {
- if (!this.isSwitchedChild) return
- var self = this
- uni.showModal({
- title: '退出切换',
- content: '请输入家长密码以确认退出',
- editable: true,
- success: function(res) {
- if (res.confirm && res.content) {
- verifyPassword(res.content).then(function(result) {
- if (result.code === 200) {
- uni.removeStorageSync('isSwitchedChild')
- uni.removeStorageSync('currentChildId')
- self.isSwitchedChild = false
- self.role = 'parent'
- if (self.$store && self.$store.commit) {
- self.$store.commit('switchBackToParent')
- }
- uni.showToast({ title: '已退出切换', icon: 'success' })
- setTimeout(function() {
- uni.reLaunch({ url: '/pages/index/index' })
- }, 1000)
- } else {
- uni.showToast({ title: '密码错误', icon: 'none' })
- }
- }).catch(function() {
- uni.showToast({ title: '验证失败', icon: 'none' })
- })
- }
- }
- })
- },
- goToCheckin() {
- uni.navigateTo({ url: '/pages/wealth-sub/checkin' })
- },
- goToInsurancePlanning() {
- uni.navigateTo({ url: '/pages/wealth-sub/insurance-planning' })
- },
- goToInsuranceList() {
- uni.navigateTo({ url: '/pages/wealth-sub/insurance-list' })
- },
- goToCreator() {
- uni.navigateTo({ url: '/pages/promotion/index' })
- },
- goToIncome() {
- uni.navigateTo({ url: '/pages/promotion/commission' })
- },
- goToAchievements() {
- uni.navigateTo({ url: '/pages/rewards/badge' })
- },
- goToNetwork() {
- uni.navigateTo({ url: '/pages/promotion/team' })
- },
- childSubDimClick(key) {
- var routes = {
- education: '/pages/assessment/results',
- social: '/pages/activity/index',
- points: '/pages/points/mall'
- }
- var url = routes[key]
- if (url) {
- uni.navigateTo({ url: url })
- }
- },
- goActivityDetail(act) {
- if (!act || !act.id) return
- uni.navigateTo({ url: '/pages/discover-detail/activity-detail/activity-detail?id=' + act.id })
- },
- goMoreActivities() {
- uni.navigateTo({ url: '/pages/activity/index' })
- },
- goArticleDetail(article) {
- var id = article.id || article
- uni.navigateTo({ url: '/pages/mind-detail/article-detail?id=' + id })
- },
- goMoreArticles() {
- uni.navigateTo({ url: '/pages/article-center/index?dimension=wealth' })
- }
- }
- }
- </script>
- <style scoped>
- .container {
- min-height: 100vh;
- background: #f5f7fa;
- padding-bottom: 120rpx;
- }
- .section {
- margin: 20rpx 30rpx;
- }
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- .section-more {
- font-size: 24rpx;
- color: #999;
- }
- /* 切换区域 */
- .switch-section {
- margin: 0 30rpx 20rpx;
- }
- .btn-switch {
- background: linear-gradient(135deg, #F59E0B, #FBBF24);
- color: #fff;
- font-size: 26rpx;
- padding: 16rpx 0;
- border-radius: 40rpx;
- text-align: center;
- line-height: 1.5;
- }
- /* 财富数据卡片 */
- .wealth-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 30rpx 20rpx;
- display: flex;
- align-items: center;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .wealth-item {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .wealth-value {
- font-size: 40rpx;
- font-weight: bold;
- color: #F97316;
- }
- .wealth-label {
- font-size: 24rpx;
- color: #999;
- margin-top: 8rpx;
- }
- .wealth-divider {
- width: 1rpx;
- height: 60rpx;
- background: #f0f0f0;
- }
- /* 邀请码复制条 */
- .referral-code-bar {
- display: flex;
- align-items: center;
- background: #fff;
- margin-top: 16rpx;
- border-radius: 16rpx;
- padding: 24rpx 30rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .referral-code-label {
- font-size: 26rpx;
- color: #666;
- margin-right: 16rpx;
- }
- .referral-code-value {
- flex: 1;
- font-size: 30rpx;
- font-weight: bold;
- color: #F59E0B;
- letter-spacing: 2rpx;
- }
- .referral-code-copy {
- font-size: 24rpx;
- color: #fff;
- background: linear-gradient(135deg, #F59E0B, #FBBF24);
- padding: 8rpx 24rpx;
- border-radius: 20rpx;
- }
- /* 三子维度卡片 */
- .sub-dim-grid {
- display: flex;
- }
- .sub-dim-card {
- flex: 1;
- margin-right: 16rpx;
- background: #fff;
- border-radius: 16rpx;
- padding: 24rpx 16rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .sub-dim-card:last-child {
- margin-right: 0;
- }
- .sub-dim-score {
- font-size: 48rpx;
- font-weight: bold;
- color: #F59E0B;
- }
- .sub-dim-label {
- font-size: 24rpx;
- color: #333;
- margin-top: 8rpx;
- font-weight: 500;
- }
- .sub-dim-desc {
- font-size: 20rpx;
- color: #999;
- margin-top: 4rpx;
- }
- /* 增值服务 */
- .service-grid {
- display: flex;
- flex-wrap: wrap;
- background: #fff;
- border-radius: 20rpx;
- padding: 24rpx 16rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .service-item {
- width: 33.33%;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 16rpx 0;
- }
- .service-icon {
- font-size: 48rpx;
- margin-bottom: 8rpx;
- }
- .service-label {
- font-size: 22rpx;
- color: #666;
- }
- /* 退出切换 */
- .exit-switch {
- margin: 20rpx 30rpx 0;
- padding: 16rpx 24rpx;
- background: #FEF3C7;
- border-radius: 12rpx;
- text-align: center;
- font-size: 26rpx;
- color: #92400E;
- }
- /* 底部占位 */
- .bottom-spacer {
- height: 120rpx;
- }
- </style>
|