<template>
    <!-- <router-link
        :to="{
            path: '/creatorDetail',
            query: {
                id: info.id
            }
        }"
        class="info"
    > -->
    <div class="info" @click="$router.push({ path: '/creatorDetail', query: { id: info.id } })">
        <van-image :width="66" :height="66" :src="getImg(info.avatar)" fit="cover" radius="33" />
        <!-- <img v-if="rank" class="NOImg" :src="NOInfo.img1" alt="" /> -->
        <div class="content">
            <div class="text1 van-ellipsis">{{ info.nickname }}</div>
            <div class="text2 van-ellipsis">
                {{ info.intro }}
            </div>
            <div class="flex1"></div>

            <!-- <div class="text3"> -->
                <!-- <div class="sale" v-if="rank" :style="{ color: NOInfo.color }">
                    <img class="icon" :src="NOInfo.img2" alt="" />
                    <span>已售{{ info.sales }}</span>
                    <i class="font_family icon-a-icon-dianzan2"></i>
                </div> -->
                <!-- <div class="text4">
                    <span class="text4_one">已售</span>
                    <span class="text4_two">{{ info.sales }}</span>
                </div>
            </div> -->
        </div>

        <van-button
            @click.stop="follow"
            :class="info.follow ? (isFollow ? 'followedtwo' : 'followedtwo') : 'followedthree'"
            :plain="info.follow"
            type="primary"
            size="mini"
            round
        >
            {{ info.follow ? (isFollow ? '互相关注' : '已关注') : '关注' }}
        </van-button>
    </div>
    <!-- </router-link> -->
</template>

<script>
export default {
    props: {
        rank: {
            type: Number,
            default: 0
        },
        info: {
            type: Object,
            default: () => {
                return {};
            }
        },
        isFollow: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'normal'
        }
    },
    computed: {
        NOInfo() {
            if (this.rank) {
                const colors = ['#FF8E12', '#C37BFF', '#3ACEFF'];
                return {
                    img1: require(`@assets/NO${this.rank}.png`),
                    img2: require(`@assets/svgs/NOicon${this.rank}.svg`),
                    color: colors[this.rank - 1]
                };
            }
            return {};
        }
    },
    methods: {
        follow() {
            this.checkLogin().then(() => {
                if (!this.info.follow) {
                    this.$http.get(`/user/${this.info.id}/follow`).then(res => {
                        this.$emit('update:info', {
                            ...this.info,
                            follow: true,
                            followers: this.info.followers + 1
                        });
                        this.$toast.success('关注成功');
                    });
                } else {
                    this.$http.get(`/user/${this.info.id}/unfollow`).then(() => {
                        this.$emit('update:info', {
                            ...this.info,
                            follow: false,
                            followers: this.info.followers - 1
                        });
                        this.$toast.success('取消关注');
                    });
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.info {
    display: flex;
    padding: 20px 15px;
    position: relative;
    align-items: center;
    .content {
        flex-grow: 1;
        padding-left: 10px;
        // display: flex;
        // flex-direction: column;
        overflow: hidden;
        // height: 60px;
        .text1 {
            font-size: 16px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #ffffff;
            line-height: 22px;
            margin-bottom: 2px;
        }
        .text2 {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #8c8e93;
            line-height: 20px;
            margin-bottom: 2px;
        }

        .text3 {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .sale {
                display: flex;
                align-items: center;
                font-size: @font1;
                line-height: 24px;

                .font_family {
                    font-size: @font2;
                    margin-left: 2px;
                }

                .icon {
                    display: block;
                    width: 18px;
                }

                span {
                    transform: translateX(3px);
                }
            }

            .text4 {
                span {
                    font-size: @font1;
                    color: @text0;
                    &:first-child {
                        color: @text3;
                        margin-right: 2px;
                    }
                }
            }
        }
        .text4 {
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #8c8e93;
            line-height: 18px;
            .text4_two {
                color: #ffffff;
                margin-left: 5px;
            }
        }
    }

    .van-image {
        flex-shrink: 0;
    }
    .NOImg {
        position: absolute;
        width: 80px;
        height: 90px;
        display: block;
        left: 12px;
        top: 15px;
    }

    .van-button--mini {
        min-width: 60px;
        font-size: @font1;
        font-size: 14px;
        height: 28px;
        border-radius: 4px;
        border-width: 0;
        background-image: none;

        &.follow {
            color: @text3;
            background-image: none;
        }
    }
}
.followedthree {
    width: 60px;
    height: 28px;
    background: #f9ddb3;
    border-radius: 4px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: bold;
    color: #503a1e;
    line-height: 20px;
    text-align: center;
}
.followedtwo {
    border: 1px solid #222630 !important;
    box-sizing: border-box;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.3);
    line-height: 18px;
}
.info + .info {
    position: relative;
    &::before {
        content: '';
        position: absolute;
        left: 15px;
        right: 0px;
        top: 0;
        height: 1px;
        background-color: #ffffff10;
    }
}
</style>
