ans_rank.vue 7.82 KB
<template>
    <div class="bck">
        <div class="updete">
            更新时间:{{ Moment().locale("zh-cn").format("LL") }}
        </div>

        <div class="context">
            <div class="title">
                <div
                    :class="active == 'a' ? 'title_check' : 'title_nocheck'"
                    @click="chooseTag('a')"
                >
                    <div>个人排行榜</div>
                    <div class="blue_div"></div>
                </div>
                <div
                    :class="active == 'b' ? 'title_check' : 'title_nocheck'"
                    @click="chooseTag('b')"
                >
                    <div>学校排行榜</div>
                    <div class="blue_div"></div>
                </div>
            </div>

            <div class="card">
                <div class="card_item">
                    <img src="@/assets/rank/tx.png" />
                    <div>{{person.name}}</div>
                </div>
                <div class="card_item_red">
                    <div v-if="person.rank">第{{person.rank}}名</div>
                    <div v-else>暂无名次</div>
                    <div>{{person.score}}分</div>
                </div>
            </div>

            <div class="table_title titleFont">
                <div class="title_1">排名</div>
                <div class="title_2">
                    <div class="title_2_2">姓名</div>
                    <div class="title_2_3">得分</div>
                </div>
            </div>

            <div
                class="table_title conFont"
                v-for="(v, i) in rankList"
                :key="i"
            >
                <div class="title_1" v-if="i == 0">
                    <img src="@/assets/rank/1.png" />
                </div>
                <div class="title_1" v-if="i == 1">
                    <img src="@/assets/rank/2.png" />
                </div>
                <div class="title_1" v-if="i == 2">
                    <img src="@/assets/rank/3.png" />
                </div>
                <div class="title_1" v-if="i > 2">{{ i + 1 }}</div>
                <div class="title_2">
                    <div class="title_2_2">{{ v.name }}</div>
                    <div class="title_2_3">{{ v.num }}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Tabbar4 from "@/component/Tabbar4";
export default {
    components: { Tabbar4 },
    data() {
        return {
            active: "a",
            rankList: [],
            person: {
                name: '',
                rank: 0,
                score: 0,
            },
        };
    },
    methods: {
        chooseTag(val) {
            this.active = val;
            if(val == 'a') {
                this.getPersonRank()
            }else if(val == 'b') {
                this.getschoolRank()
            }
        },
        //个人排行榜
        getPersonRank() {
            this.yxAxios
                .get(
                    `${
                        this.kqUrl
                    }/item/getScoreRank/person?travelerNum=${localStorage.getItem(
                        "travelerNum"
                    )}`
                )
                .then((res) => {
                    if (res.data.code == 200) {
                        const data = res.data.data;
                        this.person = {
                            name: data.name,
                            rank: data.rank,
                            score: data.score,
                        };
                        this.rankList = data.rankList;
                    } else {
                        this.$toast.fail(res.data.message);
                    }
                });
        },
        //学校排行榜
        getschoolRank() {
            this.yxAxios
                .get(
                    `${
                        this.kqUrl
                    }/item/getScoreRank/school`
                )
                .then((res) => {
                    if (res.data.code == 200) {
                        this.rankList = res.data.data;
                    } else {
                        this.$toast.fail(res.data.message);
                    }
                });
        },
    },
    mounted() {
        this.getPersonRank();
    },
};
</script>

<style lang="scss" scoped>
.bck {
    position: absolute;
    width: 100vw;
    min-height: 100vh;
    background-image: url("../../assets/rank/red_rank.png");
    -moz-background-size: 100% 100%;
    background-size: 100% 100%;

    .updete {
        position: absolute;
        top: 15vh;
        left: 6vw;
        font-size: 4.2vw;
        color: #fff;
        opacity: 0.8;
    }

    .context {
        width: 94vw;
        min-height: 1100px;
        background-color: #fff;
        margin-top: 310px;
        margin-left: 3vw;
        margin-bottom: 50px;
        border-radius: 80px;
        padding: 2vw 5vw;
        box-sizing: border-box;

        .title {
            width: 90%;
            height: 100px;
            margin-top: 40px;
            display: flex;
            align-items: center;

            .title_check {
                font-size: 5vw;
                color: #333333;
                margin: 0 3vw;
                font-weight: 800;

                .blue_div {
                    width: 50px;
                    height: 15px;
                    border-radius: 10px;
                    margin-left: 10vw;
                    margin-top: 20px;
                    background-color: #0b91f3;
                }
            }
            .title_nocheck {
                font-size: 4.2vw;
                color: #999999;
                margin: 0 3vw;

                .blue_div {
                    width: 50px;
                    height: 15px;
                    border-radius: 10px;
                    margin-left: 10vw;
                    margin-top: 20px;
                    background-color: #fff;
                }
            }
        }

        .card {
            width: 100%;
            height: 170px;
            margin-top: 20px;
            box-shadow: 1px 1px 4px rgb(197, 197, 197);
            padding: 3vw;
            box-sizing: border-box;
            display: flex;
            justify-content: space-between;

            .card_item {
                width: 50%;
                font-size: 4.6vw;
                font-weight: 700;
                color: #333333;
                display: flex;
                align-items: center;
                padding-left: 10px;
                box-sizing: border-box;

                img {
                    width: 90px;
                    height: 90px;
                    margin-right: 17px;
                }
            }
            .card_item_red {
                width: 50%;
                font-size: 4vw;
                color: #fd4649;
                display: flex;
                align-items: center;
                justify-content: space-around;
            }
        }

        .table_title {
            width: 100%;
            height: 100px;
            margin-top: 25px;
            padding: 20px 3vw 3vw 0;
            box-sizing: border-box;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .title_1 {
                width: 15%;
                text-align: center;

                img {
                    width: 55px;
                    height: 70px;
                }
            }
            .title_2 {
                width: 70%;
                display: flex;
                justify-content: space-between;

                .title_2_3 {
                    width: 10vw;
                    text-align: left;
                }
            }
        }
        .titleFont {
            font-size: 4.5vw;
            color: #999999;
        }
        .conFont {
            font-size: 4.45vw;
            color: #333333;
        }
    }
}
</style>