<template>
    <div>
        <transition name="fade">
            <div class="alert" @touchstart.stop.prevent="" v-if="visible">

            </div>
        </transition>
        <transition name="fade">
            <div class="swiper-container" id='swiper' v-if="visible" @click="close">
                <div class="swiper-wrapper">
                    <div class="swiper-slide" v-for="(item,index) in list" :style="{backgroundImage:'url('+item.imageUrl+')'}">
                        <div class="tab">{{item.imageName}}</div>
                    </div>
                </div>
                <div class="swiper-pagination"></div>

                <img src="../../assets/icon_tancuang_close.png" class="close" alt="">
            </div>
        </transition>
    </div>
</template>
<script>
import swiper from 'swiper'
export default {
    mounted() {
        this.visible = true
        setTimeout(() => {
            this.mySwiper = new Swiper('#swiper', {
                pagination: '.swiper-pagination',
            })
            this.mySwiper.slideTo(this.index, 0, false);
        }, 100)
    },
    data() {
        return {
            list: [],
            index: 0,
            visible: false,
            mySwiper:null
        }
    },
    name: 'ShowPicture',
    methods: {
        cancel() {
            if (this.cancelFn) {
                this.cancelFn()
            }
            this.close()
        },
        confirm() {
            if (this.confirmFn) {
                this.confirmFn()
            }
            this.close()
        },
        close() {
            this.visible = false
            this.$el.addEventListener('transitionend', this.destroyView)
        },
        destroyView() {
            this.$el.removeEventListener('transitionend', this.destroyView)
            this.$destroy(true)
            this.$el.parentNode.removeChild(this.$el)
        }
    }
}
</script>
<style lang="less" scoped>
@import '../../swiper.css';
.alert {
    background: rgba(0, 0, 0, 0.8);
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
}
.swiper-container {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 550;

    .swiper-slide {
        background-size: contain;
        background-position: center center;
        background-repeat: no-repeat;
    }

    .tab {
        top: 0.2rem;
        left: 50%;
        transform: translateX(-50%);
        font-size: 0.28rem;
        background-color: transparent;
        color: #fff;
        line-height: 0.6rem;
    }

    .close {
        position: absolute;
        top: 0.2rem;
        right: 0.2rem;
        width: 0.6rem;
        height: 0.6rem;
    }
}
.fade-enter,
.fade-leave-active {
    opacity: 0;
}

.fade-enter-active,
.fade-leave-active {
    transition: all 0.5s;
}
</style>
