<template>
  <div class="d-flex flex-wrap">
    <div v-for="(item, index) in fileList" :key="item.id" class="h-files">
      <div class="h-wrap" @click="handleShowImage(index)">
        <a-icon type="eye" :style="{ color: 'rgba(255, 255, 255, .8)', fontSize: '30px' }" />
      </div>
      <el-image ref="ElImageRef" :src="item.url" :preview-src-list="previewImageList" class="h-image" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'HImage',
  data() {
    return {
      fileList: [
        { id: '1', url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg' },
        { id: '2', url: 'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg' },
        { id: '3', url: 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg' },
        { id: '4', url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg' },
        { id: '5', url: 'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg' },
        { id: '6', url: 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg' },
        { id: '7', url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg' },
        { id: '8', url: 'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg' },
        { id: '9', url: 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg' }
      ],

      previewImageList: [
        'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
        'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
        'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
      ]
    }
  },
  methods: {
    handleShowImage(index) {
      this.$refs.ElImageRef[index].clickHandler()
    }
  }
}
</script>

<style lang="scss" scoped>
.h-files {
  width: 103px;
  height: 103px;
  margin-right: 12px;
  margin-bottom: 12px;
  cursor: pointer;
  position: relative;

  .h-wrap {
    position: absolute;
    width: 103px;
    height: 103px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .h-image {
    width: 100%;
    height: 100%;
    border-radius: 8px;
  }

  &:hover {
    .h-wrap {
      z-index: 999;
      background-color: rgba(0, 0, 0, 0.57);
    }
  }
}
</style>
