<template>
    <social-share :config="shareConfig" v-if="info.id" />
</template>
<script>
import SocialShare from 'vue-social-share';
import resolveUrl from 'resolve-url';
import product from '../mixins/product';
export default {
    name: 'share',
    props: {
        isCasting: {
            type: Boolean,
            default: false
        },
        info: {
            type: Object,
            default: () => {
                return {};
            }
        },
        pageType: {
            type: String,
            default: 'collectionDetail'
        }
    },
    mixins: [product],
    components: {
        SocialShare
    },
    computed: {
        shareConfig() {
            return {
                url: resolveUrl(this.$baseUrl, '9th/' + this.pageType + '?id=' + this.info.id),
                title: this.shareTitle, // 标题，默认读取 document.title 或者 <meta name="title" content="share.js" />
                description: this.description, // 描述, 默认读取head标签：<meta name="description" content="PHP弱类型的实现原理分析" />
                image: this.image, // 图片, 默认取网页中第一个img标签
                sites: ['qq', 'wechat', 'weibo'], // 启用的站点
                disabled: [], // 禁用的站点
                wechatQrcodeTitle: '微信扫一扫',
                wechatQrcodeHelper: '<p>微信里点“+”，扫一扫</p>'
            };
        },
        shareTitle() {
            return this.pageType == 'collectionDetail'
                ? `收藏品——${this.info.name}`
                : this.pageType === 'castingDetail'
                ? `铸造者——${this.info.name}`
                : `收藏品——${this.info.name}`;
        },
        description() {
            return this.pageType == 'collectionDetail'
                ? `铸造者——${this.info.minter}`
                : this.pageType === 'castingDetail'
                ? this.info.intro
                : `铸造者——${this.info.minter}`;
        },
        image() {
            return this.pageType == 'collectionDetail'
                ? this.getImg(this.changeImgs(this.info.pic))
                : this.pageType === 'castingDetail'
                ? this.info.avatar
                : this.getImg(this.changeImgs(this.info.pic));
        }
    }
};
</script>
