<!--
 Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

 https://www.mall4j.com/

 未经允许，不可做商业用途！

 版权所有，侵权必究！
-->
<template>
  <div>
    <div class="video-upload-components">
      <div
        tabindex="0"
        class="el-upload el-upload--text"
        @click.prevent.stop="videoboxHandle"
      >
        <video
          v-if="value"
          ref="myVideo"
          class="video"
          :src="addDomain(value)"
          controls="controls"
        />
        <el-icon
          v-else
          class="el-icon-plus pic-uploader-icon"
        >
          <Plus />
        </el-icon>
      </div>
    </div>
    <!-- 弹窗, 新增视频 -->
    <video-box
      v-if="videoboxVisible"
      ref="videoboxRef"
      @refresh-pic="refreshPic"
    />
  </div>
</template>

<script setup>
const Data = reactive({
  videoboxVisible: false
})

const { videoboxVisible } = toRefs(Data)

defineProps({
  value: {
    default: '',
    type: String
  },
  disabled: {
    default: false,
    type: Boolean
  }
})

const emit = defineEmits(['update:value'])

const videoboxRef = ref(null)
// 打开视频选择窗
const videoboxHandle = () => {
  if (Data.disabled) {
    return false
  }
  Data.videoboxVisible = true
  nextTick(() => {
    videoboxRef.value.init(1)
  })
}
const refreshPic = (imagePath) => {
  emit('update:value', imagePath)
}
</script>

<style lang="scss" scoped>
.video-upload-components {
  display: inline-block;
  width: auto;
  .el-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 120px;
    max-width: 300px;
    height: auto;
    min-height: 120px;
    max-height: 250px;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    .pic-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: auto;
      height: auto;
      // width: 120px;
      // height: 120px;
      // line-height: 120px;
      text-align: center;
    }
    .video {
      width: auto;
      max-width: 300px;
      // height: 120px;
      height: auto;
      max-height: 250px;
      display: block;
    }
    .el-upload:hover {
      border-color: #409eff;
    }
  }
}
</style>
