<template>
  <div>
    <div class="menu-title">
      概览
    </div>
    <div class="home-box">
      <div class="counts-box">
        <div class="count-item" v-for="(value, key, i) in count" :key="key">
          <div class="count-img" :style="{background:colorArray[i].color}">
            <i :class="colorArray[i].icon"></i>
          </div>
          <div  class="count-title">
            <div class="name">{{ key }}</div>
            <div class="count">{{ value }}</div>
          </div>
        </div>
      </div>
      <div class="chart-box">
        <div class="title"><i class="el-icon-s-data" style="margin-right: 10px;font-size: 18px"></i>正反馈率</div>
        <div id="chart"></div>
      </div>
    </div>

  </div>
</template>

<script>
import request from '@/utils/request';

var _this;
export default {
  name: "homePage",
  data() {
    return {
      count: {
        '用户': '2,636',
        '物品': '51,754',
        '总反馈': '267,610',
        '正面反馈': '120,927',
        '负面反馈': '51,123'
      },
      colorArray:[
        {color:"linear-gradient(#2196F3, #2196f394)",icon:"el-icon-user-solid",font:"#2196F3"},
        {color:"linear-gradient(#FF9800, #ff980094)",icon:"el-icon-s-goods",font:"#FF9800"},
        {color:"linear-gradient(#F44336, #f44336b5)",icon:"el-icon-document-remove",font:"#F44336"},
        {color:"linear-gradient(#4CAF50, #8bc34abf)",icon:"el-icon-document-checked",font:"#4CAF50"},
        {color:"linear-gradient(#c862d9, #c862d9bf)",icon:"el-icon-document-delete",font:"#c862d9"}
      ]
    }
  },
  mounted() {
    _this = this;
    _this.initChart();
  },
  methods: {
    initChart() {
      let dom = document.getElementById("chart");
      let chart = _this.$echarts.init(dom);
      chart.setOption({
        grid: {
          left: '5%',
          right: '5%'
        },
        xAxis: {
          type: 'category',
          data: ['05/01', '05/02', '05/03', '05/04', '05/05', '05/06', '05/07']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: 'like',
            data: [0.1, 0.23, 0.52, 0.44, 0.49, 0.78, 1],
            type: 'line',
            // 区域填充样式
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                  offset: 0, color: '#557cc7' // 0% 处的颜色
                },{
                  offset: 0.2, color: 'rgba(85,124,199,0.2)' // 0% 处的颜色
                }, {
                  offset: 1, color: 'rgba(58,132,255, 0)' // 100% 处的颜色
                }],
              }
            },
          },
          {
            name: 'star',
            data: [0.92, 0.7, 0.65, 0.44, 0.55, 0.55, 0.78],
            type: 'line',
            // 区域填充样式
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                  offset: 0, color: 'rgb(145,204,117)' // 0% 处的颜色
                },{
                  offset: 0.2, color: 'rgba(145,204,117,0.2)' // 0% 处的颜色
                }, {
                  offset: 1, color: 'rgba(58,132,255, 0)' // 100% 处的颜色
                }],
              }
            },
          }
        ]
      });
    }
  }
}
</script>
<style scoped lang="scss">

.content-box > div {
  height: 100%;
}

.home-box {
  padding: 20px 30px 0 30px;

  height: calc(100% - 100px);
  .chart-box {
    background-color: #fff;
    box-shadow: 0px 5px 12px 1px rgba(105, 105, 105, 0.12);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 30px;
    height: calc(100% - 130px);

    #chart {
      width: 100%;
      height: calc(100% - 50px);
    }

    .title {
      width: 100%;
      height: 50px;
      margin-top: 10px;
      line-height: 50px;
      padding-left: 30px;
      font-size: 16px;
      color: #666666;
      font-weight: bold;
      //background: #f0f5fa;
      //border-bottom: 1px solid rgba(105, 105, 105, 0.12);
    }
  }

  .counts-box {
    display: flex;
    justify-content: space-between;

    .count-item {
      width: 18%;
      height: 100px;
      background-color: #fff;
      box-shadow: 0px 5px 12px 1px rgba(105, 105, 105, 0.12);
      //text-align: center;
      border-radius: 4px;
      display: flex;

      &:hover {
        transform: scale(1.03);
      }

      .count-img{
        width: 80px;
        color:#ffffff;
        font-size: 40px;
        text-align: center;
        line-height: 100px;
        height: 100px;
        border-top-left-radius: 4px;
        border-bottom-left-radius: 4px;
      }

      .count-title{
        flex: 1;
        margin: 0 20px;
      }

      .name {
        font-size: 14px;
        padding-top: 20px;
        color: #333333;
        //font-weight: bold;
      }

      .count {
        font-size: 30px;
        color: #3e4c5c;
        padding-top: 15px;
      }
    }
  }
}


</style>
