<template>
	<view class="app-container">
		<view class="code-container" v-if="isShowCode">
			<view class="title">请完成安全验证</view>
			<pt-images-verification ref="verification" :top="codeObj.yHeight" :bgImg="codeObj.bigImage" :maskImg="codeObj.smallImage" :isSuccess="codeObj.isSuccess" :isFail="codeObj.isFail" @refresh="refresh" @finish="finish"></pt-images-verification>
		</view>
		<image v-else :src="imagesUrl" style="width:100%" mode="widthFix"></image>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				imagesUrl:'',
				code: '',
				isShowCode: true,
				codeObj: {
					bigImage: '',
					smallImage: '',
					key: '',
					yHeight: '',
					isSuccess: false,
					isFail: false,
				}
			}
		},
		computed: {
			...mapState(['userInfo', 'isLogin', 'userId', 'websitData']),
		},
		onLoad() {
			this.init();
		},
		methods: {
			// 获取图片验证码
			init(){
				this.$axios({
					url: '/common/getVerifi',
					method: 'get',
					params: {},
					isLoading: 1
				}).then(res => {
					this.codeObj = res.data;
				})
			},
			
			// 刷新验证码
			refresh(){
				this.isShowCode = true
				this.init()
			},
			
			// 验证结束
			finish(value){
				this.$axios({
					url: '/user/user/detail',
					method: 'get',
					params: {
						userId: this.userId,
					},
				}).then((res) => {
					this.$axios({
						url: '/user/websitUrl',
						params: {
							websitId: res?.data?.adminWebsit?.websitId,
							key: this.codeObj.key,
							vrifyCode: Math.round(value)
						},
						isLoading: 1
					}).then(res => {
						this.imagesUrl = res.data
						this.isShowCode = false
					}).catch(err => {
						
					})
				});
			}
		}
	}
</script>

<style lang="scss">
	.app-container {
		background: #F4F2F2;
		box-sizing: border-box;
	}
	.banner {
		image {
			width: 100%;
		}
	}
	.code-container {
		position: fixed;
		top: calc(50vh - 150px);
		left: calc(50vw - 170px);
		z-index: 999;
		background: #FFFFFF;
		padding: 20px;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		.title {
			font-size: 28rpx;
			color: #333333;
			width: 100%;
			text-align: left;
			margin-bottom: 10px;
		}
		.button {
			margin-top: 20px;
			color: #666666;
			width: 200rpx;
			line-height: 60rpx;
			border: 1px solid #eaeaea;
			border-radius: 10rpx;
			text-align: center;
		}
	}
	.main {
		padding: 50rpx;
		.title {
			font-size: 32rpx;
			color: #333333;
			text-align: center;
		}
		.button {
			margin-top: 120rpx;
			width: 100%;
			text-align: center;
			line-height: 88rpx;
			border-radius: 88rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			background: linear-gradient(-90deg,#ff3f42 0%, #fe781f 100%);
			&.disabled {
				background: #C1C1C1;
			}
		}
		.tips {
			font-size: 24rpx;
			color: #FE781F;
			line-height: 24rpx;
			margin-top: 20rpx;
			height: 24rpx;
			margin-left: 10rpx;
		}
		.form {
			margin-top: 60rpx;
			.row {
				&:last-child {
					margin-top: 40rpx;
					display: flex;
					align-items: flex-end;
					.btn {
						width: 180rpx;
						height: 50rpx;
						border-radius: 50rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 24rpx;
						color: #FFFFFF;
						background: linear-gradient(-90deg,#ff3f42 0%, #fe781f 100%);
						margin-left: 30rpx;
						&.disabled {
							background: #C1C1C1;
						}
					}
				}
				.row-c {
					height: 60rpx;
					display: flex;
					align-items: center;
					border-bottom: 1px solid #D1D1D1;
					.left {
						width: 140rpx;
						height: 28rpx;
						border-right: 1px solid #D1D1D1;
						font-size: 30rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						flex-shrink: 0;
					}
					.input {
						width: 100%;
						input {
							font-size: 30rpx;
							width: 100%;
							padding: 0 25rpx;
							box-sizing: border-box;
						}
					}
				}
			}
		}
	}
</style>
