<template>
    <div class="product" @click="goAsset">
        <van-image
            v-if="opened === false"
            width="21.3vw"
            height="21.3vw"
            radius="8"
            :src="require('../../assets/manghe.png')"
            fit="cover"
        />
        <template v-else>
            <van-image
                class="icon-img"
                radius="8"
                width="21.3vw"
                height="21.3vw"
                :src="getImg(changeImgs(info.pic))"
                fit="contain"
            />
            <van-image
                class="more-img"
                radius="8"
                width="21.3vw"
                height="21.3vw"
                :src="getImg(changeImgs(info.pic))"
                fit="contain"
                v-if="isMore"
            />
        </template>

        <div class="number" v-if="info.number && opened">编号：{{ info.number }}</div>
        <img src="../../assets/png-touxing.png" class="touying" alt="" />
        <template v-if="opened && !isMore">
            <!-- <div class="status status1" v-if="info.consignment">寄售中</div> -->
            <img v-if="isLock" class="status-img" src="../../assets/png-shangsuo.png" alt="" />
            <img v-else-if="info.consignment" class="status-img" src="../../assets/png-jishouzhong.png" alt="" />
            <img
                v-else-if="info.status === 'NORMAL' && info.publicShow"
                class="status-img"
                src="../../assets/png-jinzhanshi.png"
                alt=""
            />
            <img
                v-else-if="info.status === 'AUCTIONING'"
                class="status-img"
                src="../../assets/png-paimaizhong.png"
                alt=""
            />
            <!-- <img v-if="info.consignment" class="status-img" src="../../assets/png-jishouzhong.png" alt="" />
            <div class="status" v-else-if="info.status === 'NORMAL'">
                {{ info.publicShow ? '仅展示' : '未展示' }}
            </div>
            <div class="status" v-else>
                {{ getLabelName(info.status, assetStatusOptions) }}
            </div> -->
        </template>
        <img v-else-if="!isMore" class="status-img" src="../../assets/png-kaiqi.png" alt="" />
        <div class="num-icon" v-else>
            <span>×{{ num }}</span>
        </div>
        <!-- <div class="status status2" v-else>待开启</div> -->
        <div class="content">
            <div class="name van-ellipsis">
                {{ !opened ? '盲盒待开启' : info.name }}
            </div>
            <!-- <template v-if="opened">
                <div class="price-content" v-if="info.consignment">
                    <div class="price">
                        <img src="@assets/jiage_huang.png" alt="" />
                        <span>{{ info.sellPrice }}</span>
                    </div>
                </div>
                <div class="status" v-else-if="info.status === 'NORMAL'">
                    {{ info.publicShow ? '仅展示' : '未展示' }}
                </div>
                <div class="status" v-else>
                    {{ getLabelName(info.status, assetStatusOptions) }}
                </div>
            </template>
            <div v-else class="status" style="min-height: 24px;"></div> -->
            <div class="text">
                <div class="minter">
                    <!-- <van-image width="18" height="18" radius="18" :src="info.minterAvatar" fit="cover" /> -->
                    <span class="van-ellipsis">{{ info.minter }}</span>
                </div>
                <!-- <van-image width="18" height="18" :radius="100" :src="info.minterAvatar" fit="cover" />
                <span>{{ info.minter }}</span> -->
                <!-- <div class="text1" v-if="info.type === 'BLIND_BOX'">
          <span>{{ info.sale }}/ </span>
          <span>{{ info.stock }}</span>
        </div>
        <div class="flex1"></div>
        <like-button :isLike="info.liked" @click="likeProduct">
          {{ info.likes }}
        </like-button> -->
            </div>
        </div>
    </div>
</template>

<script>
import asset from '../../mixins/asset';
import product from '../../mixins/product';

export default {
    mixins: [asset, product],
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        },
        num: {
            type: Number,
            default: 1
        }
    },
    computed: {
        isMore() {
            return this.num > 1;
        }
    },
    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('取消收藏');
                });
            }
        },
        goAsset() {
            if (this.isMore) {
                this.$emit('showMore', this.info);
            } else {
                this.$router.push({
                    path: '/' + this.$route.params.companyId + '/assetDetail',
                    query: {
                        id: this.info.assetId || this.info.id
                    }
                });
            }
        }
    }
};
</script>

<style lang="less" scoped>
.product {
    width: 25.6vw;
    padding-top: 5.3vw;
    // margin: 8px;
    // background-color: #1c1e25;
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    min-height: 35.8vw;

    &:nth-child(3n + 1) {
        padding-right: 7.5vw;
    }
    &:nth-child(3n + 2) {
        padding-right: 7.5vw;
    }

    .icon-img {
        overflow: hidden;
        display: block;
        z-index: 1;
        box-shadow: 2px -2px 4px 0px rgba(0, 0, 0, 0.3);
    }
    .more-img {
        position: absolute;
        top: calc(5.3vw - 5px);
        left: 5px;
        z-index: 0;
    }
    .content {
        // padding: 6px 10px 8px;
        padding: 5.3vw 0 0;

        .name {
            font-size: @font1;
            color: #ffffff;
            line-height: 4.5vw;
            width: calc(21.3vw + 16px);
        }

        .price {
            font-size: @font4;
            font-family: OSP;
            color: @prim;
            line-height: 18px;
            padding: 12px 0;

            img {
                display: inline-block;
                width: 8px;
            }
        }
        .status {
            line-height: 24px;
            padding: 10px 0 8px;
            color: @text3;
            font-size: @font2;
        }
    }

    .text {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .text1 {
            font-weight: 400;
            color: @text3;
            line-height: 117px;
            span {
                &:last-child {
                    color: #fff;
                    font-size: @font1;
                }
            }
        }
    }
}
.price-content {
    display: flex;
    align-items: center;
    .text1 {
        font-size: @font1;
        color: @text3;
        line-height: 12px;
    }
}

.minter {
    display: flex;
    font-size: @font1;
    color: @text3;
    line-height: 4.5vw;
    align-items: center;
    overflow: hidden;
    span {
        // margin-left: 4px;
    }
    .van-image {
        flex-shrink: 0;
    }
}

.number {
    position: absolute;
    top: calc(26.6vw - 17px);
    left: 0;
    width: 21.3vw;
    font-size: 10px;
    color: @text3;
    line-height: 17px;
    background-color: fade(#000, 80%);
    padding: 0 5px;
    box-sizing: border-box;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 2;
}
.touying {
    position: absolute;
    width: 25.6vw;
    height: 6.4vw;
    left: 0;
    top: 21.3vw;
    z-index: 0;
}
.status-img {
    width: 22px;
    height: 14px;
    position: absolute;
    left: 0;
    top: 5.3vw;
    z-index: 3;
}
.status {
    background-color: #fff;
    font-size: 12px;
    font-weight: bold;
    color: @text3;
    position: absolute;
    top: 4px;
    left: 3px;
    line-height: 14px;
    border-radius: 9px;
    z-index: 3;
    padding: 0 10px;
    transform: scaleX(0.8);
    &.status1 {
        color: #3ab200;
    }
    &.status2 {
        color: #ff4f50;
    }
}
.num-icon {
    font-size: 12px;
    font-weight: bold;
    color: #ffffff;
    line-height: 14px;
    padding: 0 6px;
    background: #b65dff;
    backdrop-filter: blur(39px);
    position: absolute;
    top: 5.3vw;
    left: 0;
    border-radius: 8px 0 8px 0;
    z-index: 2;
    span {
        transform: scale(0.8);
    }
}
</style>
