<template>
  <div class="learning-effect">
    <div class="education" ref="education"></div>
    <div class="learning" ref="learning"></div>
  </div>
</template>

<script>
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
import echarts from "echarts";
let vm = null;
export default {
  data() {
    return {
      echartsData: {
        chart1: {},
        chart2: {}
      }
    };
  },
  created() {
    vm = this;
    vm.$nextTick(() => {
      vm.setEducation();
      vm.setLearning();
    });
  },
  mounted() {
    commonUtil.resizeHeight();
  },
  methods: {
    updateResize() {
      this.$nextTick(function() {
        window.onresize = function() {
          vm.echartsData.chart1.resize();
          vm.echartsData.chart2.resize();
        };
      });
    },
    setEducation() {
      let myChart = echarts.init(this.$refs.education);
      let option = {
        title: {
          text: ""
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        color: ['#5D7092','#FFB01B'],
        legend: {
          data: ["项目前总正确率", "项目后总正确率"]
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: {
          type: "category",
          data: ["本科", "大专", "中专及以下", "硕士", "博士", "其他"]
        },
        yAxis: {
          min: 0,
          max: 100,
          type: "value",
          axisLabel: {
            formatter: "{value} %"
          }
        },
        series: [
          {
            name: "项目前总正确率",
            type: "bar",
            barWidth: 10,
            data: [45, 45, 34, 34, 4, 8]
          },
          {
            name: "项目后总正确率",
            type: "bar",
            barWidth: 10,
            data: [70, 66, 67, 67, 24, 24]
          }
        ]
      };
      myChart.setOption(option);
      vm.echartsData.chart1 = myChart;
      vm.updateResize();
    },
    setLearning() {
      let myChart = echarts.init(this.$refs.learning);
      let option = {
        title: {
          text: ""
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        color: ['#5D7092','#FFB01B'],
        legend: {
          data: ["培训前正确率", "培训后正确率"]
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: {
          axisLabel: {
            interval: 0,
            rotate: 45
          },
          type: "category",
          data: ["推荐联合用药方案"]
        },
        yAxis: {
          min: 0,
          max: 100,
          type: "value",
          axisLabel: {
            formatter: "{value} %"
          }
        },
        series: [
          {
            name: "培训前正确率",
            type: "bar",
            barWidth: 10,
            data: [45]
          },
          {
            name: "培训后正确率",
            type: "bar",
            barWidth: 10,
            data: [81]
          }
        ]
      };
      myChart.setOption(option);
      vm.echartsData.chart2 = myChart;
      vm.updateResize();
    },
  }
};
</script>

<style lang='scss' rel='stylesheet/scss'>
.learning-effect {
  width: 100%;
  .learning,
  .education {
    margin-top: 40px;
    min-width: 400px;
    height: 400px;
    background: #fff;
  }
}
</style>
