<template>
	<view class="my-box">
		<view class="my-content">
			<view class="my-top"></view>
			<image class="my-avatar" @click="$navigateTo('/pages/myDetail/myDetail')" :src="user.portrait"
				mode="aspectFill"></image>
			<view class="name" @click="$navigateTo('/pages/myDetail/myDetail')">{{user.userName || '登录/注册'}}</view>
			<view class="organization" v-if="user.organizedName">{{user.organizedName}}</view>
			<view class="my-tab">
				<view class="tab-box">
					<view class="tab-item" @click="$navigateTo('/pages/myHouse/myHouse')">
						<view class="tab-number">{{fansCount.roomCount}}</view>
						<view class="tab-text">房源</view>
					</view>
					<view class="tab-item" @click="$navigateTo('/pages/fans/fans')">
						<view class="tab-number">{{fansCount.fansCount}}</view>
						<view class="tab-text">粉丝</view>
					</view>
					<view class="tab-item" @click="$navigateTo('/pages/attention/attention')">
						<view class="tab-number">{{fansCount.attentionCount}}</view>
						<view class="tab-text">关注</view>
					</view>
				</view>
			</view>
			<view class="my-list">
				<view class="my-list-box">
					<view class="my-item" @click="$navigateTo('/pages/collect/collect')">
						<view class="my-icon bg1">
							<uni-icons custom-prefix="iconfont" type="icon-wodeshoucangshixin" color="#fff"
								size="20"></uni-icons>
						</view>
						<view class="item-content">
							我的收藏
						</view>
						<view class="my-forward">
							<uni-icons type="forward" size="18" color="#c1c0c8"></uni-icons>
						</view>
					</view>
					<view class="my-item" @click="$navigateTo('/pages/client/client')">
						<view class="my-icon bg2">
							<uni-icons custom-prefix="iconfont" type="icon-wodekehu" color="#fff" size="20">
							</uni-icons>
						</view>
						<view class="item-content">
							我的客户
						</view>
						<view class="my-forward">
							<uni-icons type="forward" size="18" color="#c1c0c8"></uni-icons>
						</view>
					</view>
					<view class="my-item" @click="$navigateTo('/pages/organization/organization')">
						<view class="my-icon bg3">
							<uni-icons custom-prefix="iconfont" type="icon-wodegongsi-gaoliang" color="#fff" size="22">
							</uni-icons>
						</view>
						<view class="item-content">
							我的公司
						</view>
						<view class="my-forward">
							<uni-icons type="forward" size="18" color="#c1c0c8"></uni-icons>
						</view>
					</view>
					<view class="my-item" @click="$navigateTo('/pages/download/download')">
						<view class="my-icon bg4">
							<uni-icons custom-prefix="iconfont" type="icon-wodexiazaizhongxin" color="#fff" size="18">
							</uni-icons>
						</view>
						<view class="item-content">
							我的下载
						</view>
						<view class="my-forward">
							<uni-icons type="forward" size="18" color="#c1c0c8"></uni-icons>
						</view>
					</view>
					<view class="my-item">
						<view class="my-icon bg5">
							<uni-icons custom-prefix="iconfont" type="icon-kefuzhongxin" color="#fff" size="24">
							</uni-icons>
						</view>
						<view class="item-content">
							客服中心
						</view>
						<view class="my-forward">
							<uni-icons type="forward" size="18" color="#c1c0c8"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyCount
	} from '@/request/api/my.js'
	export default {
		data() {
			return {
				fansCount: {
					attentionCount: 0,
					fansCount: 0,
					roomCount: 0
				},
				user: {}
			}
		},
		onShow() {
			if (!uni.getStorageSync('token')) {
				this.user = {};
				this.fansCount = {
					attentionCount: 0,
					fansCount: 0,
					roomCount: 0
				}
			} else {
				this.user = this.$store.getters.user;
				this.user.organizedName = this.$store.getters.organization && this.$store.getters.organization.name;
				this.init();
			}
		},
		methods: {
			init() {
				getMyCount().then(res => {
					if (res.code === 200) {
						this.fansCount = res.data;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.my-box {
		height: 100vh;
		background: #fff;
		overflow-y: auto;

		.my-content {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-bottom: 80rpx;
		}

		.my-top {
			height: 260rpx;
			background-image: url('https://images.unsplash.com/photo-1558591710-4b4a1ae0f04d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwyMDUzMDJ8MHwxfHNlYXJjaHw1fHxhYnN0cmFjdHxlbnwxfHx8fDE2NTI4OTYzNTU&ixlib=rb-1.2.1&q=80&w=1080');
			background-position: center center;
			background-size: cover;
			background-repeat: no-repeat;
			width: 100%;
		}

		.my-avatar {
			width: 200rpx;
			height: 200rpx;
			border-radius: 50%;
			margin-top: -100rpx;
			border: 6rpx solid #fff;
			background: #eee;
		}

		.name {
			font-size: 20px;
			font-weight: 700;
			margin: 10rpx 0;
		}

		.organization {
			color: $uni-secondary-color;
			font-weight: 300;
		}

		.my-tab {
			width: 100%;
			padding: 0 30rpx;
			box-sizing: border-box;
			margin: 40rpx 0;

			.tab-box {
				height: 160rpx;
				border-radius: 24rpx;
				box-shadow: 1px 1px 12px rgba(164, 164, 164, 0.25);
				display: flex;
				align-items: center;
			}

			.tab-item {
				flex: 1;
				text-align: center;
			}

			.tab-number {
				font-size: 40rpx;
				font-weight: 600;
			}

			.tab-text {
				font-size: 24rpx;
				font-weight: 300;
				margin-top: 10rpx;
			}
		}

		.my-list {
			width: 100%;
			padding: 0 30rpx;
			box-sizing: border-box;

			.my-list-box {
				border-radius: 24rpx;
				box-shadow: 1px 1px 12px rgba(164, 164, 164, 0.25);
				overflow: hidden;
			}

			.my-item {
				display: flex;
				align-items: center;
				padding: 20rpx 30rpx;
			}

			.my-item:active {
				background: $uni-background-color;
			}

			.my-icon {
				width: 80rpx;
				height: 80rpx;
				border-radius: 16rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 20rpx;
				background: #c1c0c8;

				&.bg1 {
					background: #88d498;
				}

				&.bg2 {
					background: #ffb997;
				}

				&.bg3 {
					background: #7ad9ff;
				}

				&.bg4 {
					background: #9ac0cd;
				}

				&.bg5 {
					background: #40e0d0;
				}
			}

			.my-forward {
				height: 40rpx;
			}

			.item-content {
				flex: 1;
				width: 0;
				overflow: hidden;
				font-weight: 700;
			}
		}
	}
</style>