<template>

	<view class="login">


	</view>
</template>

<script>
    import {
    	mapGetters,
		mapMutations
	} from 'vuex'
	import {
		currentPage,
		trottle,
		urlencode
	} from '@/utils/tools'
	import Cache from "@/utils/cache"
	import {
		BACK_URL,
		INVITE_CODE
	} from '@/config/cachekey'

	export default {
		data() {
			return {
				token: null,
				loginUrl: 'https://www.jucai.gov.cn/mobile/auth/login/company?redirect_url='
			};
		},

		async onLoad(option) {
			this.authLoginJucai();
		},
		onShow() {},
		onUnload() {

		},
		methods: {
			...mapMutations(['login']),

			async authLoginJucai() {

				const {
					token
				} = this.$Route.query
				console.log('token: ' + token)
				if (token || this.appConfig.token) {
					// uni.showLoading({
					// 	title: '登录中...',
					// 	mask: true
					// });
					this.loginHandle(token || this.appConfig.token)
				} else {
					uni.showLoading({
						title: '仅对企业开放',
						mask: true,
						complete: () => {
							//延迟0.5s登录，提示用户信息
							setTimeout(() => {
								location.href = this.loginUrl + urlencode(location.href)
							}, 500)
						}
					});
				}
			},
			// 登录结果处理
			async loginHandle(token) {

				//保存token，获取用户
				this.login({
					token: token
				})
				uni.hideLoading()

				//跳转逻辑
				if (getCurrentPages().length > 1) {
					uni.navigateBack({
						success() {
							const {
								onLoad,
								options
							} = currentPage()
							onLoad && onLoad(options)
						}
					})
				} else if (Cache.get(BACK_URL)) {
					this.$Router.replace(Cache.get(BACK_URL))
				} else {
					this.$Router.pushTab('/pages/index/index')
				}
				Cache.remove(BACK_URL)
			},
		},
		computed: {
            ...mapGetters(['appConfig']),
        }
	};
</script>
<style lang="scss">
	page {
		background-color: #fff;
		text-align: center;
		padding: 0;

		.login {
			min-height: 100vh;
			display: flex;
			flex-direction: column;

			.mpwx-login {
				min-height: 0;
				flex: 1;

				.avatar {
					display: inline-block;
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					border: 1px solid #eee;
					overflow: hidden;
				}

				.user-name {
					height: 40rpx;
				}

				.image {
					width: 50rpx;
					height: 50rpx;
				}

				.btn {
					background-color: #09BB07;
					width: 580rpx;
					margin: 80rpx auto 0;
				}
			}


			.acount-login {
				padding-top: 100rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				box-sizing: border-box;
				min-height: 0;
				flex: 1;

				.logo {

					height: 120rpx;
					margin-bottom: 50rpx;
				}

				.input {
					width: 670rpx;
					border-bottom: $-solid-border;
					margin-top: 30rpx;
				}

				.sms-btn {
					border: 1px solid $-color-primary;
					width: 176rpx;
					height: 60rpx;
					box-sizing: border-box;
				}

				.wx-login {
					margin-top: 60rpx;

					.image {
						margin-top: 40rpx;
						width: 80rpx;
						height: 80rpx;
					}
				}
			}
		}
	}

	.password-icon {
		width: 58rpx;
		height: 58rpx;
		overflow: hidden;
		margin-left: 20rpx;

		image {
			width: 100%;
		}
	}

	.agreement {
		position: fixed;
		bottom: 0px;
		width: 100%;
		padding: 30rpx 0;
	}


	.modify-container {
		padding: 40rpx 30rpx;
		width: 100%;
		border-radius: 30rpx;
		font-size: 28rpx;
		text-align: left;
		color: #333333;
		font-weight: bold;

		.title {
			padding: 26rpx 0rpx;
		}

		.btn {
			height: 80rpx;
			border-radius: 20rpx;
			margin: 60rpx 50rpx 0;
		}
	}
</style>