<template>
  <div class="examination-analysis">
    <div class="box-list">
      <div v-for="(item , index) in cardData" :key="index" class="box-card" v-bind:class="{ 'box-last': index == 2 }">
        <!-- <el-card class="box-card" v-bind:class="{ 'box-last': index == 2 }"> -->
          <p class="value">{{ item.value }}</p>
          <p class="title">{{ item.title }}</p>
        <!-- </el-card> -->
      </div>
    </div>
    <div class="spacing"></div>
    <div v-if="containOfficial === 1">
    <div class="chart-title">完成项目考试次数情况</div>
    <div v-if="showExamTimes === true" class="overflow-chart">
      <div class="chart" id="examTimes" ref="examTimes"></div>
    </div>
    <div v-if="showExamTimes === false" class="empty-img">
      <img src="../../assets/image/noData.png" />
    </div>
    <div class="chart-remarks">注：本报表数据来源包括用户参加正式考试次数，不包含摸底考试次数。</div>
    <div class="spacing"></div>
    <!-- <div class="chart-title">完成项目考试分数情况</div> -->
    <div class="chart-title-more">
      <p>完成项目考试分数情况</p>
      <el-radio-group v-if="showExamScore === true && showRadioValue === 0" class="rank-radio" size="medium" v-model="rankType" @change="changeRank">
        <el-radio-button label="1">1分</el-radio-button>
        <el-radio-button label="5">5分</el-radio-button>
        <el-radio-button label="10">10分</el-radio-button>
      </el-radio-group>
      <!-- <div v-if="showRadioValue === 1" class="change-radio">{{ changeRadio[rankType] }}</div> -->
    </div>
    <div v-if="showExamScore === true" class="overflow-chart">
      <div class="chart" id="examScore" ref="examScore"></div>
    </div>
    <div v-if="showExamScore === false" class="empty-img">
      <img src="../../assets/image/noData.png" />
    </div>
    <div class="chart-remarks">注：本报表数据来源包括用户参加正式考试，不包含摸底考试。</div>
    <div class="spacing"></div>
    </div>
    <div class="chart-title">考试列表</div>
    <div v-if="downloadId == null">
      <el-table :data="tableData" class="exam-table">
        <el-table-column prop="examType" label="类型" align="center"></el-table-column>
        <el-table-column prop="examName" label="考试名" min-width="150" align="center"></el-table-column>
        <el-table-column prop="doctorCount" label="应参与考试人数" align="center"></el-table-column>
        <el-table-column prop="passCount" label="通过考试人数" align="center"></el-table-column>
        <el-table-column prop="passRate" label="整体通过率" align="center">
          <template slot-scope="scope">{{ scope.row.passRate | examRate }}</template>
        </el-table-column>
        <el-table-column prop="joinCount" label="参与考试人数" align="center"></el-table-column>
        <el-table-column prop="joinRate" label="参与通过率" align="center">
          <template slot-scope="scope">{{ scope.row.joinRate | examRate }}</template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="100">
          <template slot-scope="scope">
            <el-button class="button-jump" type="text" size="small" @click="goPage(scope.row)">查看名单</el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <div class="table-empty">
            <img src="../../assets/image/noData.png" />
          </div>
        </div>
      </el-table>
    </div>
    <div v-if="downloadId != null">
      <el-table :data="tableData.slice((pageNo-1)*pageSize,pageNo*pageSize)" class="exam-table">
        <el-table-column prop="examType" label="类型" align="center"></el-table-column>
        <el-table-column prop="examName" label="考试名" min-width="150" align="center"></el-table-column>
        <el-table-column prop="doctorCount" label="应参与考试人数" align="center"></el-table-column>
        <el-table-column prop="passCount" label="通过考试人数" align="center"></el-table-column>
        <el-table-column prop="passRate" label="整体通过率" align="center">
          <template slot-scope="scope">{{ scope.row.passRate | examRate }}</template>
        </el-table-column>
        <el-table-column prop="joinCount" label="参与考试人数" align="center"></el-table-column>
        <el-table-column prop="joinRate" label="参与通过率" align="center">
          <template slot-scope="scope">{{ scope.row.joinRate | examRate }}</template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="100">
          <template slot-scope="scope">
            <el-button class="button-jump" type="text" size="small" @click="goPage(scope.row)">查看名单</el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <div class="table-empty">
            <img src="../../assets/image/noData.png" />
          </div>
        </div>
      </el-table>
    </div>
    <div class="pagination">
      <el-pagination
        class="pagination"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="[20, 50 ,100, 200]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalRows"
      ></el-pagination>
    </div>
    <div class="spacing"></div>
  </div>
</template>

<script>
import { log } from "util";
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;
export default {
  props: {
    formInline: {
      type: Object
    },
    activeName: {
      type: String
    },
    dialogData: {
      type: Object
    },
    organizationList: {
      type: Array
    },
    timeInfoData: {
      type: Object
    },
    containOfficialFlag: {
      type: Number
    },
    showRadio: {
      type: Number
    },
  },
  data() {
    return {
      projectId: "",
      tableData: [],
      cardData: [],
      totalRows: 0, //数据总数
      pageNo: 1, //当前是第几页
      pageSize: 20, //页面总数
      labelTd: [],
      showTd: [false, false, false, false],
      echartsData: {
        chart0: {},
        chart1: {}
      },
      examData: {},
      rankType: '1',
      timeInfoChild: {},
      downloadId: null,
      showExamTimes: true,
      showExamScore: true,
      containOfficial: 1,
      changeRadio: {
        '1': '1分',
        '5': '5分',
        '10': '10分',
      },
      showRadioValue: 0,
    };
  },
  watch: {
    timeInfoData: {
      deep: true,
      handler(nv, ov) {
        vm.timeInfoChild = nv;
      }
    },
    containOfficialFlag: {
      deep: true,
      handler(nv, ov) {
        vm.containOfficial = nv;
      }
    },
    showRadio: {
      deep: true,
      handler(nv, ov) {
        vm.showRadioValue = nv;
      }
    },
  },
  created() {
    vm = this;
    vm.projectId = vm.getUrlSearch(window.location.href, "id");
    vm.downloadId = vm.getUrlSearch(window.location.href, "downloadId");
  },
  // 挂载到Dom完成时
  mounted: function() {
    this.$on("search", () => {
      // console.log(this.formInline);
      this.pageNo = 1;
      this.rankType = '1';
      this.search();
      this.searchTable();
    });
    this.$on("init", () => {
      this.$nextTick(function() {
        if (vm.formInline.region.length != 0) {
          this.search();
          this.searchTable();
        }
      });
    });
    this.$on("reset", () => {
      this.pageNo = 1;
      this.pageSize = 20;
      this.tableData = [];
      this.cardData = [];
    });
    this.$on("static", () => {
      vm.getStatic();
    });
  },
  methods: {
    // 搜索列表
    getStatic() {
      let examAnalysisModel = vm.timeInfoChild.examAnalysisModel;
      vm.containOfficial = vm.timeInfoChild.doctorInfoRep.containOfficialFlag;
      vm.setCardData(examAnalysisModel);
      if(vm.containOfficial === 1) {
        vm.setExamTimes(examAnalysisModel.examTimesList);
        vm.setExamScore(examAnalysisModel.examScoreList);
      }

      vm.tableData = examAnalysisModel.examListDto.examInfoList;
      vm.totalRows = examAnalysisModel.examListDto.totalRows;
    },
    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 ? 2 : 1,
        // regionId: vm.formInline.region[vm.formInline.region.length - 1],
        regionId: vm.formInline.selectRegionId,
        timeFlag: vm.formInline.timeFlag
      };
      vm.POST("stats/report/exam", req, '', '', true).then(res => {
        if (res.code == "000000") {
          vm.examData = res.data;
          vm.setCardData(res.data);
          if(vm.containOfficial === 1) {
            vm.setExamTimes(res.data.examTimesList);
            vm.setExamScore(res.data.examScoreList);
          }
        } else {
          vm.$message(res.message);
        }
      });
    },
    //获取考试列表数据
    searchTable() {
      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 ? 2 : 1,
        // regionId: vm.formInline.region[vm.formInline.region.length - 1],
        regionId: vm.formInline.selectRegionId,
        timeFlag: vm.formInline.timeFlag
      };
      let reqList = req;
      reqList.pageNo = vm.pageNo;
      reqList.pageSize = vm.pageSize;
      // openLoading(vm);
      vm.POST("stats/report/exam/list", req, '', '', true).then(res => {
        // closeLoading(vm);
        if (res.code == "000000") {
          vm.tableData = res.data.examInfoList;
          vm.totalRows = res.data.totalRows;
        }
      });
    },
    setCardData(data) {
      // vm.totalRows = data.projectExamCount;
      let cardData = [
        {
          title: "项目正式考试数",
          value: "0门"
        },
        {
          title: "项目摸底考试数",
          value: "0门"
        },
        {
          title: "项目所有考题数",
          value: "0道"
        }
      ];
      cardData[0].value = data.afterExamCount + "门";
      cardData[1].value = data.beforeExamCount + "门";
      cardData[2].value = data.examTitleCount + "道";
      vm.cardData = cardData;
    },
    updateResize() {
      setTimeout(function() {
        window.onresize = function() {
          vm.echartsData.chart0.resize();
          vm.echartsData.chart1.resize();
        };
      }, 30);
    },
    //设置--完成项目考试次数情况
    setExamTimes(data) {
      if(data.length == 0) {
        vm.showExamTimes = false;
        return;
      } else {
        vm.showExamTimes = true;
      }
      let xAxisData = [];
      let seriesData = [];
      for (let i = 0; i < data.length; i++) {
        xAxisData.push(data[i].times + "次");
        seriesData.push(data[i].count);
      }
      setTimeout(function(){
        let myChart = echarts.init(vm.$refs.examTimes);
        let option = chartData.examTimes(xAxisData, seriesData);
        myChart.setOption(option);
        vm.echartsData.chart0 = myChart;
      },20);
    },
    changeRank(value) {
      console.log(value);
      if(vm.downloadId == null) {
        if(value == '1') {
          vm.setExamScore(vm.examData.examScoreList);
        } else if(value == '5') {
          vm.setExamScore(vm.examData.fiveExamScoreList);
        } else if(value == '10') {
          vm.setExamScore(vm.examData.tenExamScoreList);
        }
      } else {
        let examAnalysisModel = vm.timeInfoChild.examAnalysisModel;
        if(value == '1') {
          vm.setExamScore(examAnalysisModel.examScoreList);
        } else if(value == '5') {
          vm.setExamScore(examAnalysisModel.fiveExamScoreList);
        } else if(value == '10') {
          vm.setExamScore(examAnalysisModel.tenExamScoreList);
        }
      }
    },
    //设置--完成项目考试分数情况
    setExamScore(data) {
      if(data.length == 0) {
        vm.showExamScore = false;
        return;
      } else {
        vm.showExamScore = true;
      }
      let xAxisData = [];
      let seriesData = [];
      for (let i = 0; i < data.length; i++) {
        xAxisData.push(data[i].timesStr);
        seriesData.push(data[i].count);
      }
      setTimeout(function(){
        let myChart = echarts.init(vm.$refs.examScore);
        let option = chartData.examScore(xAxisData, seriesData);
        myChart.setOption(option);
        vm.echartsData.chart1 = myChart;
      },20);
    },
    // 跳转查看名单页面
    goPage(data) {
      let routerData = {};
      if(vm.downloadId == null) {
        routerData = this.dialogData;
        routerData.projectId = vm.projectId;
        routerData.projectName = vm.getUrlSearch(
          window.location.href,
          "projectName"
        );
        routerData.tableType = 2;
        routerData.examId = data.examId;
        routerData.beginDate = operationData.setDuringTime(vm.formInline.during, "begin"),
        routerData.endDate = operationData.setDuringTime(vm.formInline.during, "end"),
        // routerData.regionId = vm.formInline.region[vm.formInline.region.length - 1];
        routerData.regionId = vm.formInline.selectRegionId;
        routerData.originalFlag = vm.formInline.checked == false ? 2 : 1;
        routerData.timeFlag = vm.formInline.timeFlag;
        routerData.hospitalIdList = operationData.setHospitalIdList(vm.formInline.organization);
      } else {
        let reportParamModel = vm.timeInfoChild.reportParamModel;
        routerData.base = 'static';
        routerData.region = reportParamModel.regionNames;
        routerData.organization = reportParamModel.hospitalNames;
        routerData.projectId = reportParamModel.projectId,
        routerData.projectName = reportParamModel.projectName,
        routerData.tableType = 2;
        routerData.examId = data.examId;
        routerData.beginDate = reportParamModel.beginDate;
        routerData.endDate = reportParamModel.endDate;
        routerData.regionId = reportParamModel.regionId;
        routerData.originalFlag = reportParamModel.originalFlag;
        routerData.timeFlag = reportParamModel.timeFlag;
        routerData.hospitalIdList = operationData.setHospitalIdList(reportParamModel.hospitalIdList);
      }

      // this.$router.push({ path: '/name-list', query: routerData});
      let routeData = this.$router.resolve({
        path: "/name-list",
        query: routerData
      });
      window.open(routeData.href, "_blank");
    },
    // 更改数据显示数量
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      vm.pageSize = val;
      vm.pageNo = 1;
      if(vm.downloadId == null) {
        vm.searchTable();
      }
    },
    // 换页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      vm.pageNo = val;
      if(vm.downloadId == null) {
        vm.searchTable();
      }
    }
  }
};
</script>

<style lang='scss' rel='stylesheet/scss'>
.examination-analysis {
  background: #fff;
  overflow: hidden;
  .change-radio {
    position: relative;
    float: right;
    top: 27px;
    right: 55px;
    margin-left: -60px;
    width: 80px;
    height: 34px;
    background:rgba(68,146,132,1);
    border-radius:4px;
    font-size:14px;
    line-height: 34px;
    text-align: center;
    color: #fff;
  }
  .el-card {
    border-width: 0px;
  }
  .el-card.is-always-shadow {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.1);
  }
  .line {
    background: #e4e4e4;
    height: 80px;
    width: 1px;
    float: left;
    margin-top: 20px;
  }
  .table {
    margin-top: 30px;
  }
  .spacing {
    position: relative;
    width: 100%;
    height: 20px;
    background: #f0f2f5;
  }
  .box-list {
    position: relative;
    height: 110px;
    background: #f0f2f5;
    .box-card {
      position: relative;
      background-color: #ffffff;
      width: 32%;
      margin-right: 2%;
      height: 120px;
      float: left;
      .el-card__header {
        border-bottom-width: 0;
      }
      .el-card__body {
        padding: 0px;
      }
      .value {
        color: #373839;
        text-align: center;
        margin-top: 24px;
        margin-bottom: 8px;
        height: 45px;
        line-height: 45px;
        font-size: 32px;
        font-weight: 500;
      }
      .title {
        color: #666666;
        text-align: center;
        font-size: 14px;
        height: 20px;
        line-height: 20px;
      }
    }
    .box-last {
      margin-right: 0%;
    }
  }
  .chart-title {
    position: relative;
    margin-top: 30px;
    margin-left: 30px;
    height: 25px;
    font-size:18px;
    font-weight:600;
    line-height: 25px;
    color: #000000;
  }
  .chart-title-more {
    position: relative;
    width: 100%;
    height: 70px;
    p {
      position: relative;
      float: left;
      width: 400px;
      margin-top: 30px;
      margin-left: 30px;
      height: 25px;
      font-size:18px;
      font-weight:600;
      line-height: 25px;
      color: #000000;
    }
    .rank-radio {
      position: relative;
      margin: 30px 30px 0 0;
      float: right;
      .el-radio-button__inner {
        padding: 7px 29px;
      }
    }
  }
  .chart {
    position: relative;
    margin: 0 auto 0 auto;
    width: 1064px;
    height: 380px;
  }
  .chart-remarks {
    position: relative;
    height: 66px;
    padding: 20px 0 30px 30px;
    font-size: 16px;
    font-weight: 400;
    line-height: 16px;
    color: #666666;
  }
  .exam-table {
    top: 20px;
    padding: 0;
    width: 95%;
    margin:0 auto 20px auto;
    .button-jump {
      color: #449284;
    }
  }
  .pagination {
    margin-top: 30px;
    margin-right: 13px;
  }
  .table-empty {
    img {
      height: 24px;
      width: 106px;
    }
  }
}
</style>
