<template>
  <el-dialog v-model="visible" width="730px" :destroy-on-close="true">
    <template #title></template>
    <div style="height: 20px"></div>
    <div>
      <div class="player" style="height: 510px">
        <videoPlayer ref="videoplayer"></videoPlayer>
      </div>
    </div>
  </el-dialog>
</template>

<script>
// import videoPlayer from "@/components/videoPlayer.vue";

import videoPlayer from "@/views/videoSurveillance/newLayerContrl/components/videoPlayer.vue"
import { getVideoUrl } from "@/api/operation";
export default {
  components: { videoPlayer },
  props: {
    id: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      visible: false,
      url: null,
    };
  },
  watch: {
    id(newVal) {
      if (!newVal) {
        this.visible = false;
      } else {
        this.visible = true;
        this.initUrl();
      }
    },
  },
  methods: {
    initUrl() {
      const { id } = this;
      if (!id) {
        return;
      }
      getVideoUrl(id).then((res) => {
        const url = res.data;
        if (!url) {
          return;
        }
        this.url = url
        this.$refs.videoplayer.createPlayer(url, id);
      });
    },
  },
};
</script>
