<template>
  <Card title="质量管理">
    <div class="container">
      <div class="left" ref="chart"></div>
      <div class="right">
        <div class="top">
          <div class="left">
            <span class="label">已整改质量问题</span>
            <span class="value">(13)</span>
          </div>
          <div class="right">
            <span class="label">未整改质量问题</span>
            <span class="value">(14)</span>
          </div>
        </div>
        <div class="list">
          <div class="list-item" v-for="(item, index) in list" :key="index">
            <span class="label">{{ item.name }}</span>
            <span class="value">{{ item.content }}</span>
          </div>
        </div>
      </div>
    </div>
  </Card>
</template>

<script>
import Card from '../components/Card'
import echarts from 'echarts4'

export default {
  components: { Card },
  data() {
    return {
      list: [
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '测试测试测试测试' },
        { name: '项目位置', content: '1测试测试测试测试' }
      ]
    }
  },
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      const myChart = echarts.init(this.$refs.chart)

      const option = {
        backgroundColor: '#182337',
        tooltip: {
          trigger: 'item'
        },
        title: {
          text: '质量问题数',
          left: '47%',
          top: '55%',
          textAlign: 'center',
          textStyle: {
            fontSize: '15',
            color: '#8f929b',
            fontWeight: '400'
          },
        },
        series: [
          {
            type: 'pie',
            radius: ['80', '68'],
            center: ['50%', '50%'],
            hoverAnimation: true,
            label: {
              normal: {
                position: 'center'
              }
            },
            data: [
              {
                value: '56',
                name: '标题',
                itemStyle: {
                  normal: {
                    color: '#f25d17'
                  }
                },
                label: {
                  normal: {
                    show: false
                  }
                }
              },
              {
                value: 100 - '56',
                name: '占位',
                tooltip: {
                  show: false
                },
                itemStyle: {
                  normal: {
                    color: '#60d3d0'
                  }
                },
                label: {
                  normal: {
                    formatter: '56',
                    textStyle: {
                      fontSize: 36,
                      color: '#ffc30f',
                      // 调整label的位置
                      padding:[-30, 0, 0, 0],
                    }
                  }
                }
              }
            ]
          },
          // {
          //   type: 'pie',
          //   roseType: 'area',
          //   radius: ['58%', '54%'],
          //   color: ['#182337', '#68d7d9'],
          //   data: [50, 50]
          // }
        ]
      }

      myChart.setOption(option)
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  display: flex;
  box-sizing: border-box;
  padding-bottom: 5px;

  width: 100%;
  height: 100%;

  > .left {
    display: grid;
    place-items: center;

    width: 50%;
    height: 100%;
  }

  > .right {
    display: flex;
    flex-direction: column;
    width: 50%;
    .top {
      display: flex;
      padding: 5px 0;
      color: #fff;
      font-size: 12px;
      white-space: nowrap;
      line-height: 34px;
      .left {
        color: #af5320;
        transform: translateX(-10%);
      }
    }

    .list {
      width: 100%;
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      color: #fff;
      overflow-y: scroll;

      .list-item {
        display: flex;
        box-sizing: border-box;
        border-left: 4px solid #66d3d8;
        margin-bottom: 5px;
        padding: 6px 0;
        width: 100%;
        background-image: linear-gradient(to right, #3b7589, #212c3e);
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.3s;
        white-space: nowrap;

        &:hover {
          padding: 20px 0;
        }

        &:hover .value {
          color: #c2805f;
        }

        &:last-child {
          margin-bottom: 0;
        }

        .label,
        .value {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .label {
          box-sizing: border-box;
          width: 40%;
          padding-left: 20px;
        }

        .value {
          width: 60%;
        }
      }
    }
  }
}
</style>
