<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">学习园地</block>
		</cu-custom>
		<scroll-view @scrolltolower="scrolltolower"  scroll-y="true"  :style="'top:'+sTop+'px;height:calc(100vh - '+totalHeight+'px)'">

			<view class="sbanner">
				<view class="simgs">
					<image src="../../../static/study-banner.png" mode=""></image>
				</view>
			</view>
			<view class="study-apps">
				<view class="study-apps-item" @click="$noMultipleClicks(goMyTask)">
					<image src="../../../static/study-app01.png" mode=""></image>
				</view>
				<view class="study-apps-item" @click="$noMultipleClicks(goCourseware)">
					<image src="../../../static/study-app02.png" mode=""></image>
				</view>
			</view>
			<view class="cu-tabbar-height"></view>
		</scroll-view>

		<video v-show="showVideo" id="video"  :src='videoUrl' @fullscreenchange = 'fullscreenchange'></video>
	</view>
</template>

<script>
	import {
		basePath,
		corpinfoId,
		loginUser,
		loginSession,
		baseImgPath
	} from '@/common/tool.js';
	export default {
		data() {
			return {
				backUrl: '/pages/index/index',
				dataFlag:'noData',
				noClick: true,
				listVal: [],
				videoPlaying:false,
				baseImgPath:baseImgPath,
				sTop:0,
				TabCur: 0,
				scrollLeft: 0,
				totalHeight:0,
				list:[],//返回数据
				page:1,//分页参数--页数
				rows:10,//分页参数--每页数据条数
				totalCount:0,//分页参数--初始化页数
				isEnd:false,//防止多次刷新
				totalPage:0,//分页参数--分页数量
				showVideo:false,
				videoUrl:'',
				VideoContext:'',
				tabList : [
					{
						name:'职业技能'
					},
					{
						name:'安全生产'
					},
					{
						name:'工伤预防'
					},
				]
			}
		},
		mounted(){
			// let that=this;
			// let CustomBar = this.CustomBar;
			// uni.getSystemInfo({ //调用uni-app接口获取屏幕高度
			// 	success(res) { //成功回调函数
			// 		let titleH=uni.createSelectorQuery().select(".top-fixed"); //想要获取高度的元素名(class/id)
			// 		titleH.boundingClientRect(data=>{
			// 			that._data.sTop=data.height  //计算高度:元素高度=窗口高度-元素距离顶部的距离(data.top)
			// 			that.totalHeight = data.height+CustomBar
			// 		}).exec()
			// 	}
			// })
			this.VideoContext = uni.createVideoContext('video')
		},
		onShow(){

			var _this = this;
			_this.background = require('@/common/background.json');
			_this.showCount = -1;
			_this.currentPage = 1;
			_this.list = [];
			_this.isEnd = false;
			_this.getData();
			// _this.getDept();
			loginSession();
		},
		onLoad() {
			// this.getData();
			// loginSession();
		},
		methods: {
			//跳转事件
			goToEdit(e) {
				uni.navigateTo({
					url: '/pages/application/basic-info-manage/basic-information/basic-information-edit'
				});
			},
			getData() {
				// var _this = this;
				// uni.showLoading({
				// 	title: '请稍候'
				// })
				// uni.request({
				// 	url: basePath + '/app/studysection/list',
				// 	method: 'POST',
				// 	dataType: 'json',
				// 	header: {
				// 		'Content-type': 'application/x-www-form-urlencoded'
				// 	},
				// 	data: {
				// 		CORPINFO_ID: corpinfoId,
				// 	},
				// 	success: (res) => {
				// 		uni.hideLoading(); //结束加载中动画
				// 		var result = res.data.result;
				// 		if ("success" == result) {
				// 			_this.listVal = res.data.varList;
				// 		}
				// 	}
				// });


				var _this = this;
				if (_this.isEnd) {
					return
				}else{
					this.isEnd =true;
				}
				uni.showLoading({
					title:"加载中..."
				});//加载中动画
				uni.request({
					url: basePath +'/app/studysection/list?showCount='+_this.showCount+'&currentPage='+_this.currentPage ,
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CORPINFO_ID:corpinfoId
					},
					success: (res) => {
						uni.hideLoading();//结束加载中动画
						if (res.data != null) {
							_this.totalPage = res.data.page.totalPage;
							if(_this.list.length == 0){
								_this.list = res.data.varList;
							}else{
								if(res.data.varList != null){
									_this.list2 = res.data.varList;
									_this.list = _this.list.concat(_this.list2);
								}
							}
						}

					}
				})
			},

			// 滑动到底方法
			scrolltolower(){
				console.info(666)
				var _this = this;
				_this.showCount = -1;
				_this.currentPage = _this.currentPage + 1;
				_this.isEnd = false;
				if(_this.totalPage >= _this.currentPage){
					_this.getData();//开始分页查询
				}
			},
			goStuToOpen(e) {
				var url = baseImgPath + e;
				var url2 = encodeURI(url);
				plus.runtime.openURL(url2, function(res) {});
			},
			goMyTask() {
				uni.redirectTo({
					url: '/pages/application/onlinexxks/my-tasks'
				});
			},
			goCourseware() {
				uni.redirectTo({
					url: '/pages/application/onlinexxks/courseware-list'
				});
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},

			showFile(item){
				var isVideo = false
				if(item.FILEPATH.lastIndexOf('.mp4', item.FILEPATH.length - 1) > -1){
					isVideo = true
				}
				if(isVideo){
					this.videoUrl = baseImgPath+item.FILEPATH
					this.VideoContext.requestFullScreen()
				} else {
					uni.showLoading({
						title:"加载中..."
					});//加载中动画
					uni.downloadFile({
						url:baseImgPath+item.FILEPATH,
						success:(res)=>{
							uni.hideLoading();//结束加载中动画
							uni.openDocument({
								filePath:res.tempFilePath,
								success:function(res){
									console.info(res)
								}
							})
						}
					})
				}


			},
			fullscreenchange(){
				console.info(this.videoUrl)
				if(!this.videoPlaying){
					this.videoPlaying = true
					this.VideoContext.play()
				} else {
					this.videoPlaying = false
					this.VideoContext.stop()
					this.videoUrl = ''
				}
				// this.showVideo = false
			}
		}
	}
</script>

<style>
	.nav{margin-bottom: 4upx;}
	.cu-tag+.cu-tag{
		margin-left: 30upx;
	}
</style>