<template>
	<view class="tabPage" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='我的' bgColor="transparent" :showback="false"></cus-header>
		<image class="topbg" :src="imgBase+'my_topbg.png'" mode="widthFix"></image>
		<view class="box">
			<view class="top adfacjb">
				<view class="top-left adfac">
					<view class="top-left-img">
						<image :src="userInfo.headUrl||(imgBase+'my_avatar.png')"></image>
					</view>
					<view class="top-left-info">
						<view class="top-left-info-name">{{userInfo.realName||'未登录'}}</view>
						<view class="top-left-info-tip" v-if="!userInfo.id" @click="handleLogin">点击立即登录</view>
						<view class="top-left-info-version" v-else>{{typeCfg[headData.type]||'基础版'}}</view>
					</view>
				</view>
				<view class="top-right">
					<image :src="imgBase+'my_set.png'" @click="handleTurn('/pagesMy/userSet')"></image>
				</view>
			</view>
			<view class="num adf">
				<view class="num-pre adffcac">
					<view class="num-pre-sz">{{headData.basicCount||0}}</view>
					<view class="num-pre-text">基础版次数</view>
				</view>
				<view class="num-pre adffcac">
					<view class="num-pre-sz">{{headData.proCount||0}}</view>
					<view class="num-pre-text">专业版次数</view>
				</view>
				<view class="num-pre adffcac">
					<view class="num-pre-sz">{{headData.teamCount||0}}</view>
					<view class="num-pre-text">我的团队</view>
				</view>
			</view>
			<view class="preill adfacjb">
				<view class="preill-left">深入了解支撑高价值团队的关键因素</view>
				<view class="preill-right" @click="handleTurn('/pagesPublish/rechargeCenter')">立即购买</view>
			</view>
			<view class="menu">
				<view class="menu-item adfacjb" v-for="(item,index) in menuList" :key="index" @click="handleTurn(item.path)">
					<view class="menu-item-left adfac">
						<image :src="item.img"></image>
						<text>{{item.title}}</text>
					</view>
					<image class="menu-item-right" :src="imgBase+'my_arrow_right.png'"></image>
				</view>
			</view>
		</view>
		<Tabbar :tabbarIndex="2"></Tabbar>
	</view>
</template>

<script>
	import Tabbar from '@/components/CusTabbar/index.vue'
	export default {
		components:{ Tabbar },
		data(){
			return {
				userInfo:{
					avatar:this.$imgBase+'my_avatar.png',
					name:''
				},
				headData:null,
				typeCfg:{
					1:'基础版',
					2:'专业版',
					3:'专家版',
				},
				menuList:[
					{
						img:this.$imgBase+'my_order.png',
						title:'我的订单',
						path:'/pagesMy/order'
					},
					{
						img:this.$imgBase+'my_record.png',
						title:'推荐记录',
						path:'/pagesMy/recommendHistory'
					},
					{
						img:this.$imgBase+'my_program.png',
						title:'我的团队',
						path:'/pagesMy/team'
					},
					{
						img:this.$imgBase+'my_teamusers.png',
						title:'团队成员',
						path:'/pagesMy/teamUser'
					},
					{
						img:this.$imgBase+'my_friends.png',
						title:'邀请好友',
						path:''
					}
				]
			}
		},
		onLoad(options) {
			if(uni.getStorageSync('userInfo')){
				this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
				this.getMyInfo(this.userInfo.id)
			} 
		},
		methods:{
			getMyInfo(userId){
				this.$api.get(`/wx/myCount/${userId}`,this.params).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.headData = res.data;
				})
			},
			handleLogin(){
				uni.reLaunch({
					url:'/pages/login'
				})
			},
			handleTurn(url){
				if(!this.isLogin()) return
				if(!url) return
				uni.navigateTo({ url })
			},
		}
	}
</script>

<style scoped lang="scss">
	.tabPage{
		.topbg{
			width: 100%;
			position: absolute;
			left: 0;
			top: 0;
		}
		
		.box{
			position: relative;
			padding-top: 40rpx;
			
			.top{
				padding: 0 22rpx 0 16rpx;
				&-left{
					&-img{
						image{
							width: 128rpx;
							height: 128rpx;
						}
					}
					&-info{
						margin-left: 20rpx;
						&-name{
							font-family: PingFang-SC, PingFang-SC;
							font-weight: bold;
							font-size: 40rpx;
							color: #002846;
							line-height: 40rpx;
						}
						&-tip{
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 26rpx;
							color: #86909C;
							line-height: 26rpx;
							margin-top: 31rpx;
						}
						&-version{
							width: 129rpx;
							height: 40rpx;
							background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/my_version_bg.png') no-repeat;
							background-size: 100% 100%;
							padding-left: 48rpx;
							box-sizing: border-box;
							font-family: PingFang-SC, PingFang-SC;
							font-weight: bold;
							font-size: 22rpx;
							color: #795021;
							line-height: 40rpx;
							margin-top: 24rpx;
						}
					}
				}
				&-right{
					image{
						width: 42rpx;
						height: 42rpx;
					}
				}
			}
		
			.num{
				margin-top: 48rpx;
				&-pre{
					width: calc(100% / 3);
					&-sz{
						font-family: D-DINCondensed, D-DINCondensed;
						font-weight: bold;
						font-size: 48rpx;
						color: #002846;
						line-height: 48rpx;
					}
					&-text{
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #86909C;
						line-height: 26rpx;
						text-align: center;
						margin-top: 24rpx;
					}
				}
			}
		
			.preill{
				margin-top: 49rpx;
				background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/my_pinggu_bg.png') no-repeat;
				background-size: 100% 100%;
				padding: 34rpx 24rpx;
				&-left{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #B0B7C7;
					line-height: 24rpx;
					padding-top: 42rpx;
				}
				&-right{
					padding: 18rpx 26rpx;
					background: linear-gradient( 270deg, #F0E2C7 0%, #E3CD9E 100%);
					border-radius: 32rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #795021;
					line-height: 26rpx;
				}
			}
		
			.menu{
				margin-top: 30rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				&-item{
					padding: 35rpx 30rpx;
					box-shadow: inset 0rpx -1rpx 0rpx 0rpx #EFEFEF;
					&-left{
						image{
							width: 40rpx;
							height: 40rpx;
						}
						text{
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 30rpx;
							color: #002846;
							line-height: 32rpx;
							margin-left: 21rpx;
						}
					}
					&-right{
						width: 36rpx;
						height: 36rpx;
					}
				}
			}
		}
	}
</style>