<template>
	<view class="page">
		<image class="bg" src="@/static/image/person-bg.png"></image>
		<view class="wrap">
			<view class="info">
				<image class="avatar" :src="avatar" mode=""></image>
				<view class="text">
					<view class="name">{{ my.info.userName }}</view>
					<view class="phone">{{ my.info.phone }}</view>
				</view>
			</view>
			<view class="list">
				<view v-if="auth('我的:我的收益')" class="item">
					<view class="left">
						<image class="icon" src="@/static/image/person1.png" mode=""></image>
						<text class="name">我的项目收益</text>
					</view>
					<text class="val">{{ my.myIncome}}元</text>
				</view>
				<view v-if="auth('我的:团队收益')" class="item">
					<view class="left">
						<image class="icon" src="@/static/image/person2.png" mode=""></image>
						<text class="name">团队收益</text>
					</view>
					<text class="val">{{ my.teamIncome}}元</text>
				</view>
				<view v-if="auth('我的:设置')" class="item" @click="$util.to('../setting/setting')">
					<view class="left">
						<image class="icon" src="@/static/image/person3.png" mode=""></image>
						<text class="name">设置</text>
					</view>
				</view>
				<view v-if="auth('我的:退出账号')" class="item" @click="logout">
					<view class="left">
						<image class="icon" src="@/static/image/person4.png" mode=""></image>
						<text class="name">退出账号</text>
					</view>
				</view>
			</view>
		</view>
		<view v-if="!per" class="per-mask">功能升级中，敬请期待...</view>
	</view>
</template>

<script>
	import { my } from '@/apis/modules/parner.js'
	export default {
		data() {
			return {
				per: true, // 是否有权限
				my: {
					info: {
						phone: ''
					},
					myIncome: 0,
					teamIncome: 0
				},
				avatar: uni.getStorageSync('avatar') || '@/static/image/avatar.png',
				userName: uni.getStorageSync('userName')
			}
		},
		onShow() {
			this.per = true
			this.initRole()
		},
		methods: {
			// 初始化权限
			initRole() {
				if (!uni.getStorageSync('auth').includes('我的')) {
					this.per = false
				} else {
					this.getInfo()
				}
			},
			// 获取个人信息
			getInfo() {
				const team = uni.getStorageSync('team')
				my({
					partnerId: team.partnerId,
					teamId: team.teamId
				}).then(({ my }) => {
					this.my = my
				}).catch(e => {})
			},
			// 退出登录
			logout() {
				const that = this
				uni.showModal({
					title: '提示',
					content: '确定要退出账号吗？',
					success(res) {
						if (res.confirm) {
							uni.clearStorageSync()
							that.$util.to('../login/login')
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.bg {
	width: 100%;
	height: 300rpx;
}
.wrap {
	position: relative;
	padding: 0 24rpx;
	margin-top: -150rpx;
}
.info {
	display: flex;
	align-items: center;
	padding: 26rpx 34rpx;
	background-color: #fff;
	border-radius: 16rpx;
	.avatar {
		width: 120rpx;
		height: 120rpx;
		margin-right: 28rpx;
		border-radius: 50%;
	}
	.name {
		margin-bottom: 10rpx;
		font-size: 40rpx;
		color: #333;
	}
	.phone {
		font-size: 28rpx;
		color: #333;
	}
}
.list {
	margin-top: 16rpx;
	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 26rpx 28rpx;
		margin-bottom: 16rpx;
		background-color: #fff;
		border-radius: 16rpx;
	}
	.left {
		display: inline-flex;
		align-items: center;
	}
	.icon {
		width: 48rpx;
		height: 48rpx;
		margin-right: 16rpx;
	}
	text {
		font-size: 28rpx;
		color: #333;
	}
}
</style>
