<template>
  <div class="learning-effect">
    <div class="box-list">
      <div v-for="(item , index) in cardData" :key="index" class="box">
        <el-card class="box-card">
          <!-- <el-tooltip class="item-tool" placement="bottom-end" effect="light">
            <div slot="content">
              <p v-for="text in item.content">{{ text }}</p>
            </div>
            <i class="el-icon-question notice"></i>
          </el-tooltip> -->
          <div class="left-content">
            <p class="title">{{ item.title }}</p>
            <p class="value">{{ item.value }}</p>
          </div>
          <!-- <div class="vertical"></div>
          <div class="right-content">
            <p class="has">{{ item.hasKey }}:{{ item.hasNum }}</p>
            <p class="should">{{ item.shouldKey }}:{{ item.shouldNum }}</p>
          </div>-->
        </el-card>
      </div>
    </div>
    <div class="chart" ref="education"></div>
    <div class="chart" ref="learning"></div>
  </div>
</template>

<script>
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
import * as operationData from "../../utils/operation";
import * as chartData from "../../utils/learning/chartData";
import echarts from "echarts";
let vm = null;
export default {
  props: {
    formInline: {
      type: Object
    },
    activeName: {
      type: String
    }
  },
  data() {
    return {
      cardData: [],
      echartsData: {
        chart1: {},
        chart2: {}
      }
    };
  },
  created() {
    vm = this;
    vm.projectId = vm.getUrlSearch(window.location.href, "id");
  },
  mounted() {
    commonUtil.resizeHeight();
    this.$on("search", () => {
      this.search();
    });
  },
  methods: {
    updateResize() {
      this.$nextTick(function() {
        window.onresize = function() {
          vm.echartsData.chart1.resize();
          vm.echartsData.chart2.resize();
        };
      });
    },
    search() {
      let req = {
        projectId: vm.projectId,
        beginDate: operationData.setDuringTime(vm.formInline.during, "begin"),
        endDate: operationData.setDuringTime(vm.formInline.during, "end"),
        hospitalIdList: vm.formInline.organization,
        originalFlag: vm.formInline.checked == false ? 0 : 1,
        regionId: vm.formInline.region[vm.formInline.region.length - 1],
        timeFlag: vm.formInline.timeFlag
      };
      openLoading(vm);
      // if(req.regionId == "000") {
      //   req.regionId = "000";
      // }
      // console.log("0 req", req);
      vm.POST("stats/report/studyEffect", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          vm.initCard(res.data);
          setTimeout(function() {
            vm.setEducation(res.data.educationEffectList);
            vm.setLearning(res.data.knowledgeEffectList);
          }, 20);
        }
      });
    },
    initCard(data) {
      let cardData = [
        {
          value: "0%",
          title: "培训前总正确率"
        },
        {
          value: "0%",
          title: "培训前后正确率"
        }
      ];
      cardData[0].value = data.beforeRate*100 + "%";
      cardData[1].value = data.afterRate*100 + "%";
      vm.cardData = cardData;
    },
    setEducation(data) {
      let myChart = echarts.init(this.$refs.education);
      let xAxisData = [];
      let seriesBefore = [];
      let seriesAfter = [];
      for(let i = 0; i < data.length ; i++) {
        xAxisData.push(data[i].classifyName);
        seriesBefore.push(data[i].beforeRate*100);
        seriesAfter.push(data[i].afterRate*100);
      }
      let option = chartData.educationEffect(xAxisData, seriesBefore ,seriesAfter);
      myChart.setOption(option);
      vm.echartsData.chart1 = myChart;
      vm.updateResize();
    },
    setLearning(data) {
      let myChart = echarts.init(this.$refs.learning);
      let xAxisData = [];
      let seriesBefore = [];
      let seriesAfter = [];
      for(let i = 0; i < data.length ; i++) {
        xAxisData.push(data[i].classifyName);
        seriesBefore.push(data[i].beforeRate*100);
        seriesAfter.push(data[i].afterRate*100);
      }
      let option = chartData.knowledgeEffect(xAxisData, seriesBefore ,seriesAfter);
      myChart.setOption(option);
      vm.echartsData.chart2 = myChart;
      vm.updateResize();
    }
  }
};
</script>

<style lang='scss' rel='stylesheet/scss'>
.learning-effect {
  background: #fff;
  overflow: hidden;
  padding: 10px;
  .box-list {
    position: relative;
    // width: 100%;
    height: 110px;
    .box-card {
      position: relative;
      background-color: #e3efed;
      color: #449284;
      width: 48%;
      margin-right: 1%;
      height: 110px;
      float: left;
      .notice {
        position: absolute;
        z-index: 999;
        top: 21px;
        right: 14px;
        width: 16px;
        height: 16px;
      }
      .el-card__header {
        border-bottom-width: 0;
      }
      .el-card__body {
        padding: 0px;
      }
      .left-content {
        position: relative;
        float: left;
        width: 33%;
        height: 110px;
        text-align: left;
        padding: 23px 0 0 20px;
        .title {
          font-size: 14px;
          height: 14px;
          line-height: 14px;
        }
        .value {
          margin-top: 20px;
          height: 22px;
          font-size: 30px;
          line-height: 22px;
          font-weight: 500;
        }
      }
      .vertical {
        position: absolute;
        left: 34%;
        float: left;
        margin-top: 23px;
        width:1px;
        height:57px;
        background-color: #C1D8D4;
      }
    }
  }
  .chart {
    position: relative;
    margin: 20px auto 0 auto;
    // width: 100%;
    width: 860px;
    height: 350px;
  }
}
</style>
