<template>
  <!-- 气瓶安检汇总 -->
  <div class="border" :style="{height: boxHeight}">
    <div class="card_box">
      <div class="title_trapezoid center_in">
        <span class="center_in">{{title}}</span>
      </div>
    </div>
    <div class="card_collect">
      <div id="security"></div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'wavyBlock',
    props: {
      title: {
        type: String,
        default: () => '文字',
      },
      boxHeight: {
        type: String,
        default: () => '95%',
      },
    },
    data() {
      return {}
    },
    mounted() {
      this.getEnterpriseCylinder()
    },
    methods: {
      getEnterpriseCylinder() {
        var chartDom = document.getElementById('security');
        var myChart = this.$echarts.init(chartDom);
        var option;
        let bgColor = '#000';
        let title = '总瓶数';
        let color = ['#33f198', '#fbd242', '#c5233b'];
        let echartData = [{
            name: "绿码",
            value: "3720"
          },
          {
            name: "黄码",
            value: "2920"
          },
          {
            name: "红码",
            value: "2200"
          }
        ];
        let formatNumber = function(num) {
          let reg = /(?=(\B)(\d{3})+$)/g;
          return num.toString().replace(reg, ',');
        }
        let total = echartData.reduce((a, b) => {
          return a + b.value * 1
        }, 0);

        option = {
          color: color,
          tooltip: {
            trigger: 'item'
          },
          title: [{
            text: '{name|' + title + '}\n{val|' + formatNumber(total) + '瓶}',
            top: 'center',
            left: 'center',
            textStyle: {
              rich: {
                name: {
                  fontSize: 14,
                  fontWeight: 'normal',
                  color: '#fff',
                  padding: [10, 0]
                },
                val: {
                  fontSize: 20,
                  fontWeight: 'bolder',
                  color: '#fff',
                }
              }
            }
          }, {
            text: '单位：个',
            top: 20,
            left: 20,
            textStyle: {
              fontSize: 14,
              color: '#666666',
              fontWeight: 400
            },
            show: false
          }],
          series: [{
            type: 'pie',
            roseType: 'radius',
            radius: ['48%', '75%'],
            center: ['50%', '50%'],
            data: echartData,
            hoverAnimation: false,
            itemStyle: {
              normal: {
                borderWidth: 2
              }
            },
            labelLine: {
              normal: {
                length: 5,
                length2: 20,
              }
            },
            label: {
              normal: {
                formatter: params => {
                  return (
                    '{icon|●}{name|' + params.name + '}\n{value|' +
                    formatNumber(params.value) + '}'
                  );
                },
                rich: {
                  icon: {
                    fontSize: 16,
                    color: 'inherit'
                  },
                  name: {
                    fontSize: 18,
                    padding: [0, 0, 0, 10],
                    color: '#fff'
                  },
                  value: {
                    fontSize: 14,
                    fontWeight: 'bolder',
                    padding: [10, 0, 0, 20],
                    color: 'inherit'
                  }
                }
              }
            },
          }]
        };
        myChart.setOption(option);
      }
    }
  }
</script>

<style lang="scss" scoped>
  .border {
    border: 1px solid #3077ca;
    margin: 0 10px 0 auto;
    border-radius: 4px;
    box-shadow: inset 0 0 40px rgba(48, 119, 202, 0.3);
  }


  .card_box {
    position: absolute;
    top: 0;
    left: calc(50% - 100px);
    right: 0;
  }

  .title_trapezoid {
    position: relative;
    color: #fff !important;
    width: 200px;
    height: 30px;
    text-align: center;
    z-index: 2;
  }

  .title_trapezoid span {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 200px;
    top: -1px;
    z-index: 2;
    font-size: 15px;
    line-height: 25px;
  }

  .title_trapezoid::before {
    border-bottom: 2px solid #2CD5FF;
    content: '';
    z-index: 1;
    width: 100%;
    height: 30px;
    background-image: linear-gradient(to top, #3077ca99, #3077ca7f, transparent);
    display: inline-block;
    position: absolute;
    left: 0;
    top: -1px;
    transform: perspective(100px) rotateX(150deg);
  }

  .card_collect {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    margin-top: 30px;
    height: calc(100% - 30px);
  }

  #security {
    width: 100%;
    height: 100%;
  }
</style>
