<template>
	<image-container
		:imgObj="{src: '/images/bg.jpg',width: '100vw',height:'41vh',mode: 'fill'}"></image-container>
</template>

<script setup lang="ts">
	import { ref,onMounted, computed } from 'vue';
	import { GetCaptcha, PostCompanyLogin} from '@/apis/models';
	import { store } from '@/store/index';
	import { router } from '@/router/index';
	import { warnToast, successToast } from '@/utils/toastHelper';
	let loginType = ref<String>('1')
	
	const loginTypeChange = () => {
		getCaptcha()
	}
	const showLoginBox = computed(() => {
		return store.state.showLoginBox
	})
	
	onMounted(() => {
		getCaptcha()
	})
	
	let cpt_id = ref<String>('')
	let codeImage = ref<String>('')
	const getCaptcha = () => {
		loginForm.value.captcha = '';
		GetCaptcha().then(res => {
			cpt_id.value = res.data.cpt_id;
			codeImage.value = res.data.img;
		})
	}
	
	const login = () => {
		store.commit('setShowLoginBox', {
			showLoginBox: false
		})
		sessionStorage.setItem('token', 'admin')
		sessionStorage.setItem('role', 'company')
		store.commit('permissions/SET_PERMISSION', null)
		store.commit('permissions/SET_MENU', [])
		router.push('/manage/home')
	}
	
	// 进入注册
	const register = () => {
		store.commit('getIntoRegister', {
			intoRegister: true
		})
	}
	
	// 企业登录
	let loginForm = ref<Object>({
		username: "18022147412",
		password: "123456",
		cpt_id: "",
		captcha: ""
	})
	
	const companylogin = () => {
		loginForm.value.cpt_id = cpt_id.value;
		PostCompanyLogin(loginForm.value).then(res => {
			successToast('登录成功');
			store.commit('setShowLoginBox', {
				showLoginBox: false
			})
			store.commit('getToken', {
				token: res.data.jwttoken.accesstoken
			})
			store.commit('getRole', {
				role: 'company'
			})
			store.commit('getPageType', {
				pageType: 'company'
			})
			sessionStorage.setItem('token', res.data.jwttoken.accesstoken)
			sessionStorage.setItem('role', 'company')
			sessionStorage.setItem('pageType', 'company')
			sessionStorage.setItem('id', res.data.company_id)
			store.commit('permissions/SET_PERMISSION', null)
			store.commit('permissions/SET_MENU', [])
			router.push('/manage/home')
		}).catch(err => {
			getCaptcha()
		})
	}	
</script>

<style lang="less" scoped>
	.login-content {
		position: relative;
		width: 100%;
		height: 41vh;

		.login-position {
			position: absolute;
			top: 30px;
			left: 0;
			right: 0;
			bottom: 0;

			.login-box {
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 20px 30px;
				border-radius: 10px;
				background-color: aliceblue;
			}
		}
	}

	:deep(.ant-tabs-nav-wrap) {
		flex: none !important;
	}

	:deep(.ant-tabs-nav) {
		justify-content: center !important;
	}
</style>