<template>
	<view></view>
	<!-- <view style="display: flex;align-items: center;justify-content: center;height: 100vh;">
		 <tn-loading mode="circle" size="60"></tn-loading>

	</view> -->
	
</template>

<script>
	import request from '../../utils/request'
	
	export default {
		name: 'Auth',
		data() {
			return {
				
			}
		},
		created() {			 
			let that = this;
			if(!uni.getStorageSync('loginOut')){
				uni.login({
					success(res) {
						 that.loginByCode(res.code);
					},
					fail(res) {
						//登录失效，
						// uni.hideLoading();
						// uni.redirectTo({
						// 	url:'/pages/index/index'
						// })
					}
				});
			}
			
		
		},
		methods: {
			reLogin(){
				let that = this;
				if(!uni.getStorageSync('loginOut')){
					uni.login({
						success(res) {
							 that.loginByCode(res.code);
						},
						fail(res) {
							//登录失效，
							// uni.hideLoading();
							// uni.redirectTo({
							// 	url:'/pages/index/index'
							// })
						}
					});
				}
			},
			loginByCode(frontId) {
				const that = this;
				uni.setStorageSync('loginStatus', 'false');
				wx.getUserInfo({
				  success: function(res) {
					request.post("/slbMpAutoLogin", {
					 		code:frontId, 
					 	    appType:'ma',
							encryptedData:res.encryptedData,
							iv: res.iv
					 	}, {
						login: false,
						warn:false,
						loading:false
					}).then(res2=>{
						if(res2.success){
							//登录成功
							uni.setStorageSync('loginStatus', 'true');
							uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
							uni.setStorageSync('userNo', res2.resultMap.accountName);
							that.getUserInfo();
						}else{
							uni.setStorageSync('loginStatus', 'false');
							uni.removeStorageSync('userMap');
							uni.removeStorageSync('userNo');
							uni.removeStorageSync('userInfo');
						}
					});
					 
					 
				  }
				})
				 
				
			},
			getUserInfo() {
				  let that = this;
				  request.post('/slbWxma/getPersonlInfo', {
					 
				  }).then(res => {
					  if(res&&res.success){
						  that.personInfo = res.resultMap.userInfo||{};
						  uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
					  }else{
						  uni.setStorageSync('loginStatus', 'false');
						  uni.removeStorageSync('userMap');
						  uni.removeStorageSync('userNo');
						  uni.removeStorageSync('userInfo');
					  }
				  })
		   
			},
		}
	}
</script>

<style>

</style>
