<template>
  <Card title="质量管理">
    <div class="container">
      <div class="left" ref="chart" style="transform: translateY(5px)"></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: '' }
      ]
    }
  },
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      const myChart = echarts.init(this.$refs.chart)

      const option = {
        backgroundColor: '#182337',
        tooltip: {
          trigger: 'item'
        },
        title: {
          text: '质量问题数',
          left: '48%',
          top: '55%',
          textAlign: 'center',
          textStyle: {
            fontSize: '13',
            color: '#8f929b',
            fontWeight: '400'
          }
        },
        series: [
          {
            type: 'pie',
            radius: ['76%', '88%'],
            center: ['50%', '50%'],
            hoverAnimation: true,
            label: {
              normal: {
                position: 'center'
              }
            },
            data: [
              {
                value: '14',
                name: '未整改质量问题',
                itemStyle: {
                  normal: {
                    color: '#60d3d0'
                  }
                },
                label: {
                  normal: {
                    show: false
                  }
                }
              },
              {
                value: '13',
                name: '已整改质量问题',
                tooltip: {
                  show: true
                },
                itemStyle: {
                  normal: {
                    color:  '#f25d17'
                  }
                },
                label: {
                  normal: {
                    formatter: '56',
                    textStyle: {
                      fontSize: 36,
                      color: '#ffc30f',
                      // 调整label的位置
                      padding: [-30, 0, 0, 0]
                    }
                  }
                }
              }
            ]
          },
          {
            name: '人员类型',
            type: 'pie',
            hoverAnimation: false,
            legendHoverLink: false,
            radius: ['67%', '70%'],
            center: ['50%', '50%'],
            color: ['#182337', '#60d3d0'],
            label: {
              normal: {
                position: 'inner'
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            },
            tooltip: {
              show: false
            },

            data: [
              {
                value: 50,
                name: ''
              },
              {
                value: 50,
                name: ''
              },
            ]
          }
        ]
      }

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

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

  width: 100%;
  height: 100%;

  > .left {
    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;
      color: #fff;
      overflow-y: scroll;

      .list-item {
        position: relative;
        display: flex;
        box-sizing: border-box;
        border-left: 4px solid #66d3d8;
        margin-bottom: 5px;
        padding: 5px 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: 10px 0;
          &::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 8px;
            display: inline-block;
            transform: translate(0, -50%);
            width: 6.6px;
            height: 11.6px;
            background-image: url('../assets/images/command-center/triangle.png');
            background-size: 100% 100%;
            transition: all .3s;
          }
        }

        &: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: 100%;
          padding-left: 20px;
        }

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