<template>
  <transition name="scale">
    <div class="ui-card"
         v-show="show">
      <div class="ui-card-content">
        <div class="ui-card-top">
          <div class="ui-card-title">{{title}}</div>
          <div class="ui-card-introduction gray">{{introduction}}</div>
        </div>
        <div class="ui-card-bottom">
          <div class="ui-card-number">{{getFormatNumber}}<span>{{getUnit}}</span></div>
          <div class="ui-card-prompt gray">{{prompt}}</div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
  export default {
    name: 'md-scrolling-ribbon-item',
    props: {
      title: {
        type: String,
        default: ''
      },
      introduction: {
        type: String,
        default: ''
      },
      number: {
        type: Number,
        default: 0
      },
      prompt: {
        type: String,
        default: ''
      },
      type: {
        type: String,
        default: 'amount' // amount 金额  percentage 百分比  decimal 小数
      }
    },
    data () {
      return {
        show: false
      }
    },
    mounted () {
      this.show = true
    },
    computed: {
      getFormatNumber () {
        let str = ''
        switch (this.type) {
          case 'amount':
            str = this.number.toFixed(2)
            break
          case 'percentage':
            str = this.number.toFixed(2)
            break
          case 'decimal':
            str = this.number
            break
          default:
            break
        }
        return str
      },
      getUnit () {
        let str = ''
        switch (this.type) {
          case 'amount':
            str = '元'
            break
          case 'percentage':
            str = '%'
            break
          default:
            break
        }
        return str
      }
    }
  }
</script>

<style scoped>
  .ui-card {
    width: 100px;
    height: 90px;
    background: #efefef;
    display: inline-block;
    font-size: 14px;
    line-height: 14px;
    padding: 10px 0 8px 0;
    transform: scale(1);
    opacity: 1;
  }

  .ui-card-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-direction: column;
  }

  .ui-card-top, .ui-card-bottom {
    padding-left: 10px;
  }

  .ui-card-introduction {
    line-height: 24px;
  }

  .ui-card-number {
    color: red;
    font-size: 20px;
    font-weight: 600;
  }

  .ui-card-number > span {
    font-size: 8px;
  }

  .ui-card-prompt {
    transform: scale(.8);
    transform-origin: left;
  }

  .gray {
    font-size: 12px;
    color: #888;
  }

  .scale-leave-to, .scale-enter {
    transform: scale(0);
    opacity: 0;
  }

  .scale-enter-active, .scale-leave-active {
    transition: transform .5s ease, opacity .5s ease;
  }
</style>
