<template>
    <a :href="`collectionDetail?id=${info.id}`" class="collect" :target="target">
        <el-image class="imgBox" :src="getImg(changeImgs(info.pic))" fit="cover"></el-image>
        <div class="introduce">{{ info.name }}</div>
        <div class="price" v-if="info.salable">
            <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="init" v-else>仅展示</div>
        <div class="con">
            <div class="border"></div>
            <div class="price2" v-if="info.salable">已售 {{ info.sale }} / 剩余 {{ info.stock }}</div>
        </div>
        <div class="fans">
            <div class="text">
                <div class="text1 name1">
                    <img class="text2" :src="info.minterAvatar" alt="" />
                    <!-- <div class="text3">铸造者</div> -->
                    <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 class="text3">持有者</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>
    </a>
</template>

<script>
import product from '../mixins/product';
import LikeButton from './LikeButton.vue';
import { mapState } from 'vuex';
export default {
    components: { LikeButton },
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        },
        target: {
            type: String,
            default: '_self'
        }
    },
    mixins: [product],
    computed: {
        ...mapState(['userInfo'])
    },
    methods: {
        likeProduct() {
            if (!this.info.liked) {
                console.log(111);
                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.info.liked = true;
                console.log(222);
                console.log(this.info);
                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('取消收藏');
                });
            }
            this.$emit('init');
        }
    }
};
</script>
<style lang="less" scoped>
.collect {
    .line();
    width: 276px;
    height: 426px;
    display: inline-block;
    &::before {
        border-radius: 8px !important;
    }
    .imgBox {
        height: 274px;
        width: 100%;
        border-radius: 8px 8px 0px 0px;
    }

    &:hover {
        // .imgBox {
        position: relative;
        transition: transform 0.5s ease-out;
        -o-transition: transform 0.5s ease-out;
        -webkit-transition: transform 0.5s ease-out;
        -moz-transition: transform 0.5s ease-out;
        transform: scale(1.1);
        -ms-transform: scale(1.1);
        -webkit-transform: scale(1.1);
        // &::before {
        //     content: '';
        //     position: absolute;
        //     left: 0;
        //     top: 0;
        //     right: 0;
        //     bottom: 0;
        //     background-color: fade(@prim, 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 14px;
        font-size: 16px;
        font-weight: bold;
        color: #ffffff;
        line-height: 20px;
    }
    .con {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .border {
            width: 100%;
            height: 1px;
            background: #494a4d;
            border-radius: 1px;
            margin: 10px 16px;
        }
        .price2 {
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #939599;
            line-height: 22px;
            width: 220px;
            text-align: right;
            margin-right: 16px;
        }
    }
    .init {
        font-size: 16px;
        font-weight: 400;
        color: #939599;
        line-height: 24px;
        padding: 0 16px 1px;
        margin-top: 4px;
    }
    .price {
        display: flex;
        align-items: center;
        // justify-content: space-between;
        padding-left: 16px;
        .img1 {
            width: 10px;
            height: 11px;
            margin-top: 4px;
        }
        .num {
            font-size: 26px;
            font-family: OSP-DIN, OSP;
            font-weight: normal;
            color: @prim;
            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: @prim;
                line-height: 24px;
                margin-left: 6px;
            }
        }
    }

    .fans {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 9px 16px 0px;
        .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;
                    width: 60px;
                    .ellipsis();
                    color: #939599;
                    line-height: 24px;
                }
            }
        }
    }
}
</style>
