<template>
    <div ref="share">
        <van-overlay :show="show" @click="show = false" z-index="99">
            <div class="wrapper">
                <div class="img" ref="wrap"></div>
                <div class="content" v-if="!img" ref="post" @click.stop>
                    <van-image
                        :src="getImg(info.pics || info.pic)"
                        width="80vw"
                        height="80vw"
                        fit="cover"
                        @load="loadImg"
                    />
                    <div class="info">
                        <div class="name van-multi-ellipsis--l2">
                            {{ info.name }}
                        </div>
                        <div class="text">
                            <div class="price">
                                <img src="../assets/svgs/jiage.svg" alt="" />
                                <span>{{ info.price }}</span>
                            </div>
                            <div class="text1" v-if="info.stock">
                                <span>已售 {{ info.sale }}</span>
                                <span>剩余 {{ info.stock }}</span>
                            </div>
                        </div>
                    </div>
                    <div class="minter">
                        <div class="minter-content">
                            <van-image width="30" height="30" round :src="info.minterAvatar" fit="cover" />
                            <div class="text1">{{ info.minter }}</div>
                            <div class="text2">铸造者</div>
                        </div>

                        <vue-qrcode :value="url" :options="{ width: 70, margin: 2 }" class="code"></vue-qrcode>
                    </div>
                </div>

                <div class="tips">长按图片保存</div>
            </div>
        </van-overlay>
        <!-- <div class="share" @click="init">
      <img src="../assets/svgs/icon-share.svg" alt="" />
      <span>分享</span>
    </div> -->
    </div>
</template>
<script>
import vueQrcode from '@chenfengyuan/vue-qrcode';
import html2canvas from 'html2canvas';
const path = require('path');
export default {
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        },
        pageUrl: {
            type: String,
            default: 'productDetail'
        }
    },
    data() {
        return {
            show: false,
            share: null,
            img: false
        };
    },
    computed: {
        url() {
            return path.resolve(this.$baseUrl, this.pageUrl + '?id=' + this.info.id);
        }
    },
    components: {
        vueQrcode
    },
    methods: {
        init() {
            if (!this.img) {
                this.$toast.loading({
                    message: '加载中...',
                    forbidClick: true
                });
            }

            this.show = true;
        },
        loadImg() {
            setTimeout(() => {
                html2canvas(this.$refs.post).then(canvas => {
                    this.$toast.clear();
                    this.$refs.wrap.appendChild(canvas);
                    this.$nextTick(() => {
                        this.img = true;
                    });
                });
            }, 100);
        }
    }
};
</script>
<style lang="less" scoped>
.wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    height: 100%;
}

.content {
    width: 80vw;
    background: #19191b;
    border-radius: 8px;
}

.img {
    /deep/ canvas {
        overflow: hidden;
        border-radius: 8px;
        display: block;
    }
}

.info {
    padding: 12px 10px;
    .name {
        font-size: 18px;
        font-weight: bold;
        color: #ffffff;
        line-height: 24px;
    }
    .text {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        margin-top: 6px;

        .price {
            span {
                font-size: 32px;
                font-family: OSP-DIN, OSP;
                color: #fdfb60;
                line-height: 36px;
            }
        }
        .text1 {
            font-size: 14px;
            color: #939599;
            line-height: 24px;
            span + span {
                margin-left: 10px;
            }
        }
    }
}

.code {
    border-radius: 6px;
}

.minter {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 10px;
    border-top: 2px solid #202122;

    .minter-content {
        .text1 {
            font-size: 14px;
            color: #ffffff;
            line-height: 24px;
            margin-top: 6px;
        }
        .text2 {
            font-size: 12px;
            color: #939599;
            line-height: 22px;
        }
    }
}

.tips {
    font-size: 13px;
    color: #939599;
    line-height: 22px;
    margin-top: 16px;
}

.share {
    position: fixed;
    right: 16px;
    bottom: 20vh;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #fdfb60 0%, #ff8f3e 100%);
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 100px;
    justify-content: center;
    span {
        font-size: 12px;
        color: #333230;
        line-height: 17px;
    }
    img {
        display: block;
    }
}
</style>
