<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" @click="handleLogin">
						<view class="top-left-info-name">{{userInfo.realName||'未登录'}}</view>
						<view class="top-left-info-tip" v-if="!userInfo.id">点击立即登录</view>
						<view class="top-left-info-version" v-else>{{headData.userBriefText||'普通用户'}}</view>
					</view>
				</view>
				<view class="top-right">
					<image :src="imgBase+'my_set.png'" @click="handleTurn('/pagesMy/set')"></image>
				</view>
			</view>
			<view class="num adf">
				<view class="num-pre adffcac" @click="handleTurn('/pagesPublish/rechargeCenter')">
					<view class="num-pre-sz">{{headData.basicCount||0}}</view>
					<view class="num-pre-text">个人版次数</view>
				</view>
				<view class="num-pre adffcac" @click="handleTurn('/pagesPublish/rechargeCenter')">
					<view class="num-pre-sz">{{headData.proCount||0}}</view>
					<view class="num-pre-text">团队版次数</view>
				</view>
				<view class="num-pre adffcac" @click="handleTurn('/pagesMy/team')">
					<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)">
					<!-- <template v-if="item.title === '邀请好友'">
						<button class="share-btn" open-type="share">
							<div class="menu-item-left adfac">
								<image :src="item.img"></image>
								<text>{{ item.title }}</text>
							</div>
							<image class="menu-item-right" :src="imgBase+'my_arrow_right.png'"></image>
						</button>
					</template> -->
					<div class="menu-item-left adfac">
						<image :src="item.img"></image>
						<text>{{ item.title }}</text>
					</div>
					<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:'团队版',
					0:'团队PRO版',
				},
				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:'/pagesMy/forward'
					}
				]
			}
		},
		onLoad(options) {
			if(uni.getStorageSync('userInfo')){
				this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
				this.getMyInfo(this.userInfo.id)
			} 
		},
		methods:{
			getTeamScaleData(){
				return new Promise(resolve=>{
					this.$api.get('/getListByType/user_brief').then(({data:res})=>{
						if(res.code!==0) return this.$showToast(res.msg)
						resolve(res.data.map(d=>({name:d.dictLabel,id:d.dictValue})))
					})
				})
			},
			async getMyInfo(userId){
				const userBrief = await this.getTeamScaleData()
				this.$api.get(`/wx/myCount/${userId}`).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.headData = res.data;
					this.$set(this.headData,'userBriefText',userBrief.find(u=>u.id==this.headData.userBrief)?userBrief.find(u=>u.id==this.headData.userBrief).name:'普通用户')
					if(this.headData&&this.headData.userBriefText&&this.headData.userBriefText=='校友') this.headData.userBriefText = '创衡校友'
				})
			},
			handleLogin(){
				if(this.userInfo?.id) return
				uni.reLaunch({
					url:'/pages/login'
				})
			},
			handleTurn(url){
				if(!this.isLogin()) return
				if(!url) return
				uni.navigateTo({ url })
			},
		}
	}
</script>

<style scoped lang="scss">
	.share-btn {
		width: 100%;
		background-color: transparent;
		border: none;
		padding: 0;
		margin: 0;
		line-height: 1;
		display: flex;
		align-items: center;
		justify-content: space-between;
		&::after {
			border: none;
		}
	}

	.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;
							border-radius: 50%;
						}
					}
					&-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: 164rpx;
							height: 40rpx;
							background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/my_version_bg2.png') no-repeat;
							background-size: 100% 100%;
							padding-left: 45rpx;
							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>