<template>
	<view>
		<u-navbar title="广告" @leftClick="leftClick" :autoBack="false">
		</u-navbar>
		<!-- 广告页 -->
		<view>
			<view class="leftbox"> {{videoLastTime}}S 后结束广告</view>
		</view>
		<video id="myVideo" class="hide-progress" style="width: 100%; height: 100vh; " :src="vurl" :autoplay="true"
			:controls="false" :show-play-btn="false" :show-fullscreen-btn="false" :enable-progress-gesture="false"
			:show-progress="false" controls @timeupdate="handleTimeUpdate" @ended="handleVideoEnded"></video>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				videoLastTime: 0,
				vurl: null,
				tableAlias: null,
				selectedChildId: null,
				type: null,
				recordId: null

			}
		},
		onLoad(option) {
			console.log(option);
			this.vurl = option.videourl
			if (option.type == 'back') {
				this.type = option.type
				this.recordId = option.recordId
			} else {
				console.log(353535, option.selectedChildId);
				this.tableAlias = option.alias
				this.selectedChildId = option.selectedChildId
			}
		},
		methods: {
			leftClick() {
				console.log('57');
				uni.switchTab({
					url: '/essayPackage/pages/Home'
				})
			},
			handleTimeUpdate(e) {

				// 更新当前播放时间  
				this.currentTime = e.detail.currentTime;
				this.videoLastTime = Math.floor(e.detail.duration - e.detail.currentTime)
				console.log(this.videoLastTime, 395)
			},
			handleVideoEnded(e) {
				if (!this.type) {
					// 跳转到下一个页面
					uni.redirectTo({
						url: `/tablePackage/pages/answerDetail?alias=${this.tableAlias}&selectedChildId=${this.selectedChildId}`
					})
				} else {
					uni.redirectTo({
						url: `/tablePackage/pages/testRecord?recordId=${this.recordId}&adStatus=ok`
					})
				}
			}
		}

	}
</script>

<style>
	.leftbox {
		font-size: 14px;
		color: #fff;
		position: fixed;
		right: 15px;
		top: 93px;
		z-index: 99999999;
		background: gba(0, 0, 0, 0.9);
		border-radius: 50px;
		box-sizing: border-box;
		padding: 5px 15px;
	}
</style>