DataItem.vue 3 KB
<template>
  <div class="data-item">
    <div class="data-item-title">
     <div class="dot"></div> {{ item.title }}
      <slot name="title-slot"></slot>
    </div>

    <template>
      <div class="data-item-content-wrapper mt-4 flex">
        <div :class="['data-item-content',item.isWarning?'warning' : '']" >
          {{ item.isCash ?formatNum(statisData[item.key]): statisData[item.key]   }}
        </div>
      </div>
        <template v-if="item.ratioKey">
          <div class="data-item-ratio mt-4 flex">
            <span class="data-item-label">环比</span>
            <div class="value" :style="{ color: getRatioColor(statisData[item.ratioKey]) }">
              {{ formatRatio(statisData[item.ratioKey]) }}
            </div>
            <div class="arrow-icon" v-if="formatIsRatio(statisData[item.ratioKey])">
              <img class="just" :src="getIconSrc(formatIsRatio(statisData[item.ratioKey]))" />
            </div>
          </div>
        </template>
    </template>
  </div>
</template>
<script>
import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js'
export default {
  props: {
    item: {
      type: Object,
      default: () => ({})
    },
    statisData: {
      type: Object,
      default: () => ({})
    },
    queryType: {
      type: String,
      default: ''
    }
  },
  data(){
    return {
      formatNum,
      formatRatio,
      formatIsRatio,
      getIconSrc,
      getRatioColor
    }
  }
}
</script>
<style lang="scss" scoped>
.data-item {
    padding:4px 8px;
    box-sizing: border-box;
  .data-item-title {
    padding-bottom: 2px;
  }
  .value {
    font-family: numberNor;
  }
  .flex {
    display: flex;
    align-items: center;
  }
  width: 100%;
  box-sizing: border-box;
  padding: 0 10px;
  padding-right: 0;
  line-height: 15px;
  .mt-4 {
    margin-top: 4px;
  }
  &-title {
    color: #666666;
    font-size: 13px;
    display: flex;
    // white-space: nowrap;
    .info {
      width: 14px;
      height: 14px;
      vertical-align: top;
      margin-left: 3.8px;
    }
    .title-arrow {
      width: 12px;
      height: 12px;
      margin-left: auto;
    }
  }
  &-content-wrapper {
    align-items: center;
  }
  &-content {
    color: #222222;
    font-size: 18px;
    font-weight: 700;
    font-family: numberBold;
  }
  .warning{
     color: #f24724;
  }
  &-label {
    color: #999999;
    font-size: 11px;
  }
  &-ratio {
    color: #ff0000;
    font-size: 11px;
    .value {
      margin-left: 2px;
      font-size: 11px;
    }
    .arrow-icon {
      width: 13px;
      height: 13px;
      img {
        width: 100%;
      }
    }
  }
  &-personne {
    color: #666666;
    font-size: 11px;
    .value {
      color: #222222;
      margin-left: 4px;
      font-size: 14px;
      font-weight: 500;
    }
  }
  &-ranking {
    color: #666666;
    font-size: 8px;
    font-weight: 400;
    background: #185efe1a;
    padding: 0 2px;
    margin-left: 4px;
    border-radius: 2px;
    .value {
      margin: 0 2px;
      color: #ff5733;
    }
  }
}
</style>