<template>
  <div v-if="itemData.fileInfoList">
    <van-col span="6" v-for="(urls, index) in itemData.fileInfoList" :key="index">
      <div class="imgview2">
        <van-icon name="close" size="16" v-on:click="deleteImg(index, urls.id)" />
        <img :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)" />
      </div>
    </van-col>
  </div>
</template>

<script>
import { ImagePreview } from 'vant';
import { removeSummaryPhoto, removePhoto } from '@/api/index';

export default {
  name: 'deleteUploadImg',
  props: {
    itemData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
    };
  },
  methods: {
    deleteImg(index, id) {
      var fileName = {
        fileId: id,
      };
      removeSummaryPhoto(fileName).then((res) => {
        if (res.code == 200) {
          this.$toast('删除成功！');
          this.$emit('deleteImg', { itemData: this.itemData, index: index });
          // this.imgs.splice(index, 1);
        } else {
          this.$toast('删除失败！');
        }
      });
    },
    previewsImg(index) {
      var arrimg = [];
      for (var imgi = 0; imgi < this.itemData.fileInfoList.length; imgi++) {
        arrimg.push(this.itemData.fileInfoList[imgi].fileUrl);
      }
      ImagePreview({
        images: arrimg,
        startPosition: index,
        onClose() {
          // do something
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.imgview2 {
  height: 80px;
  width: 80px;
  padding: 3px;
  /* border: 1px solid #ccc; */
  height: 72px;
  position: relative;
  border-radius: 5px;
  display: inline-block;
  i {
    position: absolute;
    right: -2px;
    top: -3px;
    color: white;
    background: red;
    overflow: hidden;
    border-radius: 50%;
  }
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
