<template>
    <router-link
        :to="{
            path: '/collectionDetail',
            query: {
                id: info.id
            }
        }"
        class="content"
    >
        <el-image class="imgBox" :src="getImg(changeImgs(info.pics))" fit="cover"></el-image>

        <div class="introduce">{{ info.name }}</div>
        <div class="price">
            <img class="img1" src="../assets/img/icon_jiage@3x.png" alt="" />
            <div class="num">{{ info.price }}</div>
            <!-- <div class="time" >
                <div class="time1">抢购倒计时<span>1天 01:35:06</span></div>
            </div> -->
        </div>
        <div class="border"></div>
        <div class="fans">
            <div class="text">
                <div class="text1 name1">
                    <img class="text2" :src="info.minterAvatar" alt="" />
                    <div class="text3">{{ info.minter }}</div>
                </div>
                <div class="text1" v-if="info.ownerId">
                    <img class="text2" :src="info.ownerAvatar" alt="" />
                    <div class="text3">{{ info.owner }}</div>
                </div>
            </div>
            <div class="text">
                <!-- <div class="text1">
                    <img class="text2 text4" src="../assets/img/like.png" alt="" />
                    <div class="text3">16</div>
                </div> -->
                <like-button :isLike="info.liked" @like="likeProduct">{{ info.likes }}</like-button>

                <!-- <div class="text1" v-else>
                    <img class="text2 text4" src="../assets/img/icon-yuyue@3x.png" alt="" />
                    <div class="text3">预约</div>
                </div> -->
            </div>
        </div>
    </router-link>
</template>

<script>
import product from '../mixins/product';
import LikeButton from './LikeButton.vue';
export default {
    components: { LikeButton },
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    mixins: [product],
    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.$message.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.$message.success('取消收藏');
                });
            }
        }
    }
};
</script>
<style lang="less" scoped>
.content {
    .line();
    width: 276px;
    height: 416px;
    display: inline-block;
    .imgBox {
        height: 266px;
        width: 100%;
        border-radius: 8px 8px 0px 0px;
    }

    &:hover {
        .imgBox {
            position: relative;
            &::before {
                content: '';
                position: absolute;
                left: 0;
                top: 0;
                right: 0;
                bottom: 0;
                background-color: fade(@warn, 70%);
            }

            &::after {
                padding: 0 22px;
                content: '立即购买';
                line-height: 30px;
                font-size: 16px;
                color: #1a1a1a;
                background: #ffffff;
                border-radius: 16px;
                border: 1px solid #ffffff;
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
        }
    }

    .introduce {
        padding: 10px 16px 6px;
        font-size: 14px;
        font-weight: 400;
        color: #939599;
        line-height: 20px;
    }
    .price {
        display: flex;
        align-items: center;
        // justify-content: space-between;
        padding: 0 16px 16px;
        .img1 {
            width: 10px;
            height: 11px;
            margin-top: 10px;
        }
        .num {
            font-size: 30px;
            font-family: OSP-DIN, OSP;
            font-weight: normal;
            color: #00ffcb;
            line-height: 30px;
        }
        .time {
            display: flex;
            margin-left: 24px;
            .time1 {
                font-size: 14px;
                font-weight: 400;
                color: #939599;
                line-height: 24px;
            }
            span {
                font-size: 14px;
                font-weight: 400;
                color: #00ffcb;
                line-height: 24px;
                margin-left: 6px;
            }
        }
    }
    .border {
        height: 1px;
        background: #494a4d;
        border-radius: 1px;
        margin: 0 16px;
    }
    .fans {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 19px 16px 20px;
        .text {
            display: flex;
            align-items: center;
            .text1 {
                display: flex;
                align-items: center;
                max-width: 70px;
                overflow: hidden;
                &.name1 {
                    margin-right: 22px;
                }
                .text2 {
                    width: 20px;
                    height: 20px;
                    border-radius: 50%;
                    margin-right: 4px;
                    flex-shrink: 0;
                    &.text4 {
                        width: 18px;
                        height: 18px;
                    }
                }
                .text3 {
                    font-size: 14px;
                    font-weight: 400;
                    .ellipsis();
                    color: #939599;
                    line-height: 24px;
                }
            }
        }
    }
}
</style>
