<template>
  <div class="property-health">
    <div class="chart" ref="chart"></div>
    <div class="total">
      <p>综合得分</p>
      <m-count style="font-size:0.12rem;color:#75e1b0;" :value="91"  />
      <p class="unit">（分）</p>
    </div>
  </div>
</template>

<script>
import echarts from 'echarts'
const mockValue = [22.1, 20.9, 24.5, 20.2, 21.1]
export default {
  name: 'PropertyHealth',
  data() {
    return {
      chart: null,
      option: {
        tooltip: {
          trigger: 'axis',
          confine: true,
        },
        radar: [{
          name: {
            rich: {
              a: {
                color: '#aaa',
                lineHeight: 20,
                fontSize: 12 * this.sizeRate,
              },
              b: {
                color: '#ffd400',
                align: 'center',
                fontSize: 12 * this.sizeRate,
              },
              c: {
                color: '#fff',
                fontSize: 12 * this.sizeRate,
              },
            },
            formatter: (text, {index}) => {
              const max = [25, 25, 25, 25, 25]
              return `{a|${text}}\n{b|${mockValue[index]}}{c|/${max[index]}}`
            },
          },
          splitArea: {
            show: false,
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: 'rgba(255,255,255,.3)'
            }
          },
          axisLine: {
            show: false,
          },
          indicator: [
            {text: '全市物业诚信计分', index: 0, max: 25},
            {text: '投诉报修情况', index: 1, max: 25},
            {text: '小区管理情况', index: 2, max: 25},
            {text: '业主满意度', index: 3, max: 25},
            {text: '行业落实情况', index: 4, max: 25},
          ],
          center: ['50%', '60%'],
          radius: '60%',
        }],
        series: [{
          type: 'radar',
          symbol: 'none',
          lineStyle: {
            color: '#ff0000'
          },
          areaStyle: {
            color: 'rgb(255,106,37)',
          },
          data: [{
            value: mockValue,
          }]
        }]
      }
    }
  },
  mounted() {
    setTimeout(this.init, 0)
  },
  beforeDestroy() {
    this.chart && window.removeEventListener('resize', () => this.chart.resize())
  },
  computed: {
    sizeRate() {
      return Number((screen.height / 800).toFixed(1))
    },
  },
  methods: {
    init() {
      this.chart = echarts.init(this.$refs.chart)
      window.addEventListener('resize', () => this.chart.resize())
      this.chart.setOption(this.option)
    }
  }
}
</script>

<style lang="stylus" scoped>
.property-health
  display flex
  justify-content space-around
  align-items center
  .chart
    width 70%
    height 100%
  .total
    padding 0 .1rem
    width .8rem
    height @width
    background-image url(../../assets/images/edge-bg.png)
    background-size 100% 100%
    background-repeat no-repeat
    $flex-center()
    flex-direction column
    color #aaa
    .unit
      font-size .08rem
</style>
