<template>
	<view class="SignMultiple">
		<view class="urlIndex">
			<view class="urlTitle">
				<view class="urlWelcome">
					<view style="font-size: 26px">Welcome</view>
					<view class="urlhibiscus">
						<view>芙蓉安校</view>
						<view style="font-size: 16px">FuRong District Campus security</view>
					</view>
				</view>
			</view>
		</view>
		<view class="SignItem">
			<view class="Cancel">
				<u-button color="#4e87ff" @click="onLogin">一键授权</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		postLogin,
		postopenid,
		wechatLogin,
		getstationbase
	} from '@/api/login';
	import {
		customTotast
	} from '@/utils/index';
	import {
		mapMutations,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {

			};
		},
		computed: {
			// ...mapGetters({
			// 	getopenid: 'openid/getopenid'
			// })
		},
		onLoad() {
			console.log(this.openidList);
		},
		onReady() {

		},
		methods: {
			...mapMutations({
				updateList: 'users/updateList', //用户信息
				openidList: 'openid/openidList',
				schoolList: 'users/schoolList', //学校信息
			}),

			// login
			onLogin() {
				console.log(111111111)
				uni.login({
					provider: "weixin",
					success:  (ress) => {
						console.log(2222,ress.code)
						 wechatLogin({
							code: ress.code
						}).then((res) => {
							uni.showLoading({
								title: '正在登陆中...'
							});
							this.updateList(res.data)
								getstationbase({
									name: res.data.station
								}).then((respoen) => {
									this.schoolList(respoen.data)
								})				
							setTimeout(() => {
								uni.hideLoading();
								customTotast({
									title: '登陆成功',
									icon: 'success'
								})();
								setTimeout(() => {
									uni.switchTab({
										url: `/pages/index/index`
									});
								}, 1000)
							}, 800);
						}).catch((err) => {
							if (err.code === -4) {
								uni.showLoading({
									title: '正在获取中...'
								});
								setTimeout(() => {
									uni.hideLoading();
									uni.showToast({
										title: '信息不存在未注册',
										icon: 'none',
										mask: true,
									});
									console.log(err.data);
									this.openidList(err.data)
									setTimeout(() => {
										console.log(1213);
										uni.navigateTo({
											url: `/pages/my-sign/my-sign`
										});
									}, 1000)
								}, 800)
							}
							if (err.code === -1) {
								uni.showLoading({
									title: '正在获取中...'
								});
								setTimeout(() => {
									uni.hideLoading();
									uni.showToast({
										title: '微信授权失败',
										icon: 'none',
										mask: true,
									});
								}, 1000)
							}
							if (err.code === -12) {
								uni.showLoading({
									title: '正在获取中...'
								});
								setTimeout(() => {
									uni.hideLoading();
									uni.showToast({
										title: '账号等待审批中',
										icon: 'none',
										mask: true,
									});
								}, 1000)
							}
						})
					},
				})
			},
		}
	};
</script>

<style scoped lang="scss">
	* {
		padding: 0;
	}

	.SignMultiple {
		height: 100vh;
		background: #f4f5f7;
		position: relative;

		.urlIndex {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 0;
			margin: 0;
			width: 100%;
			height: 440rpx;
			background: #3a6bbe;
			text-align: center;
			overflow: hidden;

			.urlTitle {
				width: 100%;
				height: 300rpx;

				.urlWelcome {
					color: #fff;
					font-size: 24px;
				}

				.urlhibiscus {
					height: 200rpx;
					line-height: 100rpx;
					font-size: 22px;
					// width: 200rpx;
					margin: 40rpx 20rpx;
					border: 2px solid #a1b8e0;
				}
			}
		}

		.type {
			margin: 0 20rpx 0 20rpx;
			width: 29%;
			text-align: right;
		}

		.HiddenEse {
			position: absolute;
			top: 4px;
			right: 0;
			width: 76rpx;
			height: 40rpx;

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.SignItem {
			transform: translateY(15%);
			display: flex;
			flex-direction: column;
			margin: 20rpx 48rpx;
			// background-color: #fff;
			border-radius: 20rpx;
		}

		.Cancel {
			display: flex;
			flex-direction: column;
			justify-content: center;
			text-align: center;
			margin: 20rpx 40rpx;
		}

		.dataLoginId {
			display: flex;
			background: #fff;
			border-radius: 4px;
			align-items: center;
			margin-bottom: 30rpx;
			box-shadow: 1px 3px 2px #eaeaec;
		}

		/deep/.u-form-item {
			line-height: 90rpx;
			position: relative;
			width: 90%;
		}

		/deep/.u-form-item__body {
			margin-left: 20rpx;
			width: 80%;
		}

		/deep/.u-form-item__body__right__message {
			margin-left: 24rpx !important;
		}
	}
</style>