<template>
  <div class="count-item">
    <span class="title">{{ title }}</span>
    <div class="count-content">
      <span v-for="num in nums" :class="num == '，' ? 'separator' : num == 0 ? 'zero num' : 'num'">{{ num }}</span>
     <!-- <span v-if="nums.length < 7">个</span>
      <span v-if="nums.length > 7">万</span>-->
      <span class="num">个</span>
    </div>
  </div>
</template>
<script>
  export default {
    name: 'count-item',
    props: {
      value: {
        default: 0,
        type: Number
      },
      title: {
        type: String
      }
    },
    data () {
      return {
        isMore: false
      }
    },
    methods: {
      formatNumber (num) {
        let re = /(\d+)(\d{3})/
        if (num > 9999) {
          this.isMore = true
          console.log(num.toString().charAt(4))
        }
        num = (Array(10 - String(num).length).join(0) + num)
        while (re.test(num)) {
          num = num.replace(re, '$1，$2')
        }
        num = num.split('')
//        console.log(num)
        return num
      }
    },
    computed: {
      nums () {
        return this.formatNumber(this.value)
      }
    }
  }
</script>
<style lang="scss" scoped>
  @import '~assets/scss/variables';

  .count-item {
    text-align: center;
    line-height: 20px;

    .title {
      display: inline-block;
      width: 60px;
      float: left;
      font-weight: bold;
      line-height: 40px;
      color: #fff;
      font-size: 14px;
    }
    .separator, .num {
      display: inline-block;
    }
    .separator {
      font-size: 12px;
      color: #6cb7f3;
      line-height: 38px !important;
      margin: 0 5px 0 -5px;
      width: 3px;
    }
    .count-content{
      width: 145px;
      background: #fff;
      float: right;
      height: 30px;
      margin-top: 5px;
      margin-right: 5px;
      span{
        float: left;
        line-height: 24px;
        font-weight: bold;
      }
      span.zero{
        color: #bbdffb;
      }
      span:first-child{
        margin-left: 3px;
      }
      span:last-child{
        line-height: 30px;
        color: #6cb7f3;
      }
    }
    .num {
      background: #9dd0f9;
      width: 18px;
      height: 24px;
      margin-right: 2px;
      line-height: 24px;
      text-align: center;
      color: $white;
      font-weight: bold;
      border-radius: 2px;
      margin-top: 3px;
    }
  }
</style>
