<template>
    <router-link
        :to="{
            path: '/productDetail',
            query: {
                collectionId: info.id
            }
        }"
    >
        <div class="shop_list">
            <!-- 未售完 -->
            <div class="not_sold_out" v-if="time && info.scheduleSale">
                <img :src="require('@assets/info_icon_shijian.png')" alt="" class="not_sold_out_img" />
                <div>即将开售: {{ startTime || time }}</div>
            </div>
            <!-- 已售完 -->
            <div class="shop_sold_out" v-if="isSolded">已售罄</div>
            <!-- 即将售罄 -->
            <div class="shop_sold_out" v-else-if="isSold">即将售罄</div>
            <!-- <img :src="getImg(changeImgs(info.pic, 600))" alt="" class="commodity_map" /> -->
            <van-image width="100%" height="343px" :radius="20" :src="getImg(changeImgs(info.pic))" fit="cover" />
            <div class="shop_title">{{ info.name }}</div>
            <div class="shop_number">
                <div class="limit">限量</div>
                <div class="number_of_copies">{{ info.total }}份</div>
                <div class="collection" v-if="info.category !=''">{{info.category}}</div>
            </div>
            <div class="shop_bottom">
                <div class="shop_bottom_left">
                    <!-- <img :src="getImg(info.minterAvatar)" alt="" class="shop_bottom_left_img" /> -->
                    <van-image width="18px" height="18px" :radius="18" :src="getImg(info.minterAvatar)" fit="cover"/>
                    <div class="shop_bottom_left_name">{{ info.minter }}</div>
                </div>
                <div class="shop_bottom_right">
                    <div class="shop_bottom_right_con">￥</div>
                    <div class="shop_bottom_right_price">{{ info.price }}</div>
                </div>
            </div>
        </div>
    </router-link>
</template>

<script>
import product from '../../mixins/product';
export default {
    mixins: [product],
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        },
        type: {
            type: String,
            default: 'collection'
        }
    },
    computed: {
        time() {
            if (this.info.startTime) {
                if (this.dayjs().isSameOrBefore(this.info.startTime, 'YYYY-MM-DD HH:mm:ss')) {
                    return this.dayjs(this.info.startTime).format('MM月DD日');
                }
            }

            return '';
        }
    },
    mounted() {
        if (this.info.startTime) {
            var x = this.dayjs(this.info.startTime, 'YYYY-MM-DD HH:mm:ss');
            var y = this.dayjs();
            let d = this.dayjs.duration(x.diff(y));
            let day = parseInt(d.asDays());
            if (day <= 0) {
                this.getTime(this.info.startTime);
            }
        }
    },
    methods: {
        likeProduct() {
            if (!this.info.liked) {
                this.$http.get(`/collection/${this.info.id}/like`).then(() => {
                    this.$emit('update:info', {
                        ...this.info,
                        liked: true,
                        likes: this.info.likes + 1
                    });
                    this.$toast.success('收藏成功');
                });
            } else {
                this.$http.get(`/collection/${this.info.id}/unlike`).then(() => {
                    this.$emit('update:info', {
                        ...this.info,
                        liked: false,
                        likes: this.info.likes - 1
                    });
                    this.$toast.success('取消收藏');
                });
            }
        }
    }
};
</script>

<style lang="less" scoped>
.shop_list {
    width: 100%;
            height: 455px;
            background: #29293f;
            border-radius: 20px;
            margin-bottom: 20px;
            position: relative;
            .not_sold_out {
                width: 136px;
                height: 24px;
                background: #ffffff;
                border-radius: 4px;
                line-height: 24px;
                font-size: 12px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #28b6ff;
                display: flex;
                position: absolute;
                top: 16px;
                left: 16px;
                .not_sold_out_img {
                    width: 18px;
                    height: 18px;
                    margin: 3px 3px 0 10px;
                }
            }
            .shop_sold_out {
                width: 68px;
                height: 24px;
                background: #ffffff;
                border-radius: 4px;
                font-size: 12px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #939599;
                line-height: 24px;
                text-align: center;
                position: absolute;
                top: 16px;
                left: 16px;
                z-index: 99;
            }
            .commodity_map {
                width: 100%;
                height: 343px;
                border-radius: 30px;
            }
            .shop_title {
                margin-bottom: 6px;
                padding: 10px 16px 6px 16px;
                box-sizing: border-box;
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #ffffff;
            }
            .shop_number {
                padding: 0 16px;
                box-sizing: border-box;
                display: flex;
                .limit {
                    width: 44px;
                    height: 22px;
                    background: #28b6ff;
                    border-radius: 4px 0px 0px 4px;
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #ffffff;
                    line-height: 22px;
                    text-align: center;
                }
                .number_of_copies {
                    // width: 96px;
                    padding: 0px 10px;
                    box-sizing: border-box;
                    height: 22px;
                    background: rgba(255, 255, 255, 0.1);
                    border-radius: 0px 4px 4px 0px;
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #28b6ff;
                    line-height: 22px;
                    text-align: center;
                }
                .collection {
                    width: 56px;
                    height: 22px;
                    background: rgba(255, 255, 255, 0.1);
                    border-radius: 4px;
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #28b6ff;
                    margin-left: 10px;
                    line-height: 22px;
                    text-align: center;
                }
            }
            .shop_bottom {
                padding: 0 16px;
                margin-top: 10px;
                box-sizing: border-box;
                display: flex;
                justify-content: space-between;
                .shop_bottom_left {
                    display: flex;
                    padding-top: 5px;
                    box-sizing: border-box;
                    .shop_bottom_left_name {
                        font-size: 12px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #939599;
                        margin-left: 6px;
                    }
                }
                .shop_bottom_right {
                    display: flex;
                    position: relative;
                    .shop_bottom_right_con {
                        font-size: 12px;
                        font-family: PingFangSC-Medium, PingFang SC;
                        font-weight: 500;
                        color: #ffffff;
                        position: absolute;
                        bottom: 3px;
                        left: -12px;
                    }
                    .shop_bottom_right_price {
                        font-size: 20px;
                        font-family: PingFangSC-Medium, PingFang SC;
                        font-weight: 500;
                        color: #ffffff;
                    }
                }
            }    
}
</style>
