<template>
  <div class="upload-demo" :style="{
    'border': `1px dashed ${borderColor}`,
    'background-color': `${backgroundColor}`
  }">
    <div class="flex-center flex-col relative" style="height: 270px;" v-if="fileList.length == 0">
      <div class="h-b100 overflow-hidden">
        <img src="https://res.volccdn.com/obj/volc-console-fe/dramart/static/image/PIC3.22e42366.png"
            class="w-b100 h-b100 object-cover" />
      </div>
      <div class="absolute bottom-0 left-0 top-0 w-b100 flex-center rounded-14 bg-099">
        <el-button class="mt-20" round :icon="Upload" @click="fileList=[]">重新上传</el-button>
      </div>
    </div>
    <el-upload v-else :show-file-list="false" :accept="accept" drag
      action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15">
      <slot />
    </el-upload>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { Upload } from '@element-plus/icons-vue'


const emit = defineEmits(['changeFiles'])
const props = defineProps({
  borderColor: {
    type: String,
    default: '#ddd'
  },
  backgroundColor: {
    type: String,
    default: '#fff'
  },
  showFileList: {
    type: Boolean,
    default: false
  },
  accept: {
    type: String,
    default: 'img'
  }
})

const fileList = ref([])

</script>
<style scoped lang="scss">
.upload-demo {
  border-radius: 16px;
  transition: all 0.2s;

  :deep(.el-upload) {
    border: 2px dashed #ddd;
    width: 100%;
    height: 240px;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s;

    &:hover {
      border-color: #c5c5c5;
    }
  }
  
  :deep(.el-upload-dragger) {
    background-color: transparent;
    border: none;
  }

  .el-upload__text {
    color: #00000063;
  }
  .bg-099 {
    background-color: #00000020;
  }
}
</style>