<template lang="html">
<div class="chart chart-field">

<div
  v-show=" sourceInfo && sourceInfo.length "
  class="chart-field-area">
  <el-row class="chart-field-row">
    <el-col
      :span="6"
      :key="index"
      v-for="(item,index) in sourceInfo">
      <template>
        <div class="card">
          <div :title=" item.marketName ? item.marketName : '未知市场' ">
            {{ item.marketName ? item.marketName : '未知市场' }}
          </div>
          <div>{{ item.count | numberLevel }}</div>
        </div>
      </template>
    </el-col>
  </el-row>
</div>
<div
  class="chart-field-content"
  ref="chartField"
  v-show=" !sourceInfo || !sourceInfo.length ">
</div>

</div>
</template>

<script>
import * as chart from 'assets/js/echart-config';
export default {
props: {

sourceInfo: {
  type: Array,
  required: true,
  default: () => {
    return []
  }
},
barColors: {
  type: Array,
  required: false,
  default: () => {
    return ['#115bce', '#3988ff']
  }
},
chartTitle: {
  type: String,
  required: false,
  default: '使用权限 TOP10'
}

},
data() {

return {
}

},
computed: {

chartDom() {
  return echarts.init(this.$refs.chartField);
},
optionDom() {
  const option = chart.treeOption(this.sourceInfo, this.chartTitle, this.barColors);
  return option;
}

},
filters: {

numberLevel(num) {
  if ( num !== 0 && (!num || isNaN(num)) ) {
    return 0;
  }
  // 此处为防止字符串形式的数值进来,因为toFixed方法只能用于数值型数
  num = Number(num);
  if (Math.abs(num) > 100000000) {
    return (num / 100000000).toFixed(0) + '亿';
  } else if (Math.abs(num) > 10000) {
    return (num / 10000).toFixed(0) + '万';
  } else {
    return num;
  }
}

},
watch: {

sourceInfo: {
  handler(cates) {
    this.hideLoading();
    if ( cates && cates.length ) {
      this.resize();
    } else {
      this.chartDom.setOption(chart.emptyOption(this.chartTitle), true);
      setTimeout(() => {
        this.resize();
      }, 50)
    }
  },
  deep: true
}

},
methods: {

doRender() {
  this.chartDom.setOption(this.optionDom, true);
},
resize() {
  this.chartDom.resize();
},
showLoading() {
  this.chartDom.showLoading({
    text: '',
    color: '#3988ff',
    textColor: '#000',
    maskColor: 'rgba(255, 255, 255, 0)',
    zlevel: 0
  });
},
hideLoading() {
  this.chartDom.hideLoading();
}

},
mounted() {

this.chartDom.resize(400, 400);
this.showLoading();
window.addEventListener('resize', this.resize);

},
destroyed() {

window.removeEventListener('resize', this.resize);

}
}
</script>

<style lang="scss">
.chart-field {

> div.chart-field-content {
  min-height: 260px;
}
&-area {
  width: 400px;
  height: 200px;
}
&-row {
  position: absolute;
  top: 28px;
  @media screen and (min-width: 1801px) {
    top: 42px;
  }
  width: 100%;
  .card {
    width: 90%;
    height: 40px;
    margin: 2px 2px 10px 2px;
    color: #ffffff;
    padding: 10px 0;
    text-align: center;
    border: 1px solid #378fff;
    div:nth-child(1) {
      color: #a8b0df;
      font-size: 12px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    div:nth-child(2) {
      margin-top: 5px;
      font-size: 22px;
    }
  }
}
@for $n from 1 through 12 {
  &-row .el-col-6:nth-of-type(#{$n}) {
    .card {
      background-color: nth((#0142ff, #003eeb, #0136d4, #0131c1, #0134cb, #0230ba, #032ba5, #022696, #031f80, #021b6d, #041658, #0131c1), $n);
    }
  }
}

}
</style>


亲爱的阿乾
885 声望22 粉丝

此时无能为力,此心随波逐流