<template>
    <router-link
        :to="{
            path: '/productDetail',
            query: {
                id: info.id
            }
        }"
        class="product"
    >
        <van-image width="100%" height="calc(100vw - 32px)" :src="getImg(changeImgs(info.pic))" fit="cover" />

        <div class="content">
            <div class="name van-ellipsis">{{ info.name }}</div>
            <div class="sales">
                <span>限量</span>
                <span>{{ info.total }}份</span>
            </div>
            <div class="bottom">
                <div class="miner">
                    <van-image width="18" height="18" radius="18" :src="getImg(info.minterAvatar)" fit="cover" />
                    <span>{{ info.minter }}</span>
                </div>
                <div class="flex1"></div>
                <div class="price">
                    <i class="font_family icon-icon_jiage"></i>
                    <span> {{ info.price }}</span>
                </div>
            </div>
        </div>

        <div class="xianliang" v-if="startTime">
            <img src="../../assets/shizhong.png" alt="" />
            <span>即将开售：{{ startTime }}</span>
        </div>
    </router-link>
</template>

<script>
import product from '../../mixins/product';
import dayjs from 'dayjs';
var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
dayjs.extend(isSameOrBefore);
export default {
    mixins: [product],
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    computed: {
        startTime() {
            if (this.info.startTime) {
                if (dayjs().isSameOrBefore(this.info.startTime)) {
                    return dayjs(this.info.startTime).format('MM月DD日');
                }
            }

            return '';
        }
    },
    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>
.product {
    width: calc(100vw - 32px);
    margin: 8px 16px;
    position: relative;
    background-color: #1c1e25;
    display: inline-block;
    border-radius: 12px;
    overflow: hidden;

    .xianliang {
        position: absolute;
        top: 16px;
        left: 16px;
        font-size: @font1;
        color: @prim;
        display: flex;
        align-items: center;
        img {
            width: 18px;
            height: 18px;
            margin-right: 3px;
        }
    }

    .van-image {
        display: block;
        position: relative;
        &::after {
            content: '';
            position: absolute;
            background-color: #00000030;
            top: 0;
            right: 0;
            left: 0;
            bottom: 0;
        }
    }
    .content {
        padding: 10px;
        .name {
            font-size: @font2;
            font-weight: bold;
            color: #ffffff;
            line-height: 24px;
        }

        .sales {
            border-radius: 4px;
            overflow: hidden;
            font-size: @font1;
            margin-top: 10px;

            span {
                padding: 0 10px;
                line-height: 20px;
                height: 20px;
                display: inline-block;
                &:first-child {
                    background: @prim;
                    color: @bg;
                }
                &:last-child {
                    background-color: #3d3d3a;
                    color: @prim;
                }
            }
        }

        .bottom {
            display: flex;
            margin-top: 10px;

            .miner {
                display: flex;
                align-items: center;

                span {
                    color: @text3;
                    font-size: @font1;
                    margin-left: 6px;
                }
            }

            .price {
                font-size: 24px;
                color: #fff;
                line-height: 22px;
                font-family: OSP;
                font-weight: bold;
                .font_family {
                    font-size: 11px;
                    margin-bottom: 3px;
                    vertical-align: middle;
                }
            }
        }
    }

    .text {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}
</style>
