<template>
    <van-overlay :show="show" z-index="99" @click="show = false">
        <div class="content" @click.stop="open">
            <img class="bg" ref="bg" src="@assets/open1.png" alt="" />

            <div class="box">
                <img class="img1" src="@assets/box1.png" alt="" />
                <img class="img2" ref="img2" src="@assets/box2.png" alt="" />
                <img class="img3" ref="img3" src="@assets/png-kapian.png" alt="" />
                <!-- <img class="guang" src="@assets/png-guang.png" alt="" /> -->
            </div>

            <div class="product" ref="product">
                <img class="productBg" src="@assets/png-cangping-bg.png" alt="" />
                <img class="productImg" :src="imgSrc" />
            </div>

            <div class="text1" v-if="!showProduct">点击打开盲盒</div>

            <div class="text" v-else>藏品正在生成中<br />约1~3分钟，完成后会出现在你的藏品室</div>

            <img src="@assets/icon_fenxiang_close.png" @click="show = false" alt="" class="close" />
        </div>
    </van-overlay>
</template>

<script>
export default {
    props: {
        imgSrc: {
            type: String,
            defalut: ''
        },
        id: {
            type: Number,
            defalut: 0
        },
        page: {
            type: String,
            defalut: 'order'
        }
    },
    data() {
        return {
            show: false,
            showProduct: false
        };
    },
    methods: {
        open() {
            if (this.page === 'order') {
                this.$http.post('/order/open?id=' + this.id);
            } else {
                this.$http.post('/asset/open?id=' + this.id);
            }
            this.addClass('img2', 'animate__rollOut', false)
                .then(() => {
                    return this.addClass('img3', 'animate__bounceOutUp', false);
                })
                .then(() => {
                    setTimeout(() => {
                        this.addClass('bg', 'bg1');
                    }, 300);
                    return this.addClass('product', 'animate__bounceInDown', true);
                })
                .then(() => {
                    this.showProduct = true;
                    this.$emit('getProduct');
                });
        }
        //组件名，动画名，展示（true:出现，false:消失）
    }
};
</script>

<style lang="less" scoped>
.content {
    position: absolute;
    width: 100vw;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    .flex-col();
    align-items: center;
    justify-content: center;

    .bg {
        width: 100%;
        display: block;
        transition: transform ease-in-out 0.3s;
        &.bg1 {
            transform: scale(2);
        }
    }

    .text {
        text-align: center;
        font-size: 12px;
        color: @text3;
        line-height: 17px;
        margin-top: 60px;
    }

    .text1 {
        font-size: 12px;
        color: @text3;
        line-height: 17px;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: 100px;
        z-index: 3;
    }

    .close {
        width: 40px;
        height: 40px;
        margin-top: 30px;
        position: relative;
        z-index: 5;
    }
}

.box {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    .img1 {
        width: 280px;
        display: block;
    }
    .img2 {
        width: 280px;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 3;
    }
    .guang {
        width: 280px;
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 1;
    }
    .img3 {
        width: 66px;
        height: 130px;
        position: absolute;
        left: calc(50% - 33px);
        top: calc(40% - 65px);
        z-index: 2;
        opacity: 0;
    }
}

.product {
    position: fixed;
    left: 0;
    top: calc(40% - 450 / 375 * 50vw);
    display: none;
    .productBg {
        width: 100vw;
        display: block;
    }
    .productImg {
        width: 280/375 * 100vw;
        height: 280/375 * 100vw;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        top: 106/375 * 100vw;
        border-radius: 30px;
        object-fit: cover;
    }
}

.animate__rollOut {
    animation: rollOut ease-in-out 0.8s;
}

@keyframes rollOut {
    0% {
        opacity: 1;
    }
    to {
        opacity: 0;
        -webkit-transform: translate3d(100%, 0, 0) rotate(120deg);
        transform: translate3d(100%, 0, 0) rotate(120deg);
    }
}

.animate__bounceOutUp {
    animation: bounceOutUp ease-in-out 0.8s;
}

@keyframes bounceOutUp {
    20% {
        -webkit-transform: translate3d(0, -10px, 0) scaleY(0.585);
        transform: translate3d(0, -10px, 0) scaleY(0.585);
    }
    40%,
    45% {
        opacity: 1;
        -webkit-transform: translate3d(0, 20px, 0) scaleY(0.5);
        transform: translate3d(0, 20px, 0) scaleY(0.5);
    }
    to {
        opacity: 0;
        -webkit-transform: translate3d(0, -2000px, 0) scaleY(3);
        transform: translate3d(0, -2000px, 0) scaleY(3);
    }
}

.animate__bounceInDown {
    animation: bounceInDown ease-in-out 0.8s;
}

@keyframes bounceInDown {
    0%,
    60%,
    75%,
    90%,
    to {
        -webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }
    0% {
        opacity: 0;
        -webkit-transform: translate3d(0, -3000px, 0) scaleY(3);
        transform: translate3d(0, -3000px, 0) scaleY(3);
    }
    60% {
        opacity: 1;
        -webkit-transform: translate3d(0, 25px, 0) scaleY(0.9);
        transform: translate3d(0, 25px, 0) scaleY(0.9);
    }
    75% {
        -webkit-transform: translate3d(0, -10px, 0) scaleY(0.95);
        transform: translate3d(0, -10px, 0) scaleY(0.95);
    }
    90% {
        -webkit-transform: translate3d(0, 5px, 0) scaleY(0.985);
        transform: translate3d(0, 5px, 0) scaleY(0.985);
    }
    to {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

.animate__heartBeat {
    animation: heartBeat ease-in-out 0.8s;
}
@keyframes heartBeat {
    0% {
        -webkit-transform: scale(1);
        transform: scale(1);
    }
    14% {
        -webkit-transform: scale(1.3);
        transform: scale(1.3);
    }
    28% {
        -webkit-transform: scale(1);
        transform: scale(1);
    }
    42% {
        -webkit-transform: scale(1.3);
        transform: scale(1.3);
    }
    70% {
        -webkit-transform: scale(1);
        transform: scale(1);
    }
}
</style>
