<template>
    <div class="rankContainer">
        <el-row :gutter="20">
            <!--卡路里-->
            <el-col :span="12">
                <!--          只显示前8个-->
                <li v-for="(s,i) in students.CalSort" v-if="i <= 7">
                    <div
                            :class="['rows',{'row_0':i == 0},{'row_1':i == 1},{'row_2':i == 2},{'row_3':i == 3},{'row_4':i == 4},{'row_5':i == 5},{'row_6':i == 6},{'row_7':i == 7}]">
                        <div class="head">
                            <img :src="s.Head" class="headImg" v-if="s.Head">
                            <img src="../static/img/people/flyhead.png" class="headImg" alt="" v-if="!s.Head">
                            <img src="../static/img/rank/king1.svg" class="king" alt="" v-if="i == 0">
                            <img src="../static/img/rank/king2.svg" class="king" alt="" v-if="i == 1">
                            <img src="../static/img/rank/king3.svg" class="king" alt="" v-if="i == 2">
                        </div>
                        <div class="name">
                            NO.{{ i + 1 }} {{ s.Name }}
                        </div>
                        <div class="score">
                            {{ s.Cle|fmtInt }}
                            <em>千卡</em>
                        </div>
                        <div class="record">
                            <img src="../static/img/rank/recordIcon.svg" class="king" alt=""
                                 v-if="s.IsNewUser ==0 && s.IsBreaking == 1">
                        </div>
                    </div>
                </li>
            </el-col>
            <!--CK-->
            <el-col :span="12">
                <li v-for="(s,i) in students.CkSort" v-if="i <= 7">
                    <div
                            :class="['rows',{'row_0':i == 0},{'row_1':i == 1},{'row_2':i == 2},{'row_3':i == 3},{'row_4':i == 4},{'row_5':i == 5},{'row_6':i == 6},{'row_7':i == 7}]">
                        <div class="head">
                            <img :src="s.Head" class="headImg" v-if="s.Head">
                            <img src="../static/img/people/flyhead.png" class="headImg" alt="" v-if="!s.Head">
                            <img src="../static/img/rank/king1.svg" class="king" alt="" v-if="i == 0">
                            <img src="../static/img/rank/king2.svg" class="king" alt="" v-if="i == 1">
                            <img src="../static/img/rank/king3.svg" class="king" alt="" v-if="i == 2">
                        </div>
                        <div class="name">
                            NO.{{ i + 1 }} {{ s.Name }}
                        </div>
                        <div class="score">
                            {{ s.Ck|fmtFloat }}
                            <em>CK</em>
                        </div>
                        <div class="record">
                            <img src="../static/img/rank/recordIcon.svg" class="king" alt=""
                                 v-if="s.IsNewUser ==0 && s.IsBreaking == 1">
                        </div>
                    </div>
                </li>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    // import {
    //     ClassUserRank
    // } from '@/api/getApiRes'

    let qs = require('qs');
    export default {
        data() {
            return {
                students: {
                    CkSort: [],
                    CalSort: [],
                },
                rankTimer: null,
            }
        },
        props: ['rankInfo'],
        watch: {
            rankInfo: {
                handler(newName, oldName) {
                    let that = this;
                    if (newName) {
                        // 排序
                        let CkSort = that.deepClone(newName);
                        that.students.CkSort = CkSort.sort(function (a, b) {
                            return b.Ck - a.Ck;
                        });
                        let CalSort = that.deepClone(newName);
                        that.students.CalSort = CalSort.sort(function (a, b) {
                            return b.Cle - a.Cle;
                        });
                    } else {
                        this.students.CkSort = [];
                        this.students.CalSort = [];
                    }
                },
                deep: true,
                immediate: true
            }
        },
        methods:{
            // 深拷贝
            deepClone(obj) {
                let _obj = JSON.stringify(obj),
                    objClone = JSON.parse(_obj);
                return objClone
            }
    },
        filters: {
            fmtNum(val) {
                if (val == 0) {
                    return '--'
                } else {
                    if (parseInt(val) < 0) return 0;
                    if (parseInt(val) > 0) return val
                }
            },
            fmtFloat(val) {
                if (val == 0) {
                    return '0.0'
                } else {
                    return parseFloat(val).toFixed(1);
                }
            },
            fmtInt(val) {
                if (val == 0) {
                    return '0'
                } else {
                    return parseInt(val);
                    // return parseFloat(val).toFixed(3);
                }
            },
        },
    }
</script>

<style scoped>
    .rankContainer {
        width: 100%;
        overflow: visible;
        display: block;
        margin: 0 auto;
        padding-top: 1rem;
    }

    li {
        width: 100%;
        height: 4rem;
        display: block;
        margin: 0 auto;
        overflow: visible;
    }

    li .rows {
        width: 100%;
        height: 3rem;
        /*background: #ee191d;*/
        border-radius: 250rem;
        overflow: visible;
        display: block;
        margin: 0 auto;
        margin-top: 0.15rem;
    }

    li .head {
        width: 3rem;
        height: 3rem;
        float: left;
        margin-left: 0rem;
        margin-top: 0.15rem;
        overflow: visible;
    }

    li .head .headImg {
        width: 2.8rem;
        height: 2.8rem;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        border: 2px solid #fff;
        border-radius: 33rem;
    }

    li .head .king {
        position: relative;
        top: -4rem;
        left: -0.2rem;
        width: 2rem;
        height: 2rem;
        float: left;
    }

    li .name {
        font-weight: normal;
        font-size: 1.5rem;
        text-align: left;
        color: #fff;
        float: left;
        margin-left:1rem;
        line-height: 3rem;
    }

    li .record {
        float: right;
    }

    li .record img {
        position: relative;
        top: -0rem;
        width: 1.2rem;
    }

    li .score {
        font-weight: normal;
        font-size: 1.5rem;
        color: #fff;
        float: right;
        margin-right: 1rem;
        line-height: 3rem;
        text-align: right;
    }

    li .score em {
        font-size:1rem;
    }

    .row_0 {
        background: rgba(238, 25, 29, 0.75);
    }

    .row_1 {
        background: rgba(244, 76, 31, 0.75);
    }

    .row_2 {
        background: rgba(242, 182, 23, 0.75);
    }

    .row_3 {
        background: rgba(112, 238, 21, 0.75);
    }

    .row_4 {
        background: rgba(11, 253, 45, 0.75);
    }

    .row_5 {
        background: rgba(1, 228, 182, 0.75);
    }

    .row_6 {
        background: rgba(0, 207, 230, 0.75);
    }

    .row_7 {
        background: rgba(4, 209, 252, 0.75);
    }

    .tips {
        position: absolute;
        right: 3%;
        top: 1rem;
        font-size: 0.4rem;
        color: #fff;
    }

</style>
