<template>
	<view>
		<topNavbar title="学员报名"></topNavbar>
		<!-- <web-view :webview-styles="webviewStyles" src="http://192.168.1.44:92/question/?uniItem=%7B%22phone%22%3A%2218267103167%22%2C%22cityCode%22%3A%223311%22%2C%22isUni%22%3A1%7D"></web-view> -->
		<web-view :webview-styles="webviewStyles"  class="custom-webview" :src="link" :update-title="true"></web-view>
		<!-- <iframe src="https://your-h5-url.com" frameborder="0"></iframe> -->
	</view>
</template>

<script>
	import { getApplyStep } from "@/config/api.js"
	export default {
		data() {
			return {
				webviewStyles: {
					progress: {
						color: '#3877ff'
					},
					 width: '100vw', // 设置 WebView 宽度为100%，占满整个屏幕宽度
					 height: '100vh', // 设置 WebView 高度为100vh，占满整个屏幕高度
				},
				link: '',
				ok: false,
				getApplyStepApi: null
			}
		},
		onLoad() {
			this.link = this.$store.state.webViewUrl
			console.log('噜噜哇'+ this.$store.state.webViewUrl)
			// http://192.168.1.44:92/question/?uniItem=%7B%22phone%22%3A%2218267103167%22%2C%22cityCode%22%3A%223311%22%2C%22isUni%22%3A1%7D
			// uni.hideNavigationBarLoading()
		},
		beforeDestroy() {
			clearInterval(this.timer)
			this.timer = null
		},
		onHide() {
			clearInterval(this.timer)
			this.timer = null
		},
		onShow() {
			this.pollingFn()
		},
		methods: {
			async pollingFn() {
				this.timer = setInterval(async () => {
					const res = await this.getApplyStepFn()
					console.log(res)
					if(res==2) {
						clearInterval(this.timer)
						this.timer = null
						let redirectUrl =  '/pages/indexEntry/enroll/registInfo/registInfo'
						if(this.$store.state.user.NonPlatformStudent) {
							redirectUrl =  '/pages/indexEntry/NonPlatformStudent/NonPlatformStudent'
						}
						this.$goPage(redirectUrl)
					}
				}, 2000)
			},
			getApplyStepFn() {
				let _this = this
				if(this.ok) return this.getApplyStepApi
				this.ok =true
				return new Promise((reslove,reject)=>{
					_this.getApplyStepApi = getApplyStep({userId: this.userId}).then((res)=>{
						_this.ok = false
						// console.log(res)
						reslove(res.data)
					}).catch(()=>{
						_this.ok = false
						reject(0)
					})
				})
			}
		}
	}
</script>

<style>
.custom-webview::after {
  content: none !important; /* 隐藏返回按钮 */
}
.iframe {
	display: block;
	width: 100vw;
	height: 100vh;
}
</style>
