<template>
  <div
    class="v_card"
    v-show="!options.hide"
    :class="{
      _link: options.componentName || options.link,
      actived: $parent.actived==options,
      c1: options.key,
      c2: options.chart,
      [options.componentName?'i-dao-hang':options.icon]:1
    }"
    @click="activeCard"
  >
    <div class="_label">
      {{options.title}}
      <div v-if="options.key">{{options.data}}</div>
    </div>

    <svg viewBox="0 0 198 54">
      <path fill="#fff" fill-opacity="0.15" d="M0,54L198,54L198,5.60377Q145.736,44.8302,102.015,40.2453Q58.2944,35.6604,0,0L0,54Z"/>
      <path fill="#fff" fill-opacity="0.15" d="M0,29.0377254486084L0,54.0000254486084L198,54.0000254486084L198,19.358495448608398Q192.975,29.0377254486084,181.416,34.6415254486084Q169.858,40.245225448608394,139.706,34.6415254486084Q74.8782,15.028295448608398,53.7716,16.8113104486084Q11.5584,20.3773454486084,0,29.0377254486084Z"/>
    </svg>
  </div>
</template>

<script>
export default {
  props: { options: { type: Object } },

  mounted () {
    if (this.options.actived) this.activeCard()
  },

  methods: {
    activeCard () {
      if (this.options.componentName) {
        window.__CHART_MODULE__ = this.options.chart
        this.$parent.actived = this.options
      } else if (this.options.link) {
        if (typeof this.options.link === 'function') {
          this.options.link.call(this)
        } else {
          this.$router.push(this.options.link)
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.v_card {
  margin-right: 20px;
  margin-bottom: 20px;
  padding: 10px;
  min-width: 150px;
  min-height: 72px;
  border-radius: 4px;
  color: #fff;
  background-image: linear-gradient(90deg, #656EFF, #85A7FF);
  position: relative;

  &::before {
    position: absolute;
    top: 8px;
    right: 16px;
    font-size: 30px;
    opacity: .3;
    transition: 0.2s;
  }

  &.i-dao-hang {
    &::before {
      top: 18px;
      font-size: 32px;
    }

    &.actived::before {
      transform: rotate(90deg) scale(1.3);
      opacity: 1;
    }
  }

  &.c1 {
    background-image: linear-gradient(90deg, #F97E4A, #FFBC80);
  }

  &.c2 {
    background-image: linear-gradient(90deg, #38A4FF, #85D1FF);
  }

  > ._label {
    line-height: 26px;
    position: absolute;
    top: 10px;
    left: 10px;
    text-align: center;
    z-index: 1;

    div {
      font-size: 24px;
      font-weight: bold;
    }
  }

  > svg {
    position: absolute;
    left: 0;
    bottom: 0;
  }

  &._link{
    cursor: pointer;
    transition: transform .16s;

    &:hover {
      transform: scale(1.08);
    }
  }
}
</style>
