<template>
  <div class="content">
    <div class="verify-code-div" @click="codeInputFun">
      <ul class="verify-code-num-list">
        <li>
          <span>{{codeArr[0]}}</span>
          <span v-if="isFocus && !codeArr[0]" class="caret"></span>
        </li>
        <li>
          <span>{{codeArr[1]}}</span>
          <span v-if="isFocus && !codeArr[1] && codeArr[0]" class="caret"></span>
        </li>
        <li>
          <span>{{codeArr[2]}}</span>
          <span v-if="isFocus && !codeArr[2] && codeArr[0] && codeArr[1]" class="caret"></span>
        </li>
        <li>
          <span>{{codeArr[3]}}</span>
          <span v-if="isFocus && !codeArr[3] && codeArr[0] && codeArr[1] && codeArr[2]" class="caret"></span>
        </li>
        <li>
          <span>{{codeArr[4]}}</span>
          <span v-if="isFocus && !codeArr[4] && codeArr[0] && codeArr[1] && codeArr[2]&& codeArr[3]"
            class="caret"></span>
        </li>
        <li>
          <span>{{codeArr[5]}}</span>
          <span v-if="isFocus && !codeArr[5] && codeArr[0] && codeArr[1] && codeArr[2]&& codeArr[3] && codeArr[4]"
            class="caret"></span>
        </li>
      </ul>
      <input @focus="focus" @blur="blur" ref="codeInput" type="text" class="verify-code-input" unselectable="on"
        maxlength="6" v-model="code">
    </div>
  </div>
</template>



<script>
  export default {
    name: 'verificatonCode',
    data() {
      return {
        code: '',
        codeArr: [],
        isFocus: false
      }
    },
    watch: {
      code(newVal) {
        this.codeArr = String(newVal).split("")
      }
    },
    methods: {
      focus() {
        this.isFocus = true
      },
      blur() {
        this.isFocus = false
      },
      codeInputFun() {
        this.$refs.codeInput.focus()
      },
    }
  }
</script>

<style scoped lang="less">
  @keyframes shan {
    to {
      opacity: 0;
    }

    from {
      opacity: 1;
    }
  }

  .content {
    width: 100%;
    min-height: 100vh;
    background: rgba(0,0,0,0.6);
  }

  .verify-code-div {
    width: 6.5rem;
    margin: auto;
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%,-50%);
    background: none;
    .verify-code-input {
      width: 100%;
      height: 1rem;
      border:none;
      outline: none;
      color: transparent;
      caret-color: transparent;
      background: none;
    }

    .verify-code-num-list {
      width: 100%;
      height: 1rem;

      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      text-align: center;

      &:after {
        content: "";
        display: block;
        clear: both;
      }

      li {
        background: #fff;
        float: left;
        width: 1rem;
        height: 1rem;
        text-align: center;
        line-height: 1rem;
        display: inline-block;
        //background: rgba(0, 0, 0, .05);
        border-radius: 10px;
        margin-right: .1rem;
        font-size: 20px;
        overflow: hidden;

        .caret {
          margin-top: .2rem;
          display: inline-block;
          min-width: 2px;
          max-width: 2px;
          width: 2px;
          height: .6rem;
          background: rgba(0, 0, 0, .4);
          animation: shan 0.8s infinite;
        }

        &:last-child {
          margin-right: 0px;
        }
      }
    }
  }
</style>
