<template>
    <div class="rank">
        <img src="../../assets/activityRank.png" class="top-img" alt="" />
        <div class="rank-content">
            <div class="tr-tab">
                <div class="tab-item" :class="{ prim: rare === 'SSR' }" @click="changeRare('SSR')">
                    <img v-if="rare === 'SSR'" src="@assets/png-left-bg.png" class="bg" alt="" />
                    <div class="text">
                        <i class="font_family icon-png-ssr-xuanzhong"></i>
                        <span>级</span>
                    </div>
                </div>
                <div class="tab-item" :class="{ prim: rare === 'SR' }" @click="changeRare('SR')">
                    <img v-if="rare === 'SR'" src="@assets/png-middle-bg.png" class="bg" alt="" />
                    <div class="text">
                        <i class="font_family icon-png-sr-weixuanzhong"></i>
                        <span>级</span>
                    </div>
                </div>
                <div class="tab-item" :class="{ prim: rare === 'U' }" @click="changeRare('U')">
                    <img v-if="rare === 'U'" src="@assets/png-right-bg.png" class="bg" alt="" />
                    <div class="text">
                        <i class="font_family icon-png-u-weixuanzhong"></i>
                        <span>级</span>
                    </div>
                </div>
            </div>
            <div class="tr">
                <div class="th">排行</div>
                <div class="th">用户头像</div>
                <div class="th">销毁数量</div>
            </div>
            <div class="tr" v-for="(item, index) in list" :key="index">
                <div class="td">
                    <van-image
                        v-if="index < 3"
                        width="38"
                        height="38"
                        :src="require(`../../assets/info_icon_no${index + 1}.png`)"
                    />
                    <span v-else>{{ index + 1 }}</span>
                </div>
                <div class="td">
                    <van-image width="28" height="28" radius="38" :src="item.avatar" />
                    <span>{{ item.nickname }}</span>
                </div>
                <div class="td">
                    {{ item.num }}
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            list: [],
            time: '',
            rare: 'SSR'
        };
    },
    mounted() {
        this.getList();
    },
    methods: {
        getList() {
            this.$toast.loading({
                message: '加载中...',
                forbidClick: true
            });
            this.$http.get('/destroyRecord/rank/' + this.rare).then(res => {
                this.$toast.clear();
                this.list = res;
            });
        },
        changeRare(rare) {
            this.rare = rare;
            this.getList();
        }
    }
};
</script>

<style lang="less" scoped>
.rank {
    background: #8224ad;
    position: relative;
    display: flex;
    flex-direction: column;

    .top-img {
        width: 100%;
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 0;
    }
    padding: 40vw 10px 0;

    .top-text {
        position: absolute;
        top: 36px;
        left: 20px;
        color: #fff;

        .text1 {
            font-size: 36px;
            font-family: 'ZhenyanGB';
        }
        .text2 {
            font-size: 28px;
            font-family: 'ZhenyanGB';
            margin-top: 10px;
        }
    }

    .time {
        position: absolute;
        left: 0px;
        top: calc(48vw - 40px);
        font-size: 12px;
        color: #ffffff88;
        line-height: 12px;
        transform: scale(0.83) translateX(6px);
        .text2 {
            margin-top: 2px;
        }
    }
}

.rank-content {
    height: 100%;
    background-color: #fff;
    border-radius: 16px 16px 0 0;
    flex-grow: 1;
    position: relative;
    z-index: 1;
    .bottom(15px);
    overflow: hidden;
    .tr {
        overflow: hidden;
        position: relative;
        padding: 0 30px;
        .flex();
        .th {
            font-size: 12px;
            color: @text3;
            line-height: 17px;
            padding: 15px 0;

            &:nth-child(1) {
                width: 38px;
                text-align: center;
            }

            &:nth-child(2) {
                margin-left: 37px;
                flex-grow: 1;
            }
        }

        &:not(:first-child) {
            &::after {
                content: '';
                bottom: 0;
                left: 85px;
                right: 0;
                height: 1px;
                background-color: #f5f7fa;
                position: absolute;
            }
        }
    }

    .td {
        padding: 10px 0;
        flex-shrink: 0;
        &:nth-child(2) {
            margin: 0 10px 0 37px;
            flex-grow: 1;
            overflow: hidden;
            .flex();
            .van-image {
                display: block;
            }
            span {
                font-size: 14px;
                color: #000000;
                line-height: 24px;
                margin-left: 6px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                max-width: 127px;
            }
        }

        &:nth-child(3) {
            overflow: hidden;
            span {
                width: 100%;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }

        &:nth-child(1) {
            text-align: center;
            width: 38px;
            font-size: 20px;
            font-family: 'AlibabaPuHuiTi';
            color: @text3;
            font-weight: bold;
            line-height: 20px;
        }
    }
}
.tr-tab {
    .flex();
    background: rgba(0, 0, 0, 0.1);
    .tab-item {
        width: 33.33%;
        position: relative;
        height: 49px;
        .bg {
            position: absolute;
            top: 0;
            width: 140px;
            height: 50px;
            z-index: 0;
        }
        .text {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            z-index: 1;
            .flex();
            align-items: flex-end;
            justify-content: center;
            color: #939599;
            i {
                font-size: 22px;
                display: block;
            }
            span {
                font-size: 10px;
                transform: translateX(-13px);
            }
        }
        &:nth-child(1) {
            .bg {
                left: 0;
            }
        }
        &:nth-child(2) {
            .bg {
                left: 50%;
                transform: translateX(-50%);
            }
            .text {
                span {
                    transform: translateX(-20px);
                }
            }
        }

        &:nth-child(3) {
            .bg {
                right: 0;
            }
            .text {
                span {
                    transform: translateX(-26px);
                }
            }
        }
        &.prim {
            &:nth-child(1) {
                .text {
                    color: #411c83;
                }
            }
            &:nth-child(2) {
                .text {
                    color: #a34800;
                }
            }
            &:nth-child(3) {
                .text {
                    color: #d37c3c;
                }
            }
        }
    }
}
</style>
