<template>
	<view class="videoLive">
		<u-navbar :background="background" :is-back='true' back-icon-color='#FFFFFF' :border-bottom="false" title="摄像机01"
			title-color='#FFFFFF' :title-bold='true' title-size='32'></u-navbar>
			
		<view class="center">
			<view class="video_live">
				<!-- <image src="../../static/videoLive.png" mode=""></image> -->
				<video id="myVideo" style="width: 100%;height: 100%;" :src="src" controls></video>
			</view>
			
			<view class="skills">
				<view class="left">
					<image src="../../static/direction_keys.png" mode=""></image>
					<view :class="directionFlag == 0 ? 'arrow_item_act' : 'arrow_item'" class="left_arrow_item" @touchstart='ytControl1(2)' @touchend='ytControlStop(2)'>
						<image class="left_arrow" src="../../static/left_arrow.png" mode="" v-if="directionFlag != 0"></image>
						<image class="left_arrow" src="../../static/left_arrow_act.png" mode="" v-else></image>
					</view>
					<view :class="directionFlag == 1 ? 'arrow_item_act' : 'arrow_item'" class="right_arrow_item" @touchstart='ytControl2(3)' @touchend='ytControlStop(3)'>
						<image class="right_arrow" src="../../static/right_arrow.png" mode=""  v-if="directionFlag != 1"></image>
						<image class="right_arrow" src="../../static/right_arrow_act.png" mode="" v-else></image>
					</view>
					<view :class="directionFlag == 2 ? 'arrow_item_act' : 'arrow_item'" class="up_arrow_item" @touchstart='ytControl3(0)' @touchend='ytControlStop(0)'>
						<image class="up_arrow" src="../../static/up_arrow.png" mode=""  v-if="directionFlag != 2"></image>
						<image class="up_arrow" src="../../static/up_arrow_act.png" mode="" v-else></image>
					</view>
					<view :class="directionFlag == 3 ? 'arrow_item_act' : 'arrow_item'" class="down_arrow_item" @touchstart='ytControl4(1)' @touchend='ytControlStop(1)'>
						<image class="down_arrow" src="../../static/down_arrow.png" mode=""  v-if="directionFlag != 3"></image>
						<image class="down_arrow" src="../../static/down_arrow_act.png" mode="" v-else></image>
					</view>
					
				</view>
				<view class="right">
					<view class="right_item">
						<view :class="flag1?'add_act':'add'" @touchstart='ytControlFocusAdd(10)' @touchend='ytControlStopFocusAdd(10)'>
							<image src="../../static/add_act.png" mode="" v-if="flag1==true"></image>
							<image src="../../static/add.png" mode="" v-if="flag1==false"></image>
						</view>
						<view class="focus">
							焦距
						</view>
						<view :class="flag1?'subtract':'subtract_act'" @touchstart='ytControlFocusSubtract(11)' @touchend='ytControlStopFocusSubtract(11)'>
							<image src="../../static/subtract.png" mode="" v-if="flag1==true"></image>
							<image src="../../static/subtract_act.png" mode="" v-if="flag1==false"></image>
						</view>
					</view>
					<view class="right_item">
						<view :class="flag2?'add_act':'add'" @touchstart='ytControlScaleAdd(8)' @touchend='ytControlStopScaleAdd(8)'>
							<image src="../../static/add_act.png" mode="" v-if="flag2==true"></image>
							<image src="../../static/add.png" mode="" v-if="flag2==false"></image>
						</view>
						<view class="focus">
							缩放
						</view>
						<view :class="flag2?'subtract':'subtract_act'" @touchstart='ytControlScaleSubtract(9)' @touchend='ytControlStopScaleSubtract(9)'>
							<image src="../../static/subtract.png" mode="" v-if="flag2==true"></image>
							<image src="../../static/subtract_act.png" mode="" v-if="flag2==false"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 头部导航背景
				background: {
					backgroundColor: '#24B383',
				},
				directionFlag:5,
				flag1:true,
				flag2:true,
				cameraSerialNumber:'',
				cameraChannelNumber:'',
				accesstoken:'',
				src:'',
				timer:null,
				timer1:null
			};
		},
		onLoad(options) {
			// console.log(options,'00');
			this.cameraSerialNumber = options.cameraSerialNumber;
			this.cameraChannelNumber = options.cameraChannelNumber
			this.getVideoData(this.cameraSerialNumber, this.cameraChannelNumber)
		},
		methods:{
			// 获取摄像头得地址
			getVideoData(cameraid, channelid) {
				this.$http({
					url: this.api.camera_getphonehls,
					method: 'GET',
					data: {
						cameraid,
						channelid,
					}
				}).then(res => {
					if (res.code == 200) {
						this.accesstoken = res.data.accesstoken;
						this.src = res.data.ezopen;
					}
				})
			},
			
			ytControl(num){
				let that = this;
				clearTimeout(that.timer);
				that.timer = setTimeout(() => {
					uni.request({
					    url: 'https://open.ys7.com/api/lapp/device/ptz/start',
						method: 'POST',
						data:{
							accessToken: that.accesstoken,
							deviceSerial: that.cameraSerialNumber,
							channelNo: that.cameraChannelNumber,
							direction:num,
							speed: 1,
						},
						header: {
							'Content-Type': 'application/x-www-form-urlencoded',
						},
					    success: (res) => {
					        console.log(res);
					    }
					});
				}, 500);
			},
			
			ytControlStop(num){
				let that = this;
				clearTimeout(that.timer1);
				that.timer1 = setTimeout(() => {
					uni.request({
						url:'https://open.ys7.com/api/lapp/device/ptz/stop',
						method: 'POST',
						data:{
							accessToken: that.accesstoken,
							deviceSerial: that.cameraSerialNumber,
							channelNo: that.cameraChannelNumber,
							direction:num,
							speed: 1,
						},
						header: {
							'Content-Type': 'application/x-www-form-urlencoded',
						},
						success: (res) => {
						    console.log(res);
						}
					})
				}, 500);
				
			},
			
			ytControl1(num){
				this.directionFlag = 0
				this.ytControl(num)
			},
			ytControl2(num){
				this.directionFlag = 1
				this.ytControl(num)
			},
			ytControl3(num){
				this.directionFlag = 2
				this.ytControl(num)
			},
			ytControl4(num){
				this.directionFlag = 3
				this.ytControl(num)
			},
			
			// 焦距-放大
			ytControlFocusAdd(num){
				this.flag1 = true;
				this.ytControl(num)
				
			},
			ytControlStopFocusAdd(num){
				this.ytControlStop(num);
			},
			
			// 焦距-缩小
			ytControlFocusSubtract(num){
				this.flag1 = false;
				this.ytControl(num)
				
			},
			ytControlStopFocusSubtract(num){
				this.ytControlStop(num);
			},
			
			// 缩放-放大
			ytControlScaleAdd(num){
				this.flag2 = true;
				this.ytControl(num)
			},
			ytControlStopScaleAdd(){
				this.ytControlStop(num);
			},
			
			// 缩放-缩小
			ytControlScaleSubtract(num){
				this.flag2 = false;
				this.ytControl(num)
			},
			ytControlStopScaleSubtract(num){
				this.ytControlStop(num);
			},
		}
	}
</script>

<style lang="scss" scoped>
.videoLive{
	width: 100%;
	min-height: 100vh;
	background-color: #F5F6FA;
	
	.center{
		
		.video_live{
			width: 750rpx;
			height: 970rpx;
			>image{
				width: 100%;
				height: 100%;
			}
		}
		
		.skills{
			width: 100%;
			box-sizing: border-box;
			padding: 61rpx 0 0 40rpx;
			display: flex;
			
			.left{
				width: 340rpx;
				height: 340rpx;
				position: relative;
				margin-right: 60rpx;
				
				.left_arrow,.right_arrow{
					width: 15rpx;
					height: 28rpx;
				}
				
				.up_arrow,.down_arrow{
					width: 27rpx;
					height: 15rpx;
				}
				
				.arrow_item{
					width: 51rpx;
					height: 51rpx;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					
				}
				
				.arrow_item_act{
					width: 51rpx;
					height: 51rpx;
					background: #24B383;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				
				.left_arrow_item{
					position: absolute;
					top: 145rpx;
					left: 29rpx;
				}
				
				.right_arrow_item{
					position: absolute;
					top: 145rpx;
					right: 29rpx;
				}
				
				.up_arrow_item{
					position: absolute;
					top: 29rpx;
					left: 146rpx;
				}
				
				.down_arrow_item{
					position: absolute;
					bottom: 28rpx;
					left: 145rpx;
				}
				
				>image{
					width: 100%;
					height: 100%;
				}
			}
		
			.right{
				box-sizing: border-box;
				padding-top: 10rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				
				.right_item{
					width: 240rpx;
					height: 80rpx;
					background: #EFFAF6;
					border: 2px solid rgba(36,179,131,0.35);
					border-radius: 40rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					box-sizing: border-box;
					padding: 7rpx;
					margin-bottom: 40rpx;
					
					.add{
						width: 66rpx;
						height: 66rpx;
						background: #EFFAF6;
						border-radius: 50%;
						display: flex;
						align-items: center;
						justify-content: center;
						
						>image{
							width: 38rpx;
							height: 38rpx;
						}
					}
					.add_act{
						width: 66rpx;
						height: 66rpx;
						background: #24B383;
						border-radius: 50%;
						display: flex;
						align-items: center;
						justify-content: center;
						
						>image{
							width: 38rpx;
							height: 38rpx;
						}
					}
					
					.focus{
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #24B383;
					}
					
					.subtract{
						width: 66rpx;
						height: 66rpx;
						background: #EFFAF6;
						border: 2px solid rgba(36,179,131,0.35);
						border-radius: 50%;
						display: flex;
						align-items: center;
						justify-content: center;
						
						>image{
							width: 38rpx;
							height: 8rpx;
						}
					}
					.subtract_act{
						width: 66rpx;
						height: 66rpx;
						background: #24B383;
						border: 2px solid rgba(36,179,131,0.35);
						border-radius: 50%;
						display: flex;
						align-items: center;
						justify-content: center;
						
						>image{
							width: 38rpx;
							height: 8rpx;
						}
					}
				}
			}
		}
	}
}
</style>
