<template>
	<view class="content" @click="maskClick">
		<view class="qrcode">
			<!-- <uqrcode ref="uqrcode"></uqrcode> -->
			<img :src="imgSrc" alt="" class="img">
			<!-- <view class="qrcode-text">客户扫码</view> -->
		</view>
		<u-modal v-model="isShowAlert" :title-style="{fontSize: '18px',fontWeight:'500'}"
			:content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='提示'
			showCancelButton='false' :content="content" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				imgSrc: "",
				isShowAlert: false,
				content: '登录信息过期需要重新登录,是否立即登录?',
			};
		},
		onReady() {
			this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
					if (res.data.data == "INVALID") {
						this.isShowAlert = true;
						// uni.showModal({
						// 	title: "提示",
						// 	content: "Session过期需要重新登录,是否立即登录",
						// 	showCancel: true,
						// 	confirmText: '登录',
						// 	success(e) {
						// 		if (e.confirm) {
						// 			uni.navigateTo({
						// 				url: '/pages/public/login'
						// 			})
						// 		}
						// 	}
						// })
					} else {
						this.getQRCode()
					}
				})
				.catch(res => {
					if (res.message) {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						})
					}
				});
			// console.log(this.userInfo)
			// this.$refs
			// 	.uqrcode
			// 	.make({
			// 		size: 300,
			// 		margin:50,
			// 		text: JSON.stringify({
			// 			userName:this.userInfo.userName,
			// 		})
			// 	})
			// 	.then(res => {
			// 		// 返回的res与uni.canvasToTempFilePath返回一致
			// 		console.log(res)
			// 	})
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			alertBtn() {
				uni.navigateTo({
					url: '/pages/public/login'
				})
			},
			cancelClick() {
				this.isShowAlert = false
			},
			maskClick() {
				uni.navigateBack(-1)
			},
			getQRCode() {
				this.$api.doRequest('get', '/identityAuthenticationInfo/generateQRCodeImage').then(res => {
						this.imgSrc = res.data.data
					})
					.catch(res => {
						if (res.message) {
							uni.showToast({
								title: res.message,
								icon: 'none',
								duration: 2000
							})
						}
					});
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background: rgba(0, 0, 0, 0.4);
		height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.qrcode-text {
		text-align: center;
		position: relative;
		font-size: 24rpx;
		font-weight: 400;
		color: #878C9C;
		top: -40rpx;
	}

	.qrcode {
		position: fixed;
		top: 30%;
		margin: auto;
	}

	.img {
		width: 400rpx;
	}
</style>
