<template>
  <ul :class="[{'many':students.length >= 2}]">
    <li v-for="(s,i) in students.slice(0, maxShowNum)" :class="s.className">
      <div v-show="i<10" class="centerLi">
        <!-- <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/flyhead.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="FakeclassName" 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: 10,    //最大显示记录数
      studentsFake: [],
      FakeclassName: ''
    }
  },
  props: ['students'],
  watch: {
    'students': {
      // 自动计算补全空白处
      handler(newName, oldName) {
        if (!newName) {
          console.log('没有传入学生数据');
        }
        let sum = 0;
        let that = this;
        sum = newName.length;
        that.studentsFake = 0;
        if (sum <= 2) {
          that.studentsFake = 2 - sum;
        }
        else if (sum >= 10) {
          that.studentsFake = 0
        }
        else if (sum >= 3) {
          that.studentsFake = 10 - sum;
        }

        let numberClass = '';
        let colorClass = '';
        for (let i = 0; i < sum; i++) {
          switch (true) {
            // case  sum == 1:
            //   numberClass = 'max';
            //   break;
            // case  sum == 2:
            case  sum <= 2:
              numberClass = 'two';
              break;
            case   sum > 2:
              numberClass = 'ten';
              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
          }

          newName[i].className = numberClass + ' ' + colorClass;
          that.FakeclassName = numberClass + ' ' + colorClass;
        }

      },
      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: 100%;
  display: inline-flex;
  align-items: center;
  align-content: center;
  justify-content: center;
  flex-wrap: wrap;
  flex-grow: 1;

  &.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: 99.8%;
  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: 31%;
    float: left;
    padding-right: 4%;
    margin-top:  0.2rem;

    span {
      float: right;

      em {
        color: white;
        font-size: 0.75rem;
        line-height: 1.90rem;
        font-weight: bold;
        letter-spacing: 0.03rem;
      }

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

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

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

      img {
        @include cube;
        width: 1.7rem;
        height: 1.7rem;
        border-radius: 250rem;

        &.girl {
          border: 2px solid #EA26EA;
        }

        &.boy {
          border: 2px solid #39B6FF;
        }
      }
    }

    .names {
      @include cube;
      width: 1.36rem;
      background: rgba(0, 0, 0, 0.7);
      font-size: 0.25rem;
      text-align: center;
      padding: 1% 1%;
      border-radius: 250rem;
      position: relative;
      bottom: 0.37rem;
    }

    .IsPrivate {
      width: 0.6rem;
      float: right;
      position: relative;
      right: -0.15rem;
      bottom: 2.09rem;
    }

    .IsBirthday {
      width: 1.1rem;
      float: left;
      position: relative;
      bottom: 2.18rem;
      left: 0.4rem;
    }
  }

  .rt {
    width: 32%;
    float: right;
    margin-top:  0.2rem;

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

      span {
        float: right;
      }
    }

    > span {
      width: 100%;
      text-align: right;
      float: right;
      font-size: 0.727rem;
      line-height: 1.90rem;
      font-weight: bold;
      padding-right: 15%;
    }

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

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

    img {
      width: 0.36rem;
      float: right;
      margin-right: 0%;
      margin-top: 0.60rem;
    }
  }
}

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

  span {
    width: 33.333%;
    float: left;  

    img {
      width: 0.32rem;
      float: left;
      margin-left: 0.36rem;
      margin-top: 0.2rem;
    }

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


.max {
  width: 9.5rem;
  height: 3.5rem;
  margin-top: 25%;

  .userinfo {
    height: 2.2rem;
  }

  .userSport {
    span:nth-child(1)>img {
      margin-left: 0.43rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.46rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.4rem;
    }
  }
}

.two {
  width: 9.5rem;
  height: 3.5rem;
  margin-top: 0.1rem;
  // margin-top: 0.2rem;

  .userinfo {
    height: 2.2rem;
  }

  .userSport {
    span:nth-child(1)>img {
      margin-left: 0.43rem;
    }
    span:nth-child(2)>img {
      margin-left: 0.46rem;
    }
    span:nth-child(3)>img {
      margin-left: 0.4rem;
    }
  }
}

.ten {
  width: 3.12rem;
  height: 1.46rem;
  margin-top: 0.1rem;

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

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

  /deep/ .powerContainer img {
    position: relative;
    right: -0.1rem;
    bottom: 0.1rem;
    width: 0.2rem;
  }

  .userinfo {
    height: 0.92rem;

    .lt {
      width: 33%;
      margin-top: -0.55rem;
      padding-right: 2.5%;

      em {
        font-size: 0.38rem;
        line-height: 2.0rem;
        letter-spacing: 0.01rem;
      }

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

    .md {
      height: 1.0rem;
      margin-top: -0.01rem;
      
      .head {
        height: 0.9rem;

        img {
          width: 0.75rem;
          height: 0.75rem;
          border-width: 2px !important;
        }
      }
          
      .names {
        width: 0.72rem !important;
        font-size: 0.15rem !important;
        bottom: 0.22rem !important;
      }
          
      .IsPrivate {
        width: 0.25rem;
        bottom: 0.92rem;
        // bottom: 2.65rem;
        right: -0.03rem;
      }
        
      .IsBirthday {
        width: 0.49rem;
        bottom: 0.98rem;
        left: 0.23rem;
      }
    }
    
    .rt {
      margin-top: -0.55rem;

      span {
        font-size: 0.345rem;
        line-height: 2.0rem;
        padding-right: 5%;
        
        em {
          letter-spacing: 0.01rem; 
        }
      }

      .heartJump {
        margin-right: 0.12rem;
      }

      .heartImgContainer {
        width: 20%;
      }

      img {
        width: 0.16rem;
        margin-right: 0%;
        margin-top: 0.8rem;
      }
    }
  }

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

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

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

    em {
      font-size: 0.2rem;
      margin-top: 0.03rem;
      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>