<template>
	<view class="box">
		<view class="box_top">
			<!-- <view class="tip">
				{{ userinfo.level | userLevel }}
			</view> -->
			<view class="image">
				<image :src="crown.headimgurl" mode="widthFix" style="width: 120rpx;"></image>
			</view>
			<view class="name">
				{{ crown.remark_name | getNickname }}
			</view>
			<!-- <view class="phone">
				{{ userinfo.mobile | getPhone }}
			</view> -->
		</view>
		<view class="box_bottom">
			<view class="li">
				<view class="li_item one">
					<text class="bold">{{ data.week | getNum }}</text>
					<text>近7日新增</text>
				</view>
				<view class="li_item two">
					<text class="bold">{{ data.month | getNum }}</text>
					<text>近30日新增</text>
				</view>
				<view class="li_item three">
					<text class="bold">{{ data.year | getNum }}</text>
					<text>{{ year }}累计新增</text>
				</view>
			</view>
			<view class="nav">
				
			<!-- 	<text style="margin-left: ;">2222</text> -->
				<view class="item">
					<view class="item_top" style="margin-bottom: 20rpx;align-items: center;">
						<image src="../../static/img/yuan.png" mode="widthFix" style="width: 33rpx;"></image>
						<text style="font-size: 30rpx;">授权时间：{{ userinfo.auth_startime }}</text>
					</view>
				</view>
				<view class="item">
					<view class="item_top">
						<image src="../../static/img/yuan.png" mode="widthFix" style="width: 33rpx;"></image>
						<text>新增代理</text>
					</view>
					<view class="item_bottom">
						<view class="iamge">
							<image :src="userinfo.headimgurl ? userinfo.headimgurl : headimg" mode="widthFix" style="width: 100rpx;"></image>
						</view>
						<view class="right">
							<view class="nickname">
								昵称：{{ userinfo.nickname | getNickname }}
							</view>
							<text>
								级别：{{ userinfo.level | userLevel }}
							</text>
							<text>
								手机号：{{ userinfo.mobile | getPhone }}
							</text>
						</view>
					</view>
				</view>
				<view class="item">
					<view class="item_top">
						<image src="../../static/img/yuan.png" mode="widthFix" style="width: 33rpx;"></image>
						<text>推荐人</text>
					</view>
					<view class="item_bottom">
						<view class="iamge">
							<image :src="userinfo.recom &&  userinfo.recom.headimgurl ? userinfo.recom.headimgurl : headimg" mode="widthFix" style="width: 100rpx;"></image>
						</view>
						<view class="right">
							<view class="nickname">
								昵称：{{ userinfo.recom &&  userinfo.recom.nickname | getNickname }}
							</view>
							<text>
								级别：{{ userinfo.recom && userinfo.recom.level | userLevel }}
							</text>
							<text>
								手机号：{{ userinfo.recom &&  userinfo.recom.mobile | getPhone }}
							</text>
						</view>
					</view>
				</view>
				<view class="item">
					<view class="item_top">
						<image src="../../static/img/yuan.png" mode="widthFix" style="width: 33rpx;"></image>
						<text>上级代理</text>
					</view>
					<view class="item_bottom">
						<view class="iamge">
							<image :src="userinfo.agent &&  userinfo.agent.headimgurl ? userinfo.agent.headimgurl : headimg" mode="widthFix" style="width: 100rpx;"></image>
						</view>
						<view class="right">
							<view class="nickname">
								昵称：{{ userinfo.agent &&  userinfo.agent.nickname | getNickname }}
							</view>
							<text>
								级别：{{ userinfo.agent && userinfo.agent.level | userLevel }}
							</text>
							<text>
								手机号：{{ userinfo.agent &&  userinfo.agent.mobile | getPhone }}
							</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import { GetUserCertInfo, GetCrownTeam } from '../../api/index.js';
	export default {
		data() {
			return {
				headimg: 'https://api.app.cliu.cc/logo.jpg',
				id: '',
				crown_id: '',
				year: '',
				crown: {},
				data: {},
				userinfo: {}
			}
		},
		onLoad() {
			var date = new Date();
			this.year = date.getFullYear(); //获取完整的年份(4位)
			this.id = this.$route.query.id
			this.crown_id = this.$route.query.crown_id
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				GetUserCertInfo({ id: this.id, crown_id: this.crown_id }).then(res => {
					if (res.code === 200) {
						this.crown = res.data.crown
						this.userinfo =  res.data.users
						console.log(this.userinfo)
					} else {
						uni.showToast({
							title: res.message || '获取失败',
							icon: 'none'
						})
					}
				}).catch(err => {})
				GetCrownTeam({ crown_id: this.crown_id }).then(res => {
					if (res.code === 200) {
						this.data = res.data
					} else {
						uni.showToast({
							title: res.message || '获取失败',
							icon: 'none'
						})
					}
				}).catch(err => {})
			}
		},
		filters: {
			userLevel(level) {
				if (!level) return '公司'
				let out = ''
				switch (+level) {
					case 1:
						out = '销售主管'
						break;
					case 2:
						out = '销售经理'
						break;
					case 3:
						out = '代理公司'
						break;
					default:
						out = '待定'
				}
				return out;
			},
			getPhone(value) {
				if (value) {
					// var reg = getRegExp('^(\d{3})\d{4}(\d{4})$')
					return value.substr(0, 3) + '****' + value.substr(7)
				}
			},
			getNum(value) {
				if (value) {
					// var reg = getRegExp('^(\d{3})\d{4}(\d{4})$')
					return value
				} else {
					return 0
				}
			},
			getNickname(value) {
				if (value) {
					return value.length > 10 ? value.slice(0, 10) + '...' : value;
				}
			}
		},
	}
</script>

<style lang="scss">
	.box {
		&_top {
			width: 100%;
			height: 280rpx;
			// position: relative;
			background:url('../../static/img/bg.png');
			background-size:cover;
			background-repeat:no-repeat;
			color: #fff;
			display: flex;
			flex-direction: column;
			justify-content: flex-end;
			align-items: center;
			.image {
				width: 122rpx;
				height: 122rpx;
				border-radius: 50%;
				overflow: hidden;
				border: 2rpx solid #FFFFFF;
			}
			.name {
				font-size: 36rpx;
				margin-top: 15rpx;
				font-weight: bold;
				margin-bottom: 65rpx;
			}
			.phone {
				font-size: 30rpx;
				margin-top: 20rpx;
				font-weight: bold;
			}
			.tip {
				position: absolute;
				top: 112rpx;
				right: 0;
				width: 138rpx;
				height: 56rpx;
				font-size: 28rpx;
				color: #F50F04;
				text-align: center;
				line-height: 56rpx;
				padding-left: 10rpx;
				background: #FFCC00;
				border-radius: 42rpx 0rpx 0rpx 42rpx;
			}
		}
		&_bottom {
			width: 100%;
			background: #FFFFFF;
			border-radius: 32rpx 32rpx 0rpx 0px;
			margin-top: -40rpx;
			padding: 24rpx 0 0 0;
			// padding: 54rpx 0 0 30rpx;
			.li {
				margin: 0 24rpx;
				display: flex;
				justify-content: space-between;
				margin-bottom: 25rpx;
				&_item {
					width: 218rpx;
					height: 98rpx;
					border-radius: 8px;
					padding: 14rpx 0;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					color: #fff;
					font-size: 28rpx;
					.bold {
						font-size: 40rpx;
						font-weight: bold;
						margin-bottom: 10rpx;
					}
				}
				.one {
					background: linear-gradient(90deg, #5B50FF 0%, #8D3EFF 100%);
				}
				.two {
					background: linear-gradient(93deg, #FF4646 0%, #FF893A 100%);
				}
				.three {
					background: linear-gradient(90deg, #00D59F 0%, #009AD1 100%);
				}
			}
			.nav {
				border-left: 2rpx solid #EEEEEE;
				margin-left: 30rpx;
				// height: 1100rpx;
				padding-bottom: 10rpx;
				.item {
					&_top {
						display: flex;
						align-items: flex-start;
						margin-left: -16rpx;
						text {
							color: #333;
							font-size: 32rpx;
							font-weight: bold;
							margin-left: 16rpx;
							margin-top: -7rpx;
						}
					}
					&_bottom {
						height: 162rpx;
						padding: 24rpx;
						background: #F5F5F5;
						border-radius: 16rpx;
						margin: 15rpx 24rpx 20rpx 24rpx;
						display: flex;
						align-items: flex-start;
						.image {
							width: 100rpx;
							height: 100rpx;
							border-radius: 8rpx;
							overflow: hidden;
						}
						.right {
							margin-left: 48rpx;
							height: 162rpx;
							display: flex;
							justify-content: space-between;
							flex-direction: column;
							color: #333333;
							.nickname {
								font-size: 34rpx;
								font-weight: bold;
							}
							text {
								font-size: 32rpx;
							}
						}
					}
				}
			}
		}
	}
</style>
