<script lang="ts">
export default {
  name: 'editvideo' //控制摄像机
};
</script>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import axios from 'axios';
import JessibucaPlayer from '@/components/jessibuca/index1.vue'
import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();
const videoUrl = ref("")
const props = defineProps({
  rowInfo: {
    required: false,
    type: Object,
    default: false
  },
  online: {
    required: false,
    type: String,
    default: false
  },
  
});
const controSpeed = ref(100) // 摄像头转动速度默认值 30
function ptzCamera(command: any) { // 监控视频控制方法
  isGaoliang.value = command
  if(props.online != "1"){
     return
  }
  if(channelId.value == "" || channelId.value== undefined){
    ElMessage({
        type: 'error',
        message: '暂时无法调试，请先检查视频监控是否正常！',
    })
    return
  }
  axios.get(userStore.webApiBaseUrl + '/basedata/substation-patroldevice/isWorkingOfPatrolDevice?stationcode=' + userStore.stationCode + "&devicecode=" + deviceId.value, {}).then((res: any) => {
    if(res.data.data == "0"){
      axios.post(userStore.webApiMonitorUrl + '/api/ptz/control/' + deviceId.value + '/' + channelId.value + '?command=' + command +
      '&horizonSpeed=' + controSpeed.value + '&verticalSpeed=' + controSpeed.value + '&zoomSpeed=' + controSpeed.value, {}).then((res: any) => { })
    }
  })
  
}
function condensationChang(command: any) { // 光聚方法  
  const cmdCode = ref(65)
  if (command == '加') {
    cmdCode.value = 65
    isGaoliang.value = '65'
  } else if (command == '减') {
    isGaoliang.value = '66'
    cmdCode.value = 66
  }
  if(props.online != "1"){
     return
  }
  if(channelId.value == "" || channelId.value== undefined){
    ElMessage({
      type: 'error',
      message: '暂时无法调试，请先检查视频监控是否正常！',
    })
    return
  }
  // 近（42H ）    66    远（41H） 65
  axios.get(userStore.webApiBaseUrl + '/basedata/substation-patroldevice/isWorkingOfPatrolDevice?stationcode=' + userStore.stationCode + "&devicecode=" + deviceId.value, {}).then((res: any) => {
    if(res.data.data == "0"){
      axios.post(userStore.webApiMonitorUrl + '/api/ptz/front_end_command/' + deviceId.value + '/' + channelId.value + '?cmdCode=' + cmdCode.value + '&parameter1=80&parameter2=0&combindCode2=0', {}).then((res: any) => { })
    }
  })
  
}
function apertureChang(command: any) { // 光圈方法
  // 缩小（48H ）    72    放大（44H） 70
  const cmdCode = ref(72)
  if (command == '加') {
    cmdCode.value = 70
    isGaoliang.value = '70'
  } else if (command == '减') {
    cmdCode.value = 72
    isGaoliang.value = '72'
  }
  if(props.online != "1"){
     return
  }
  if(channelId.value == "" || channelId.value== undefined){
    ElMessage({
        type: 'error',
        message: '暂时无法调试，请先检查视频监控是否正常！',
    })
    return
  }

 
  axios.get(userStore.webApiBaseUrl + '/basedata/substation-patroldevice/isWorkingOfPatrolDevice?stationcode=' + userStore.stationCode + "&devicecode=" + deviceId.value, {}).then((res: any) => {
    if(res.data.data == "0"){
      axios.post(userStore.webApiMonitorUrl + '/api/ptz/front_end_command/' + deviceId.value + '/' + channelId.value + '?cmdCode=' + cmdCode.value + '&parameter1=0&parameter2=80&combindCode2=0', {}).then((res: any) => { })
    }
  })
}
function videoRefresh(){
  videoUrl.value =  videoUrl.value +'?Math=' + Math.random()
}
const beforehandPosition = ref(1)
function presetPosition(cmdCode: any, presetPos: any) { // 预置位操作 ---设置、删除、调用
  if (props.online != "1") {
    return
  }
  if (channelId.value == "" || channelId.value == undefined) {
    ElMessage({
      type: 'error',
      message: '暂时无法调试，请先检查视频监控是否正常！',
    })
    return
  }
  axios.get(userStore.webApiBaseUrl + '/basedata/substation-patroldevice/isWorkingOfPatrolDevice?stationcode=' + userStore.stationCode + "&devicecode=" + deviceId.value, {}).then((res: any) => {
    if (res.data.data == "0") {
      axios.post(userStore.webApiMonitorUrl + '/api/ptz/front_end_command/' + deviceId.value + '/' + channelId.value + '?cmdCode=' + cmdCode + '&parameter1=0&parameter2=' + presetPos + '&combindCode2=0', {}).then((res: any) => { })
    }
  })

}
const deviceId = ref("")
const channelId = ref("")
const videofmp4 = ref('')
onMounted(() => {
  if(props.rowInfo.deviceId == undefined){
    deviceId.value = props.rowInfo.deviceid
    channelId.value = props.rowInfo.channelid
  }else{
    deviceId.value = props.rowInfo.deviceId
    channelId.value = props.rowInfo.channelId
  }
  axios.get(userStore.webApiMonitorUrl + '/api/play/start/' + deviceId.value + '/' + channelId.value, {}).then((ress: any) => {
    if (ress.data.data != undefined) {
      videoUrl.value = ress.data.data.ws_flv
      videofmp4.value = ress.data.data.fmp4
      }
  }).catch(function (error: any) {
  })
})
const isGaoliang:any =ref("")
function quxiao(){
  isGaoliang.value = ''
}
</script>
<template>
  <div class="editvideo-box">
    <div style="width: 98%; height: calc(100vh - 350px);  margin: auto;">
      <JessibucaPlayer  :isClose="false" :_uid="'editvideo1'" :visible.sync="true" :videoUrl="videoUrl" :videofmp4="videofmp4"
      :hasAudio="false" fluent autoplay live ></JessibucaPlayer>
    </div>
    <div class="Camera-buttons-box">
      <div class="Camera-left-buttons">
        <div class="Camera-left-button1" @mousedown="ptzCamera('up')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button2" @mousedown="ptzCamera('upright')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button3" @mousedown="ptzCamera('right')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button4" @mousedown="ptzCamera('downright')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button5"  @mousedown="ptzCamera('down')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button6" @mousedown="ptzCamera('downleft')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button7" @mousedown="ptzCamera('left')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button8"  @mousedown="ptzCamera('upleft')" @mouseup="ptzCamera('stop')"></div>
        <div class="Camera-left-button9"  @mousedown="presetPosition(130, beforehandPosition)"></div> 
      </div>
      <div class="Camera-right-buttons">
        <div class="focallengthbox">
          <div class="focallength1" :class="{'gaolaing': isGaoliang=='zoomout'}" @mousedown="ptzCamera('zoomout')" @mouseup="ptzCamera('stop')">
            <img src="@/assets/videoimg/left.png" style="width:8px;height:12px" alt="">
          </div>
          <div class="focallength2">缩放</div>
          <div class="focallength1" :class="{'gaolaing': isGaoliang=='zoomin'}" @mousedown="ptzCamera('zoomin')" @mouseup="ptzCamera('stop')">
            <img src="@/assets/videoimg/right.png" style="width:8px;height:12px" alt="">
          </div>
        </div>
        <div class="focallengthbox">
          <div class="focallength1" :class="{'gaolaing': isGaoliang=='66'}" @mousedown="condensationChang('减')"  @mouseup="quxiao">
            <img src="@/assets/videoimg/left.png" style="width:8px;height:12px" alt="">
          </div>
          <div class="focallength2">光聚</div>
          <div class="focallength1" :class="{'gaolaing': isGaoliang=='65'}" @mousedown="condensationChang('加')"  @mouseup="quxiao">
            <img src="@/assets/videoimg/right.png" style="width:8px;height:12px" alt="">
          </div>
        </div>
        <div class="focallengthbox">
          <div class="focallength1" :class="{'gaolaing': isGaoliang=='72'}" @mousedown="apertureChang('减')"  @mouseup="quxiao">
            <img src="@/assets/videoimg/left.png" style="width:8px;height:12px" alt="">
          </div>
          <div class="focallength2">光圈</div>
          <div class="focallength1" :class="{'gaolaing': isGaoliang=='70'}" @mousedown="apertureChang('加')" @mouseup="quxiao">
            <img src="@/assets/videoimg/right.png" style="width:8px;height:12px" alt="">
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.Camera-buttons-box {
  display: flex;
  justify-content: center;
  align-items: center;

  .Camera-left-button1{
    cursor: pointer;
    position: absolute;
    top: 3px;
    left: 63px;
    width: 74px;
    height: 57px;
    background: url(@/assets/videoimg/sxj_1.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button2{
    cursor: pointer;
    position: absolute;
    top: 10px;
    left: 122px;
    width: 73px;
    height: 72px;
    background: url(@/assets/videoimg/sxj_2.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button3{
    cursor: pointer;
    position: absolute;
    top: 62px;
    left: 147px;
    width: 57px;
    height: 75px;
    background: url(@/assets/videoimg/sxj_3.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button4{
    cursor: pointer;
    position: absolute;
    top: 121px;
    left: 124px;
    width: 73px;
    height: 73px;
    background: url(@/assets/videoimg/sxj_4.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button5{
    cursor: pointer;
    position: absolute;
    top: 147px;
    left: 67px;
    width: 74px;
    height: 57px;
    background: url(@/assets/videoimg/sxj_5.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button6{
    cursor: pointer;
    position: absolute;
    top: 125px;
    left: 12px;
    width: 72px;
    height: 72px;
    background: url(@/assets/videoimg/sxj_6.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button7{
    cursor: pointer;
    position: absolute;
    top: 69px;
    left: 2px;
    width: 57px;
    height: 73px;
    background: url(@/assets/videoimg/sxj_7.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button8{
    cursor: pointer;
    position: absolute;
    top: 12px;
    left: 10px;
    width: 72px;
    height: 72px;
    background: url(@/assets/videoimg/sxj_8.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button9{
    cursor: pointer;
    position: absolute;
    top: 58px;
    left: 57px;
    width: 91px;
    height: 91px;
    background: url(@/assets/videoimg/sxj_9.png) no-repeat center center;
    background-size: 100% 100%;
  }

  .Camera-left-button1:hover{
    background: url(@/assets/videoimg/sxj_1.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_11.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button2:hover{
    background: url(@/assets/videoimg/sxj_2.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_21.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button3:hover{
    background: url(@/assets/videoimg/sxj_3.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_31.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button4:hover{
    background: url(@/assets/videoimg/sxj_4.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_41.png) no-repeat center center;
    background-size: 100% 100%;
  }

  .Camera-left-button5:hover{
    background: url(@/assets/videoimg/sxj_5.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_51.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button6:hover{
    background: url(@/assets/videoimg/sxj_6.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_61.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button7:hover{
    background: url(@/assets/videoimg/sxj_7.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_71.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button8:hover{
    background: url(@/assets/videoimg/sxj_8.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_81.png) no-repeat center center;
    background-size: 100% 100%;
  }
  .Camera-left-button9:hover{
    background: url(@/assets/videoimg/sxj_9.png) no-repeat center center;
    background: url(@/assets/videoimg/sxj_91.png) no-repeat center center;
    background-size: 100% 100%;
  }
}
.Camera-left-buttons {
    position: relative;
    width: 205px;
    height: 204px;
    height: 204px;
    margin-top:  20px;
    margin-left:  50px;
    margin-bottom: 10px;

    .Camera-left-input {
      width: 130px;
      height: 36px;
    }

    .Camera-left-button {
      width: 48px;
      height: 48px;
      // background-color: rgba(53, 222, 176,0.4);
      border: 1px solid rgba(0, 249, 162, 1);
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;

      .img {
        width: 12px;
        height: 12px;
      }
    }

    .Camera-left-button:hover {
      background-color: rgba(33, 191, 149, 0.2);
    }
  }
  .Camera-right-buttons {
    .focallengthbox{
      display: flex;
      padding-left: 40px;
      padding-top: 10px;
      .focallength1{
        border: 1px solid rgba(50, 177, 245,0.4);
        width: 40px;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items:center ;
        cursor: pointer;
      }
      .focallength2{
        pointer-events: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        border-top: 1px solid rgba(50, 177, 245,0.4);
        border-bottom: 1px solid rgba(50, 177, 245,0.4);
        width: 140px;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items:center ;
        font-size: 14px;
        color: #B5D7FF;
      }
    }
  }
  .gaolaing{
      background:rgba(50, 177, 245,0.4)
    }
</style>

