<template>
	<view class="top">
		<view class="left">
			<image src="../static/logo.png" mode="widthFix" class="img"></image>
			<view class="nav">
				<text class="text" @click="clickIndex" :class="type=='index'?'navactive':''">首页</text>
				<text class="text" @click="toProduct" :class="type=='product'?'navactive':''">产品介绍</text>
				<text class="text" @click="toAboutUs" :class="type=='aboutUs'?'navactive':''">关于我们</text>
				<text class="text" @click="toSupport" :class="type=='support'?'navactive':''">技术支持</text>
			</view>
		</view>

		<view class="right-content" v-if='hasLogin'>
			<view class="phone" @click="phoneClick">
				<image :src="userInfo.avatarUrl" class="img"></image>
				<view class="">
					{{userInfo.phone}}
				</view>
			</view>
			<view class="out-view" v-if="isSHowUser">
				<view class="text" @click="userClick">
					个人中心
				</view>
				<view class="text" @click="logOut">
					退出
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		name: 'top',
		emits: ['click'],
		props: {
			type: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				isSHowPhone: true,
				isSHowUser: false,
			}
		},
		watch: {
			title(newVal) {
				if (uni.report && newVal !== '') {
					uni.report('title', newVal)
				}
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			logOut() {
				uni.clearStorageSync();
				var that = this

				this.$store.commit('logout')
				uni.navigateTo({
					url: `/pages/index/index`
				})
			},
			phoneClick() {
				this.isSHowUser = !this.isSHowUser
			},
			onClick() {
				this.$emit('click')
			},
			clickIndex() {
				uni.navigateTo({
					url: "/pages/index/index"
				})
			},
			userClick() {
				uni.navigateTo({
					url: "/pages/index/user"
				})
			},
			toProduct() {
				uni.navigateTo({
					url: "/pages/index/product"
				})
			},
			toAboutUs() {
				uni.navigateTo({
					url: "/pages/index/aboutUs"
				})
			},
			toSupport() {
				uni.navigateTo({
					url: "/pages/index/support"
				})
			},
		}
	}
</script>
<style lang="scss">
	.navactive {
		color: #2F54EF !important;
	}

	.img {
		width: 200rpx;
	}

	.right-content {
		position: relative;

		.phone {
			display: flex;
			align-items: center;
			position: relative;
			cursor: pointer;
		}

		.img {
			width: 64rpx;
			height: 64rpx;
			border-radius: 50%;
			margin-right: 10px;
		}

		.out-view {
			position: absolute;
			bottom: -80px;
			left: 45px;
			z-index: 2;
			width: 182rpx;
			height: 148rpx;
			background: #FFFFFF;
			box-shadow: 0px 2px 20px 0px rgba(0, 0, 0, 0.1);
			border-radius: 12px;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.text {
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
				line-height: 20px;
				cursor: pointer;
			}
		}
	}

	.top {
		display: flex;
		align-items: center;
		background: white;
		justify-content: space-between;
		padding: 66rpx 10%;
		min-width: 1200px;
		box-sizing: border-box;

		.left {
			display: flex;

			.nav {
				margin-left: 200rpx;
			}
		}

		// color: white;
		// background: black

	}

	.title {
		margin: 0 40rpx;
	}

	.nav {
		display: flex;
		align-items: center;

		.text {
			font-size: 16px;
			color: #65676B;
			margin-right: 200rpx;
			cursor: pointer;
		}
	}
</style>
