<template>
	<view class="pageBgImg">
		<topNavbar title="签署合同"></topNavbar>
		<!-- <view class="pad">
			<view class="card">
				<view class="h2">教学合同</view>
			</view>
			<view class="btnBg" @click="$goPage('/pages/indexEntry/enroll/payment/payment')">同意并签字确认</view>
		</view> -->
		<web-view :src="url"></web-view>
	</view>
</template>

<script>
	import {
		getContractStatus,
		getSignContract
	} from '@/config/api.js'
	export default {
		data() {
			return {
				url: '',
				schoolId: ''
			}
		},
		beforeDestroy() {
			clearInterval(this.timer)
			this.timer = null
		},
		onHide() {
			clearInterval(this.timer)
			this.timer = null
		},
		onLoad(options) {
			this.schoolId = options.schoolId?options.schoolId:this.vuex_userInfo.schoolId
			this.timer = setInterval(() => {
				this.getContractStatusFn()
			}, 3000)
			this.getSignContractFn()
		},
		methods: {
			async getSignContractFn() {
				uni.showLoading({
					title: '正在加载合同...'
				})
				let info = this.vuex_userInfo
				const {
					data: res
				} = await getSignContract({
					schoolId: this.schoolId,
					studentId: this.vuex_userInfo.id
				})
				uni.hideLoading()
				this.url = res.url
			},
			// 查询签约状态
			async getContractStatusFn() {
				const {
					data: res
				} = await getContractStatus({
					studentId: this.vuex_userInfo.id
				})
				if (res.flowStatus == 2) {
					clearInterval(this.timer)
					this.timer = null
					uni.navigateTo({
						url: '/pages/indexEntry/enroll/registInfo/registInfo'
					})
					if (res.flowStatus > 2) {
						clearInterval(this.timer)
						this.timer = null
						this.$u.toast('合同已撤销或过期')
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		.h2 {
			min-height: 800rpx;
			text-align: center;
			padding: 40rpx 0;
		}

	}

	.btnBg {
		width: 396rpx !important;
		margin: 100rpx auto 100rpx auto;
	}
</style>