<template>
    <ul class="img-thumbanail-wrap">
        <li class="img-item" v-for="(img,index) in _.cloneDeep(this.imgList).reverse()" :key="index" @click="showImage(img)">
            <img :src="img" />
            <span class="mask">
                <span
                    class="mask-icon"
                    @click.stop="deleteImg(img)"
                >
                    <i class="el-icon-delete"></i>
                </span>
            </span>
        </li>
    </ul>
</template>

<script>
import _ from "lodash";
export default {
    props:{
        imgList:{
            type:Array,
            default:()=>{return []}
        }
    },
    data() {
        return {
            showList:_.cloneDeep(this.imgList).reverse()
        };
    },
    methods: {
        deleteImg(img){
            //数组是逆序过的，需要找到正确的index
            const index = this.imgList.findIndex(i=>i===img)||0
            this.$emit('deleteImg',index)
        },
        showImage(img){
            this.$emit('showImage',{list:this.imgList,item:img})
        }
    },
};
</script>

<style scoped lang="scss">
.img-thumbanail-wrap{
    display: flex;
    width:280px;
    gap:20px;
    margin-left: 20px;
    .img-item{
        position:relative;
        width:120px;
        height: 120px;
        background-color: #F5F7F9;
        border: 1px dashed #DCDFE6;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        padding:4px;
        overflow: hidden;
        img,.mask{
            width:100%;
            height:100%;
        }
        &:hover{
            border: 1px dashed #3375e1;
            .mask {
                opacity: 1;
            }
        }
        .mask {
            position: absolute;
            left: 0;
            top: 0;
            cursor: default;
            text-align: center;
            color: #fff;
            opacity: 0;
            font-size: 20px;
            background-color: rgba(0, 0, 0, .5);
            transition: opacity .3s;
            z-index: 2;
            line-height: 120px;
            .mask-icon {
                cursor: pointer;
            }
        }
    }
}
</style>
