<template>
  <ul :class="[{'few':students.length == 2}, {'many':students.length > 2}]">
    <li v-for="(s,i) in students.slice(0, maxShowNum)" :class="studentsClassName[i].name">
      <div :class="[{ 'box animate__animated animate__flipInX': Listate },{'centerLi':true}]">
        <!-- <div class="power" v-if="s.RealHr != 0"> -->
        <div class="power">
          <power :cur-power="s.PowerPercent" :cur-hr="s.RealHr"></power>
        </div>
        <div class="userinfo">
          <div class="lt">
            <span>
              <em v-if="s.RealHr != 0">{{ s.ActivePercent |max100 }}</em>
              <em v-else>---</em>
              <s>%</s>
            </span>
          </div>
          <div class="md">
            <div class="head">
              <img :src="s.Head" alt="" v-if="s.Head" :class="[{'boy':s.Sex == 1},{'girl':s.Sex == 2}]">
              <!-- <img src="../static/img/people/bswHead.png" alt="" v-if="!s.Head" :class="[{'boy':s.Sex == 1},{'girl':s.Sex == 2}]"> -->
              <default-head v-if="!s.Head" :class="[{'boy':s.Sex == 1},{'girl':s.Sex == 2}]"></default-head>
              <div class="names">
              <span>
                  {{ s.Name }}
              </span>
              </div>
            </div>
            <img src="../assets/imgs/student/star.svg" class="IsPrivate" alt="IsPrivate" v-if="s.IsPrivate == 1">
            <img src="../assets/imgs/student/birthday.png" class="IsBirthday" alt="IsBirthday" v-if="s.IsBirthday == 1">
          </div>
          <div class="rt">
            <span>
              <div :class="[{'heartJump':true}]">
                <div class="heartImgContainer">
                  <img src="../assets/imgs/student/heart.svg" class=""/>
                </div>
                <em class="fastJump" v-if="s.RealHr != 0"
                    v-show="parseInt(s.ActivePercent) > 90">{{ s.RealHr }}
                </em>
                <em class="normalJump" v-if="s.RealHr != 0"
                    v-show="parseInt(s.ActivePercent) <= 90 && parseInt(s.ActivePercent) > 30">{{ s.RealHr }}
                </em>
                <em class="slowJump" v-if="s.RealHr != 0"
                    v-show="parseInt(s.ActivePercent) <= 30">{{ s.RealHr }}
                </em>
                <em v-else>---</em>
              </div>
            </span>
          </div>
        </div>
        <div class="userSport">
          <span>
            <img src="../assets/imgs/student/calc.svg" class=""/>
            <em>{{ s.Cle |fmtInt }}</em>
          </span>
          <span>
            <img src="../assets/imgs/student/ck.svg" class=""/>
            <em>{{ s.Ck |fmtFloat }}</em>
          </span>
          <span>
            <img src="../assets/imgs/student/ei.svg" class=""/>
            <em>{{ s.EI |fmtInt }}</em>
          </span>
          <!-- <span>
            <img src="../assets/imgs/student/sport.svg" class=""/>
            <em>{{ s.PureCalorieNoVo2 |fmtInt }}</em>
          </span> -->
        </div>
      </div>
    </li>
    <li v-for="(s,i) in studentsFake" :class="studentsClassName[i].name" v-show="students"
        v-if="students.length > 0">
      <div class="fakePart"></div>
    </li>
  </ul>
</template>
<script>
import power from '@/components/power'
import defaultHead from '@/components/defaultHead'

export default {
  data() {
    return {
      maxShowNum: 25,    //最大显示记录数
      studentsFake: 0,
      Listate: false,
    }
  },
  props: ['students', 'studentsClassName'],
  watch: {
    'students': {
      // 自动计算补全空白处
      handler(newName, oldName) {
        let that = this;
        if (!newName) {
          console.log('没有传入学生数据');
        }
        let sum = 0;
        sum = newName.length;
        that.studentsFake = 0;
        if (sum == 3) {
          that.studentsFake = 1;
        }
        else if (sum >= 5 && sum <= 9) {
          that.studentsFake = 9 - sum;
        }        
        else if (sum > 9 && sum <= 16) {
          that.studentsFake = 16 - sum;
        }
        else if (sum > 16 && sum <= 25) {
          that.studentsFake = 25 - sum;
        }        
        else {
          that.studentsFake = 0;
        }

        let numberClass = '';
        let colorClass = '';
        for (let i = 0; i < sum; i++) {
          that.Listate = false;
          // console.log(' that.Listate', that.Listate);
          switch (true) {
            case  parseInt(sum) == 1:
              numberClass = 'max';
              break;
            case  parseInt(sum) == 2:
              numberClass = 'two';
              break;
            case  parseInt(sum) <= 4 && parseInt(sum) > 2:
              numberClass = 'four';
              break;
            case  parseInt(sum) <= 9 && parseInt(sum) > 4:
              numberClass = 'nine';
              break;
            // case  parseInt(sum) <= 9 && parseInt(sum) > 6:
            //   numberClass = 'nine';
            //   break;
            case parseInt(sum) <= 16 && parseInt(sum) > 9:
              numberClass = 'sixteen';
              break;
            case parseInt(sum) <= 25 && parseInt(sum) > 16:
              numberClass = 'twentyFive';
              break;
            case parseInt(sum) >= 26:
              numberClass = 'twentyFive';
              break;
          }
          let per = parseInt(newName[i].ActivePercent);
          switch (true) {
            case per >= 90:
              colorClass = 'red';
              break;
            case per <= 89 && per > 79:
              colorClass = 'brown';
              break;
            case per <= 79 && per > 69:
              colorClass = 'yellow';
              break;
            case per <= 69 && per > 54:
              colorClass = 'green';
              break;
            case per <= 54 && per > 39:
              colorClass = 'violet';
              break;
            case per <= 39:
              colorClass = 'blue';
              break
          }

          // 数据变动一次，翻动一次

          // if(!localStorage.colorClass){
          //   localStorage.colorClass = colorClass;
          // }else{
          //   if(localStorage.colorClass == colorClass){
          //     that.Listate = true;
          //     localStorage.colorClass = colorClass;
          //   }
          // }

          newName[i].className = numberClass + ' ' + colorClass;
          that.FakeclassName = numberClass + ' ' + colorClass;
          that.Listate = !that.Listate;
        }
      },
      deep: true,
      immediate: true
    }
  },
  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 parseFloat(val).toFixed(2);
        return parseInt(val);
      }
    },
    max100(val) {
      if (val <= 100) {
        return val
      } else {
        return 100
      }
    }
  },
  components: {
    power, defaultHead
  }
}
</script>
<style lang="scss" scoped>

@mixin cube {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
}

em, i, ul, li, s {
  margin: 0;
  padding: 0;
  list-style: none;
  font-style: normal;
  text-decoration: none;
}

ul {
  @include cube;
  width: 97.5%;
  display: inline-flex;
  align-items: center;
  align-content: center;
  justify-content: center;
  flex-wrap: wrap;
  flex-grow: 1;

  &.few {
    justify-content: space-around;
  }
  &.many {
    justify-content: space-between;
  }
}

.blue .centerLi {
  // background: linear-gradient(#007ec7 0%, #007dc6 33%, #4cbbfc 100%);
  background: #007ec7;
}

.violet .centerLi {
  // background: linear-gradient(#3500ac 0%, #4300ad 33%, #7766f8 100%);
  background: #3519AB;
}

.green .centerLi {
  // background: linear-gradient(#0ab105 0%, #0ab105 33%, #37e06b 100%);
  background: #05A200;
}

.yellow .centerLi {
  // background: linear-gradient(#ffb308 0%, #f5c600 33%, #ffe61f 100%);
  background: #ffb308;
}

.brown .centerLi {
  // background: linear-gradient(#ff6200 0%, #ff6200 34.48%, #ff9d2b 100%);
  background: #ff6200;
}

.red .centerLi {
  // background: linear-gradient(#d11122 0%, #d11122 48.28%, #ff3445 100%);
  background: #d11122;
}

.slowJump {
  animation: moveAct 3s infinite;
  -webkit-animation: moveAct 3s infinite; /*Safari and Chrome*/
  animation-direction: alternate; /*轮流反向播放动画。*/
  animation-timing-function: ease-in-out; /*动画的速度曲线*/
  /* Safari 和 Chrome */
  -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
}

.normalJump {
  animation: moveAct 2s infinite;
  -webkit-animation: moveAct 2s infinite; /*Safari and Chrome*/
  animation-direction: alternate; /*轮流反向播放动画。*/
  animation-timing-function: ease-in-out; /*动画的速度曲线*/
  /* Safari 和 Chrome */
  -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
}

.fastJump {
  animation: moveAct 1s infinite;
  -webkit-animation: moveAct 1s infinite; /*Safari and Chrome*/
  animation-direction: alternate; /*轮流反向播放动画。*/
  animation-timing-function: ease-in-out; /*动画的速度曲线*/
  /* Safari 和 Chrome */
  -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
}

@keyframes moveAct {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}

@-webkit-keyframes moveAct /*Safari and Chrome*/
{
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}

.centerLi {
  width: 100%;
  height: 100%;
  overflow: hidden;
  float: left;
  color: #fff;
  border-radius: 0.1rem;
}

.power {
  margin-top: 0.1rem;
  margin-right: 0.1rem;
}

.userinfo {
  @include cube;

  .lt {
    width: 30%;
    float: left;
    padding-right: 5%;
    margin-top:  0.8rem;

    span {
      float: right;

      em {
        color: white;
        font-size: 1.5rem;
        line-height: 2.0rem;
        font-weight: bold;
        letter-spacing: 0.1rem;
      }

      s {
        font-size: 0.4rem;
        float: right;
        text-align: right;
        margin-top: 0.25rem;
        font-family: "Arial Black";
        font-weight: bold;
      }
    }
  }

  .md {
    width: 30%;
    float: left;
    padding-top: 3%;
    height: 3rem;

    .head {
      @include cube;
      height: 3rem;

      /deep/ img {
        @include cube;
        width: 2.6rem;
        height: 2.6rem;
        border-radius: 250rem;

        &.girl {
          border: 0.05rem solid #EA26EA;
        }

        &.boy {
          border: 0.05rem solid #39B6FF;
        }
      }
    }

    .names {
      @include cube;
      width: 2rem;
      background: rgba(0, 0, 0, 0.65);
      font-size: 0.4rem;
      text-align: center;
      padding: 0.2% 1%;
      border-radius: 250rem;
      position: relative;
      bottom: 0.55rem;
    }

    .IsPrivate {
      width: 0.6rem;
      float: right;
      position: relative;
      bottom: 3rem;
      right: 0.3rem;
    }

    .IsBirthday {
      width: 1.7rem;
      float: left;
      position: relative;
      bottom: 3.3rem;
      left: 0.95rem;
    }
  }

  .rt {
    width: 35%;
    float: right;
    margin-top:  0.8rem;

    .heartJump {
      width: 100%;
      float: right;
      letter-spacing: 0.1rem;

      span {
        float: right;
      }
    }

    > span {
      width: 100%;
      text-align: right;
      float: right;
      font-size: 1.363rem;
      line-height: 2.0rem;
      font-weight: bold;
      padding-right: 16%;
    }

    em {
      color: white;
      width: 80%;
      float: right;
      text-align: right;
    }

    s {
      font-size: 0.4rem;
      float: right;
      text-align: right;
      margin-top: 0.25rem;
    }

    .heartImgContainer {
      width: 20%;
      // height: 2rem;
      float: right;
    }

    img {
      width: 0.5rem;
      float: right;
      margin-right: 20%;
      margin-top: 0.39rem;
      // margin-top: 10%;
    }
  }
}

.userSport {
  @include cube;
  line-height: 0.8rem;
  margin-top: 0.6rem;

  span {
    width: 33.333%;
    float: left;  

    img {
      width: 0.4rem;
      float: left;
      margin-left: 1.2rem;
      margin-top: 0.18rem;
    }

    em {
      float: left;
      font-size: 0.45rem;
      font-family: Georgia, Arial;
      vertical-align: top;
      margin-left: 0.12rem;
    }
  }
}

.max {
  width: 12rem;
  height: 5.1rem;
  margin-top: 2rem;

  .userinfo {
    height: 3.2rem;
  }
}

.two {
  width: 9.2rem;
  height: 4.2rem;
  margin-top: 2.5rem;

  .userinfo {
    height: 2.9rem;

    .lt {
      width: 33%;
      padding-right: 1%;
      margin-top: 0.7rem;

      em {
        font-size: 1.2rem;
        line-height: 1.5rem;
      }

      s {
        // font-size: 0.25rem;
        margin-top: 0.1rem;
      }
    }

    .md {
      width: 30%;
      height: 2.5rem;
      
      /deep/ .head {
        height: 2.7rem;

        img {
          width: 2.2rem;
          height: 2.2rem;
        }
      }
          
      .names {
        width: 1.6rem !important;
        font-size: 0.3rem !important;
        bottom: 0.4rem !important;
      }
          
      .IsPrivate {
        bottom: 2.65rem;
        right: 0rem;
      }
        
      .IsBirthday {
        width: 1.4rem;
        bottom: 2.9rem;
        left: 0.67em;
      }
    }
    
    .rt {
      width: 33%;
      margin-top: 0.7rem;

      span {
        font-size: 1.09rem;
        line-height: 1.5rem;
        padding-right: 8%;  
      }
      
      .heartJump {
        margin-right: 0.18rem;
      }

      img {
        width: 0.4rem;
        margin-right: 10%;
        margin-top: 0.28rem;
      }
    }
  }

  .userSport {
    line-height: 0.6rem;
    margin-top: 0.1rem;

    img {
      width: 0.38rem;
      margin-top: 0.1rem;
    }

    span:nth-child(1)>img {
      margin-left: 0.66rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.96rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.96rem;
    }

    em {
      font-size: 0.4rem;
      margin-top: 0.03rem;
    }
  }
}

.four {
  width: 9.58rem;
  height: 4.3rem;
  margin-top: 0.3rem;

  .userinfo {
    height: 2.9rem;

    .lt {
      margin-top: 0.7rem;

      em {
        font-size: 1.2rem;
        line-height: 1.5rem;
      }

      s {
        // font-size: 0.25rem;
        margin-top: 0.1rem;
      }
    }

    .md {
      height: 2.5rem;
      
      /deep/ .head {
        height: 2.6rem;

        img {
          width: 2.2rem;
          height: 2.2rem;
        }
      }
          
      .names {
        width: 1.6rem !important;
        font-size: 0.3rem !important;
        bottom: 0.4rem !important;
      }
          
      .IsPrivate {
        bottom: 2.65rem;
        right: 0.1rem;
      }
        
      .IsBirthday {
        width: 1.4rem;
        bottom: 2.8rem;
        left: 0.72rem;
      }
    }
    
    .rt {
      margin-top: 0.7rem;

      span {
        font-size: 1.09rem;
        line-height: 1.5rem;
        padding-right: 6%;
      }
      
      .heartJump {
        margin-right: 0.18rem;
      }

      img {
        width: 0.4rem;
        margin-right: 20%;
        margin-top: 0.28rem;
      }
    }
  }

  .userSport {
    line-height: 0.5rem;
    margin-top: 0.2rem;

    img {
      width: 0.38rem;
      margin-top: 0.1rem;
    }

    span:nth-child(1)>img {
      margin-left: 0.86rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.96rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.96rem;
    }

    em {
      font-size: 0.4rem;
      margin-top: 0.06rem;
    }
  }
}

.nine {
  width: 6.36rem;
  height: 2.92rem;
  margin-top: 0.2rem;
  
  .userinfo {
    height: 1.9rem;

    .lt {
      width: 35%;
      padding-right: 1%;
      margin-top: 0rem;

      em {
        font-size: 0.7rem;
        line-height: 1.8rem;
      }

      s {
        // font-size: 0.25rem;
        margin-top: 0.43rem;
      }
    }

    .md {
      width: 30%;
      height: 1.8rem;
      
      /deep/ .head {
        height: 1.7rem;

        img {
          width: 1.5rem;
          height: 1.5rem;
          border-width: 2px !important;
        }
      }
          
      .names {
        width: 1.2rem !important;
        font-size: 0.2rem !important;
        bottom: 0.25rem !important;
      }
          
      .IsPrivate {
        bottom: 1.7rem !important;
        right: 0.05rem !important;
        width: 0.4rem !important;
      }
        
      .IsBirthday {
        width: 0.9rem;
        bottom: 1.85rem;
        left: 0.49rem;
      }
    }
    
    .rt {
      width: 33%;
      margin-top: 0rem;

      span {
        font-size: 0.636rem;
        line-height: 1.8rem;
        padding-right: 5%;
      }
      
      .heartJump {
        margin-right: 0.2rem;
      }

      img {
        width: 0.3rem;
        margin-right: 10%;
        margin-top: 0.6rem;
      }
    }
  }

  .userSport {
    line-height: 0.3rem;
    margin-top: 0rem;

    img {
      width: 0.25rem;
      margin-top: 0.18rem;
    }

    span:nth-child(1)>img {
      margin-left: 0.56rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.66rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.66rem;
    }

    em {
      font-size: 0.25rem;
      margin-top: 0.18rem;
    }
  }
}

.sixteen {
  width: 4.78rem;
  height: 2.25rem;
  margin-top: 0.1rem;
  
  /deep/ .powerContainer img {
    width: 0.25rem !important;
  }

  .power {
    margin-top: 0.01rem;
    margin-right: 0.01rem;
  }

  .userinfo {
    height: 1.43rem;

    .lt {
      width: 35%;
      padding-right: 2%;
      margin-top: -0.3rem;

      em {
        font-size: 0.55rem;
        line-height: 1.90rem;
        letter-spacing: 0.02rem;
      }

      s {
        font-size: 0.25rem;
        margin-top: 0.6rem;
      }
    }

    .md {
      width: 30%;
      height: 1.5rem;
      padding-top: 0.1rem;
      
      /deep/ .head {
        height: 1.4rem;

        img {
          width: 1.1rem !important;
          height: 1.1rem !important;
          border-width: 2px !important;
        }
      }
          
      .names {
        width: 1rem !important;
        font-size: 0.15rem !important;
        bottom: 0.2rem !important;
      }
          
      .IsPrivate {
        width: 0.3rem;
        bottom: 1.4rem;
        right: 0.05rem;
      }
        
      .IsBirthday {
        width: 0.6rem;
        bottom: 1.50rem;
        left: 0.41rem;
      }
    }
    
    .rt {
      width: 33%;
      margin-top: -0.3rem;

      span {
        font-size: 0.5rem;
        line-height: 1.90rem;
        padding-right: 5%;        
      }

      em {
        letter-spacing: 0.02rem;
      }

      .heartJump {
        margin-right: 0.2rem;
      }

      img {
        width: 0.25rem;
        margin-right: 5%;
        margin-top: 0.7rem;
      }
    }
  }

  .userSport {
    line-height: 0.3rem;
    margin-top: 0rem;

    img {
      width: 0.25rem;
      margin-top: 0.08rem;
    }

    span:nth-child(1)>img {
      margin-left: 0.36rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.36rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.36rem;
    }

    em {
      font-size: 0.25rem;
      margin-top: 0.08rem;
      // line-height: 0.26rem;
    }
  }
}

.twentyFive {
  width: 3.80rem;
  height: 1.78rem;
  margin-top: 0.1rem;

  /deep/ .powerContainer {
    height: 0.3rem;
  }

  /deep/ .powerContainer img {
    position: relative;
    top: 0.1rem !important;
    right: 0.1rem;
    width: 0.15rem !important;
    float: right;
  }

  .power {
    margin-top: 0.0rem;
    margin-right: 0.0rem;
  }
  
  .userinfo {
    height: 1.1rem;

    .lt {
      width: 35%;
      padding-right: 1%;
      margin-top: -0.55rem;

      em {
        font-size: 0.473rem;
        line-height: 2.10rem;
        letter-spacing: 0.02rem;
      }

      s {
        font-size: 0.2rem;
        margin-top: 0.78rem;
      }
    }

    .md {
      width: 30%;
      height: 1.0rem;
      padding-top: 0.06rem;
      
      /deep/ .head {
        height: 1.1rem;

        img {
          width: 0.8rem;
          height: 0.8rem;
          border-width: 2px !important;
        }
      }
          
      .names {
        width: 0.75rem !important;
        font-size: 0.15rem !important;
        bottom: 0.2rem !important;
      }
          
      .IsPrivate {
        width: 0.25rem;
        bottom: 1.1rem;
        // bottom: 2.65rem;
        right: 0.05rem;
      }
        
      .IsBirthday {
        width: 0.49rem;
        bottom: 1.15rem;
        left: 0.32rem;
      }
    }
    
    .rt {
      width: 33%;
      margin-top: -0.55rem;

      span {
        font-size: 0.43rem;
        line-height: 2.10rem;
        padding-right: 8%;        
      }

      em {
        letter-spacing: 0.02rem;
      }

      .heartJump {
        margin-right: 0.13rem;
      }

      .heartImgContainer {
        width: 20%;
      }

      img {
        width: 0.2rem;
        margin-right: 5%;
        margin-top: 0.86rem;
      }
    }
  }

  .userSport {
    line-height: 0.3rem;
    margin-top: 0rem;

    img {
      width: 0.22rem;
      margin-top: 0.05rem;
    }

    span:nth-child(1)>img {
      margin-left: 0.3rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.3rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.3rem;
    }

    em {
      font-size: 0.22rem;
      margin-top: 0.04rem;
      margin-left: 0.06rem;
      // line-height: 0.8rem;
    }
  }
  
}

.fakePart {
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.13);
  border-radius: 0.1rem;
}

</style>