<template>
  <transition appear name="custom-classes-transition" leave-active-class="animated fadeOut faster">
    <div class="open-video">
      <!-- <div class="vmask"></div> -->
      <video :poster="require('@/assets/images/resource/poster.jpg')" muted autoplay x5-playsinline="true" playsinline="true" webkit-playsinline="true" class="video" ref="openvideo$" preload :src="videourl"></video>
      <div class="bfposter" v-if="bofanging" >
        <img :src="require('@/assets/images/resource/poster.jpg')" alt="">
      </div>

      <div v-show="videourl" @click.stop="emit('close')" class="jump">跳过</div>
      <img v-show="videourl && bofanging" @click.stop="bofang" class="bofang" :src="require('@/assets/images/icon/bofang.png')" alt="" />
    </div>
  </transition>
</template>
<script setup>
import { ref, watch, defineEmits, computed, onMounted, nextTick, defineProps } from "vue";

const openvideo$ = ref(null);

const videourl = ref(null);
const countdown = ref(3);

const timer = ref(null);


const bofanging = ref(true);

const emit = defineEmits(["close"]);

const bofang = () => {
  openvideo$.value.play();
};

onMounted(() => {
  nextTick(() => {
    videourl.value = require('@/assets/video/FZMopoo.mp4');

    openvideo$.value.addEventListener("ended", () => {
      emit("close");
    });

    openvideo$.value.addEventListener("playing", () => {
      if (bofanging.value) {
        bofanging.value = false;
      }
     
    });

    openvideo$.value.addEventListener("pause", () => {
      if (!bofanging.value) {
        bofanging.value = true;
      }
    });
    
    document.addEventListener(
      "WeixinJSBridgeReady",
      () => {
        openvideo$.value.play();
      },
      false
    );
  });
});
</script>
<style lang="scss" scoped>
.open-video {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: table;
  table-layout: fixed;
  z-index: 1100000;
  background-color: rgba(0, 0, 0, 1);

  .bofang {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    left: 50%;
    width: 80px;
    height: 80px;
    z-index: 999;
  }
  .bfposter {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    display: flex;
    align-items: center;
    z-index: 2;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    >img{
      width: 100%;
    }
  }
  .video {
    width: 100%;
    height: 100%;
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    position: relative;
    z-index: 9;
    object-fit: cover;
  }

@media only screen and (max-width: 800px) {
  .video {
    object-fit: contain;
  }
}
  .jump {
    position: absolute;
    cursor: pointer;
    right: 15px;
    top: 20px;
    background: #b7120f;
    text-align: center;
    line-height: 28px;
    font-size: 16px;
    z-index: 999;
    color: #fff;
    border-radius: 2px;
    padding: 4px 12px;
  }
}
</style>
