<template>
  <div class="image-item" @click="$emit('goDetail')">
    <img class="image" :src="imageUrl" alt="">
    <div class="info">
      <div class="info-subtitle">{{ imageName }}</div>
      <div class="info-title">{{ item.imageTitle }}</div>
      <div class="info-date">{{ item.uploadTime }}</div>
      <div class="info-tag">
        <div style="display: flex;width: 0;;flex: 1;">
          <el-tag size="small" >{{item.isOpen == 1 ? '公开':'私有'}}</el-tag>
          <el-tag size="small" v-if="item.keyWords" style="margin-left: 3px;">{{ item.keyWords }}</el-tag>
        </div>
        
        <el-button ref="addCart" type="info" icon="el-icon-shopping-cart-full" circle plain style="margin-left: 5px;font-size: 16px;" @click.stop="addToCart"></el-button>
    </div>
    </div>
    <el-tooltip class="item" effect="dark" v-if="item.exifInfo" placement="top">
      <div slot="content" style="max-width: 300px;">{{ item.exifInfo }}</div>
      <div class="info-extra">
        EXIF<i class="el-icon-warning-outline" style="margin-left: 3px;"></i>
      </div>
    </el-tooltip>
  </div>
</template>

<script>
export default {
  name: 'ImageItem',
  props: {
    item: {
      type: Object,
      default: () => ({})
    },
  },
  computed: {
    imageUrl() {
      let url = this.item.imagePath;
      if (this.item.file?.length > 0) {
        url = this.item.file[0].attachFileUrl || this.item.imagePath;
      }
      if (url.indexOf("http") === 0) {
          return url;
      }
      return process.env.VUE_APP_BASE_API + url;
    },
    imageName() {
      if (this.item.file?.length > 0) {
        return this.item.file[0].oldName || this.item.imageName;
      }
      return this.item.imageName;
    }
  },
  methods: {
    addToCart(e) {
      // console.log(this.$refs.addCart);
      const rect = this.$refs.addCart.$el.getBoundingClientRect();
      // console.log(e);
      this.$eventBus.$emit('addImageToCart', {
        item: this.item,
        x: rect.x + rect.width / 2,
        y: rect.y + rect.height / 2,
      });
    }
  }
}
</script>

<style lang="scss">
  .image-item {
    border-radius: 10px;
    box-shadow: 0px 0px 8px #999999;
    overflow: hidden;
    position: relative;

    .image {
      width: 100%;
      height: 200px;
    }

    .info {
      padding: 5px 10px 10px;

      .info-title {
        font-size: 18px;
        margin-top: 5px;
      }

      .info-subtitle {
        font-size: 14px;
        color: #999999;
      }

      .info-date {
        margin-top: 2px;
        font-size: 15px;
        color: #999999;
      }

      
    }

    .info-tag {
      margin-top: 4px;
      font-size: 16px;
      color: #409EFF;
      padding: 0 5px 4px;
      display: flex;
      align-items: flex-end;
    }

    .info-extra {
      position: absolute;
      top: 5px;
      right: 5px;
      font-size: 14px;
      padding: 2px 5px;
      border-radius: 5px;
      background-color: rgba(0, 0, 0, 0.5);
      color: #fff;

    }

  }
</style>