<template>
	<div>
		<el-affix :offset="0" :z-index="2001">
			<div class="headers">
				<headers ref="headers" />
			</div>
		</el-affix>
		<div class="content">
			<router-view></router-view>
		</div>
		<!-- 底部版权信息 -->
		<copyright />
		<!-- <div class="sidebars">
			<sidebars ref="sidebars" :userType="userType" />
		</div> -->
	</div>
</template>

<script>
	import headers from '../components/header/header.vue'
	import sidebars from '../components/sidebar/sidebar.vue'
	import copyright from '../components/copyright/copyright.vue'
	export default {
		components: {
			headers,
			sidebars,
			copyright
		},
		computed: {
			userType() {
				return this.$store.state.userType;
			}
		},
		data() {
			return {

			}
		},
		mounted() {
			if (localStorage.getItem('token')) {
				this.getUserInfo();
			}

		},
		methods: {
			getCompany(){
				this.$Request.get("/app/company/selectCompanyByUserId").then(res => {
					if(res.code == 0){
						this.$store.commit('SET_COMPANY_ID', res.data.companyId)
						localStorage.setItem('companyId', res.data.companyId);
					}
				})
			},
			//获取用户信息
			getUserInfo() {
				this.$Request.get('/app/user/selectUserById').then(res => {
					if (res.code == 0) {
						// this.avatar = res.data.avatar
						//记录直属佣金比例
						localStorage.setItem('zhiRate', res.data.zhiRate)
						this.$store.commit('SET_ZHI_RATE', res.data.zhiRate)
						//设置手机号
						this.$store.commit('SET_PHONE', res.data.phone)
						//设置企业id
						// this.$store.commit('SET_COMPANY_ID', res.data.companyId)
						// localStorage.setItem('companyId', res.data.companyId)
						//设置邀请码
						this.$store.commit('SET_INVITATION_CODE', res.data.invitationCode)
						//设置头像
						this.$store.commit('SET_AVATAR', res.data.avatar);
						//设置昵称
						this.$store.commit('SET_NICK_NAME', res.data.userName);
						//设置微信号
						if (res.data.weChatNum) {
							this.$store.commit('SET_WE_CHAT_NUM', res.data.weChatNum);
						} else {
							this.$store.commit('SET_WE_CHAT_NUM', '');
						}

						if (res.data.userType == 1 || res.data.userType == null) {
							this.$store.commit('SET_USER_TYPE', 1);
							localStorage.setItem('userType', 1)
							if (res.data.isUserVip == 1) { //判断用户是否是vip
								this.$store.commit('SET_IS_VIP', true);
							} else {
								this.$store.commit('SET_IS_VIP', false);
							}
						} else {
							this.$store.commit('SET_USER_TYPE', 2);
							localStorage.setItem('userType', 2)
							this.getCompany();
							if (res.data.isCompanyVip == 1) { //判断企业用户是否是vip
								this.$store.commit('SET_IS_COMPANY_VIP', true);
							} else {
								this.$store.commit('SET_IS_COMPANY_VIP', false);

							}
						}
					}
				})
			},
		},
	}
</script>

<style scoped>
	.headers {
		width: 100%;
	}

	.content {
		width: 100%;
	}

	.sidebars {
		position: fixed;
		right: 20px;
		top: 70%;
		transform: translate(0, -50%);
	}
</style>