<template>
  <div class="item-list-wrap">
    <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond" :curmbThird="curmbThird" :jumPathThird="jumPathThird"></bread-crumb>
    <div class="component-content screenSet" id="screenSet">
      <div v-if="staticData == 1" class="item-form">
        <div class="form-title">查询条件</div>
        <div class="form-p">
          <p>
            <span>选择地区</span>  
            <span class="span-value">{{ reportParamModel.regionNames }}</span>
          </p>
          <p>
            <span>原始数据</span> 
            <span class="span-value">{{ reportParamModel.originalFlag === 2 ? '否' : '是' }}</span>
          </p>
          <p>
            <span>选择机构</span> 
            <span class="span-value">{{ reportParamModel.hospitalNames }}</span>
          </p>
          <p>
            <span >选择时间</span>
            <span class="span-value">{{ reportParamModel.beginDate }}-{{ reportParamModel.endDate }}</span>
          </p>
        </div>
        <div class="buttom-line"></div>
      </div>
      <el-form v-if="staticData == 0" class="item-form" ref="formInline" :model="formInline" label-width="80px">
        <div class="form-title">查询条件</div>
        <el-form-item label="选择地区：">
          <!-- :props="props" -->
          <el-col :span="12">
          <el-cascader
            size="small"
            ref="cascaderRegion"
            :options="optionsRegion"
            :props="props"
            v-model="formInline.region"
            @change="handleChange"
            filterable
            change-on-select
            placeholder="请先选择地区后再进行查询"
            style="width:330px"
          ></el-cascader>
          </el-col>
          <el-col :span="6">
            <el-checkbox v-if="showOriginal == 1" size="small" v-model="formInline.checked">查看原始数据</el-checkbox>
          </el-col>
        </el-form-item>
        <el-form-item label="选择机构：">
          <div class="form-text" v-if="optionsRegion.length == 1 && hospitalCntList.length == 1">{{ hospitalCntList[0].hospitalName }}</div>
          <el-select
            v-else
            size="small"
            v-model="formInline.organization"
            :placeholder="organizationNotice"
            @change="changeOrganization"
            multiple
            collapse-tags
            :disabled="areaLen < 3"
            style="width:330px"
          >
            <el-option
              v-for="item in organizationList"
              :key="item.index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <div class="tag-group">
          <el-tag
            v-for="tag in tags"
            :key="tag.value"
            type="info"
            closable
            @close="handleTagClose(tag)"
          >{{ tag.label }}</el-tag>
        </div>
        <el-form-item label="选择时间：">
          <el-col :span="12">
            <el-select 
              size="small"
              v-model="formInline.timeFlag" 
              placeholder="请选择"
              style="width:330px;"
              @change="changeTimeFlag"
              >
              <el-option
                v-for="item in timeFlagList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="8" v-show="formInline.timeFlag == 2">
            <el-date-picker
              size="small"
              v-model="formInline.during"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions0">
            </el-date-picker>
          </el-col>
        </el-form-item>
        <div class="buttom-line"></div>
        <!-- <el-form-item label v-if="showOriginal !== 1">
          <el-checkbox size="small" v-model="formInline.checked">查看原始数据</el-checkbox>
        </el-form-item> -->
        <div v-if="staticData == 0" class="form-button">
          <el-button size="small" @click="search()" type="primary">查询</el-button>
          <el-button size="small" @click="resetForm()">重置</el-button>
        </div>
      </el-form>
      <div class="button-group">
        <el-button class="" v-if="roleType == 1 || roleType == 2" type="default" size="small" @click="changeDate">数据修改</el-button>
        <el-button class="" type="default" size="small" @click="exportPDF">导出PDF</el-button>
        <el-button class="" type="default" size="small" :disabled="exportStatus" @click="exportExcel">导出明细</el-button>
      </div>
      <div class="item-tab"></div>
      <el-tabs class="item-list-tabs" ref="tabs" id="item-list-tabs" v-model="activeName" @tab-click="handleClick" :before-leave="beforeLeave">
        <el-tab-pane label="总体情况" name="zero" >
          <data-all
            ref="childDataAll"
            :formInline="formInline"
            :activeName="activeName"
            :organizationNum="organizationNum"
            :organizationList="organizationList"
            :timeInfoData="timeInfoData"
            :showRadio="showRadio"
          ></data-all>
        </el-tab-pane>
        <!-- <el-tab-pane label="参与情况" name="first">
          <part-in
            ref="childPart"
            :formInline="formInline"
            :activeName="activeName"
            :organizationNum="organizationNum"
            :organizationList="organizationList"
          ></part-in>
        </el-tab-pane> -->
        <el-tab-pane label="人群分析" name="second">
          <crowd-analysis
            ref="childCrowd"
            :formInline="formInline"
            :activeName="activeName"
            :organizationList="organizationList"
            :timeInfoData="timeInfoData"
            :showRadio="showRadio"
          ></crowd-analysis>
        </el-tab-pane>
        <el-tab-pane label="课程分析" name="third" v-if="displayCourse == 1">
          <course-analysis
            ref="childCourse"
            :formInline="formInline"
            :activeName="activeName"
            :dialogData="dialogData"
            :organizationList="organizationList"
            :timeInfoData="timeInfoData"
          ></course-analysis>
        </el-tab-pane>
        <el-tab-pane label="考试分析" name="fourth" v-if="displayExam == 1">
          <examination-analysisfrom
            ref="childExam"
            :formInline="formInline"
            :activeName="activeName"
            :dialogData="dialogData"
            :organizationList="organizationList"
            :timeInfoData="timeInfoData"
            :containOfficialFlag="containOfficialFlag"
            :showRadio="showRadio"
          ></examination-analysisfrom>
        </el-tab-pane>
        <el-tab-pane label="学习效果分析" name="fifth" v-if="displayEffect == 1">
          <learning-effect 
            ref="childEffect"
            :formInline="formInline"
            :activeName="activeName"
            :timeInfoData="timeInfoData"
          ></learning-effect>
        </el-tab-pane>
      </el-tabs>
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" center>
        <p style="text-align:center">您的导出预计将在24小时内完成，是否继续？</p>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="exportHttp()">继续导出</el-button>
        </span>
      </el-dialog>
      <el-dialog title="提示" :visible.sync="dialogSearch" width="30%" center>
        <p style="text-align:center">您的报告预计将在24小时内生成，是否继续？</p>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogSearch = false">取消</el-button>
          <el-button type="primary" @click="exportTime()">继续生成</el-button>
        </span>
      </el-dialog>
      <el-dialog title :visible.sync="dialogUpdate" width="80%" center>
        <!-- <el-button @click="dialogUpdate = false">取 消</el-button> -->
        <data-alignment
          ref="childAlignment"
          @closeDialog="dialogUpdate = false"
          @closeSearch="closeSearch"
          :formInline="formInline"
          :dialogData="dialogData"
          :organizationList="organizationList"
        ></data-alignment>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import CourseAnalysis from "./item-course-analysis.vue";
import CrowdAnalysis from "./item-crowd-analysis.vue";
import PartIn from "./item-part-in.vue";
import ExaminationAnalysisfrom from "./item-examination-analysis.vue";
import LearningEffect from "./item-learning-effect.vue";
import DataAlignment from "./data-alignment.vue";
import DataAll from "./item-data-all.vue";
import { create } from "domain";
import { mapGetters } from "vuex";
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
import * as operationData from "../../utils/operation";
import { log } from "util";
import html2Canvas from 'html2canvas';
import JsPDF from 'jspdf';

let vm = null;
export default {
  components: {
    BreadCrumb,
    CourseAnalysis,
    CrowdAnalysis,
    PartIn,
    ExaminationAnalysisfrom,
    LearningEffect,
    DataAlignment,
    DataAll,
  },
  data() {
    return {
      curmbFirst: "学情报告",
      curmbSecond: "项目列表",
      curmbThird: "",
      jumPathThird: "/report-list",
      projectId: "",
      projectName: "",
      exportStatus: false,
      organizationList: [],
      optionsRegion: [],
      props: {
        lazy: true,
        lazyLoad(node, resolve) {
          const { level } = node;
          // console.log("node props", node);
          if (node.level >= 1 && node.loaded === false && node.children.length == 0) {
            let req = {
              projectId: vm.projectId,
              regionId: node.data.value
            };
            vm.GET("stats/region", req).then(res => {
              let newData = vm.setRegionOptionMore(res.data.list);
              // console.log("newData", newData);
              resolve(newData);
            });
          } else {
            resolve()
          }
        }
      },
      showOriginal: 2,
      roleType: '',
      formInline: {
        region: [],
        date: "",
        organization: [],
        checked: false,
        timeFlag: 1,
        during: null,
        pageNo: 1,
        pageSize: 20,
      },
      organizationNotice: '选择地区筛选到区才能选择机构',
      dialogData: {
        region: "全部",
        // regionData: "",
        organization: ""
        // organizationData: "",
      },
      tags: [],
      activeName: "zero",
      organizationNum: 0,
      dialogVisible: false,
      dialogUpdate: false,
      displayExam: 1,
      flag: 1,
      //v2.0更新data部分
      timeFlagList: [
        {
          value: 1,
          label: '截至昨日',
        },
        {
          value: 2,
          label: '自定义时间',
        }
      ],
      areaLen: 1,
      hospitalCnt: 0,
      hospitalId: [],
      certFlag: 0,
      displayCourse: 1,
      displayEffect: 1,
      exportReq: {},
      dialogSearch: false,
      downloadId: null,
      staticData: 0,
      timeInfoData: {},
      reportParamModel: {
        beginDate: "",
        endDate: "",
        regionNames: "",
        hospitalNames: "",
        originalFlag: 2
      },
      hospitalCntList: [],
      maxDate: '',
      minDate: '',
      allRegionId: '',
      containOfficialFlag: 1,
      showRadio: 0,
      pickerOptions0: {
        disabledDate: time => {
          // 在科学计数法中，为了使公式简便，可以用带“E”的格式表示。例如1.03乘10的8次方，可简写为“1.03e8”的形式
          // 一天是24*60*60*1000 = 86400000 = 8.64e7
          // console.log('this.maxDate',this.maxDate)
          return time.getTime() > new Date(this.maxDate).getTime() || time.getTime() < new Date(this.minDate).getTime() - 8.64e7;
        }
      }, 
    };
  },
  computed: {
    ...mapGetters(["_token"])
  },
  watch: {
    tags: function(val) {
      this.setDialogData();
    },
    formInline() {
      if (this.$refs.optionsRegion) {
        this.$refs.optionsRegion.dropDownVisible = false; //监听值发生变化就关闭它
      }
    }
  },
  created() {
    vm = this;
    this.projectId = vm.getUrlSearch(window.location.href, "id");
    this.projectName = vm.getUrlSearch(window.location.href, "projectName");
    this.curmbThird = vm.getUrlSearch(window.location.href, "projectName");
    this.downloadId = vm.getUrlSearch(window.location.href, "downloadId");
    this.checkShowType();
    // this.getDisplay();
    // this.search();
    // this.getRegionOption();
  },
  mounted: function() {
    commonUtil.resizeHeight();
    // setInterval(function() {
    //   document.querySelectorAll(".el-cascader-node").forEach(el => {
    //     el.onclick = function() {
    //       if (this.previousElementSibling) this.previousElementSibling.click();
    //     };
    //   });
    // }, 1000);
  },
  methods: {
    checkShowType() {
      if(vm.downloadId == null) {
        vm.getDisplay();

        vm.curmbSecond = "项目列表";
        vm.jumPathThird = "/report-list";
      }
      if(vm.downloadId != null) {
        vm.staticData = 1;
        vm.exportTimeInfo();

        vm.curmbSecond = "任务列表";
        vm.jumPathThird = "/export-download";
      }
    },
    exportTimeInfo() {
      let req = {};
      openLoading(vm);
      vm.GET("stats/export/time/info/"+ vm.downloadId, req).then(res => {
        closeLoading(vm);
        if(res.code == "000000") {
          vm.timeInfoData = res.data;
          vm.reportParamModel = res.data.reportParamModel;
          let doctorInfoRep = res.data.doctorInfoRep;
          vm.displayCourse = doctorInfoRep.existCourse;
          vm.displayExam = doctorInfoRep.existExam;
          vm.displayEffect = doctorInfoRep.existEffect;
          vm.curmbThird = res.data.reportParamModel.projectName;
          setTimeout(function() {
            vm.$refs.childDataAll.$emit("static");
            vm.$refs.childCrowd.$emit("static");
            if(doctorInfoRep.existCourse == 1) {
              vm.$refs.childCourse.$emit("static");
            }
            if(doctorInfoRep.existExam == 1) {
              vm.$refs.childExam.$emit("static");
            }
            if(doctorInfoRep.existEffect == 1) {
              vm.$refs.childEffect.$emit("static");
            }
          },20);
        } else {
          vm.$message(res.message);
        }
      });
    },
    getDisplay(type) {
      let reqInfo = {
        projectId: vm.projectId,
      };
      vm.GET("stats/region/info", reqInfo).then(res => {
        if (res.code == "000000") {
          vm.showOriginal = res.data.status;
          vm.roleType = res.data.roleType;
          vm.displayCourse = res.data.existCourse;
          vm.displayExam = res.data.existExam;
          vm.displayEffect = res.data.existEffect;
          vm.certFlag = res.data.certFlag;
          vm.maxDate =  new Date(res.data.maxDate);
          vm.minDate = new Date(res.data.minDate);
          vm.containOfficialFlag = res.data.containOfficialFlag;
          // console.log('日期:',vm.maxDate,vm.minDate)
          vm.getRegionOption();
        }
      });
    },
    beforeLeave(activeName, oldActiveName) {
      // console.log('action',activeName,'oldActive',oldActiveName)
    },
    handleClick(tab, event) {
      // console.log("activeName", this.activeName, tab.name);
      // if (tab.name == "first") {
      //   this.$refs.childPart.$emit("init");
      // } else if (tab.name == "second") {
      //   this.$refs.childCrowd.$emit("init");
      // } else if (tab.name == "third") {
      //   this.$refs.childCourse.$emit("init");
      // } else if (tab.name == "fourth") {
      //   this.$refs.childExam.$emit("init");
      // }
    },
    handleChange(value) {
      this.formInline.organization = [];
      this.tags = [];
      let node =this.$refs.cascaderRegion.getCheckedNodes()[0];
      console.log('node change',node)

      setTimeout(function() {
        // console.log('行政区域改变',vm.$refs["cascaderRegion"].inputValue);
        vm.dialogData.region = vm.$refs["cascaderRegion"].inputValue;
      }, 20);
      // console.log('region',value,vm.formInline);

      if(node.label !== '全部') {
        let areaArr = value[value.length -1].split('_');
        vm.areaLen = areaArr.length;
        // console.log('areaArr!!',areaArr);
        if (areaArr.length >= 3) {
          this.getOrganizationList();
          this.organizationNotice = "请选择机构";
        } else {
          this.organizationNotice = "选择地区筛选到区才能选择机构";
        }
      } else {
        vm.areaLen = 1;
        vm.organizationNotice = "选择地区筛选到区才能选择机构";
      }

      vm.gethHspitalsCnt()

      //添加子节点
      // let node =this.$refs.cascaderRegion.getCheckedNodes()[0];
      if(node.data && node.data.id && node.hasChildren === true && node.loaded === false) {
        let req = {
          projectId: vm.projectId,
          regionId: node.data.value
        };
        vm.GET("stats/region", req).then(res => {
          let newData = vm.setRegionOptionMore(res.data.list);
          vm.searchNode(vm.optionsRegion, node.data.id, newData);
        });
      }
    },
    searchNode(val,id,data){
      val.map(item=>{
          if(item.id===id){
              vm.$set(item,'children',data)
          }else if(item.children&&item.children.length){
              return vm.searchNode(item.children,id,data)
          }
          return item
      })
    },
    setRegionOptionMore(data) {
      let option = [];
      for (let i = 0; i < data.length; i++) {
        let obj = data[i];
        obj.label = data[i].label;
        obj.value = data[i].id;
        if(obj.degree == 4) {
          obj.leaf = true;
        }
        option.push(obj);
      }
      return option;
    },
    changeOrganization(value) {
      // console.log('formInline',this.formInline.organization);
      this.tags = [];
      //选了全部的情况下
      for (let a = 0; a < this.formInline.organization.length; a++) {
        if (this.formInline.organization[a] == 0) {
          //选了全部
          let tagItem = {
            label: "全部",
            value: 0
          };
          this.tags.push(tagItem);
          return;
        }
      }
      //没选全部
      for (let i = 0; i < this.organizationList.length; i++) {
        for (let j = 0; j < value.length; j++) {
          if (value[j] == this.organizationList[i].value) {
            // console.log('value[j]',j,value[j],this.organizationList[i].label )
            let tagItem = {
              label: this.organizationList[i].label,
              value: this.organizationList[i].value
            };
            this.tags.push(tagItem);
          }
        }
      }
    },
    handleTagClose(tag) {
      // console.log(tag);
      //选了全部的情况下
      if (this.tags.length > 0 && this.tags[0].value == 0) {
        this.tags.splice(0, 1);
        this.formInline.organization = [];
        return;
      }
      //没全部的情况下
      for (let i = 0; i < this.tags.length; i++) {
        if (tag.value == this.tags[i].value) {
          this.tags.splice(i, 1);
          this.formInline.organization.splice(
            this.formInline.organization.indexOf(tag.value),
            1
          );
          break;
        }
      }
    },
    getMoreRegion() {
      let http = new Promise((resolve, reject) => {
        let req = {
          provinceId: 350
        };
        vm.GET("basic-data/position/cities", req).then(res => {
          resolve(res);
        });
      });
      console.log("http值", http);
      return http;
    },
    //获取地区
    getRegionOption() {
      let req = {
        projectId: vm.projectId,
      };
      vm.GET("stats/region", req, '', '', true).then(res => {
        if (res.code == "000000") {
          vm.formInline.region = [];
          vm.formInline.region[0] = res.data.list[0].id;
          vm.allRegionId = res.data.list[0].id;
          vm.optionsRegion = operationData.setRegionOptionNew(
            res.data.list
          );
          //初始化判断区域id 是不是有机构id
          let value = res.data.list[0].id;
          let areaArr = value.split('_');
          vm.areaLen = areaArr.length;
          if (areaArr.length >= 3) {
            vm.getOrganizationList();
            vm.organizationNotice = "请选择机构";
          }
          // vm.search(); // deleted by Anndy Yang
          vm.gethHspitalsCnt();
        }
      });
    },
    gethHspitalsCnt() {
      let req = {
        projectId: vm.projectId,
        regionId: vm.formInline.region[vm.formInline.region.length - 1]
      };
      vm.GET("stats/region/hospitals/cnt", req, '', '', false).then(res => {
        if (res.code == "000000") {
          vm.hospitalCnt = res.data.hospitalCnt;
          vm.hospitalCntList = res.data.list

          // 只有一个机构时，所有请求中要传递机构ID added by Anndy Yang
          if(vm.hospitalCntList.length == 1) {
            vm.formInline.organization = [];
            vm.organizationList = [];
            let obj = {
              index: 0,
              label: vm.hospitalCntList[0].hospitalName,
              value: vm.hospitalCntList[0].hospitalId,
            };
            vm.organizationList.push(obj);
            vm.formInline.organization.push(vm.hospitalCntList[0].hospitalId);
            // vm.formInline.organization[0] = vm.hospitalCntList[0].hospitalId;
          }
          vm.search(); // added by Anndy Yang
        }
      });
    },
    //获取机构列表
    getOrganizationList() {
      vm.organizationList = [];
      let regionId = vm.formInline.region[vm.formInline.region.length - 1];
      let req = {
        projectId: vm.projectId,
        regionId : regionId
      };
      vm.GET("stats/region/hospital", req, '', '', true).then(res => {
        if (res.code == "000000") {
          this.organizationList = operationData.getLearnOrganization(
            res.data.list
          );

          // // added by Anndy Yang
          // if(this.organizationList.length == 1) {
          //   vm.formInline.organization = [];
          //   vm.formInline.organization = vm.organizationList[0].value
          // }
        }
      });
    },
    getOrganizationNum() {
      //选择全部
      let num = 0;
      if (this.tags.length == 0) {
        return;
      }
      if (this.tags[0].value == 0) {
        num = this.organizationList.length - 1;
        return num;
      }
      //没有选择全部
      num = this.tags.length;
      return num;
    },
    closeSearch() {
      vm.dialogUpdate = false;
      vm.getDisplay(2);
      vm.resetForm();
    },
    setExportReq() {
      vm.exportReq = {
        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],
        timeFlag: vm.formInline.timeFlag,
      };
    },
    changeTimeFlag(value) {
      if(value == 1) {
        vm.formInline.during = null;
      }
    },
    exportTime() {
      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],
        timeFlag: vm.formInline.timeFlag,
        hospitalNames: vm.dialogData.organization,
        regionNames: vm.dialogData.region,
      };
      if(vm.organizationList.length == 1) {
        req.hospitalIdList = [];
        req.hospitalIdList[0] = vm.organizationList[0].value;
      }
      // if(req.regionNames == '全部') {
        //全部地区 机构只有一个情况
      if(vm.hospitalCntList.length == 1) {
        req.hospitalIdList = [];
        req.hospitalIdList[0] = vm.hospitalCntList[0].hospitalId;
      }
      // }
      openLoading(vm);
      vm.POST("stats/export/time", req).then(res => {
        closeLoading(vm);
        if(res.code == "000000") {
          vm.$router.push("export-download?projectId="+vm.projectId+'&listType=2');
        } else {
          vm.$message(res.message)
        }
        vm.dialogSearch = false;
      });
    },
    search() {
      // console.log(vm.formInline);
      if(vm.formInline.timeFlag == 1) {
        //截止昨日
        vm.setExportReq();
        vm.$refs.childDataAll.$emit("search");
        vm.$refs.childCrowd.$emit("search");
        if(vm.displayCourse == 1) {
          vm.$refs.childCourse.$emit("search");
        }
        if(vm.displayExam == 1) {
          vm.$refs.childExam.$emit("search");
        }
        if(vm.displayEffect == 1) {
          vm.$refs.childEffect.$emit("search");
        }
      } else if(vm.formInline.timeFlag == 2) {
        //开始时间结束时间
        if(vm.formInline.during == null) {
          vm.$message('自定义时间，请选择时间段！')
        } else {
          vm.dialogSearch = true;
        }
      }

      // if (this.activeName == "first") {
      //   this.organizationNum = this.getOrganizationNum();
      //   // console.log('this.organizationNum',this.organizationNum)
      //   this.$nextTick(function() {
      //     this.$refs.childPart.$emit("search");
      //   });
      // } else if (this.activeName == "second") {
      //   this.$refs.childCrowd.$emit("search");
      // } else if (this.activeName == "third") {
      //   this.$refs.childCourse.$emit("search");
      // } else if (this.activeName == "fourth") {
      //   this.$refs.childExam.$emit("search");
      // }
    },
    //重置
    resetForm() {
      vm.formInline = Object.assign(
        {},
        {
          region: [],
          date: "",
          organization: [],
          checked: false,
          timeFlag: 1,
          during: null,
          pageNo: 1,
          pageSize: 20,
        }
      );
      vm.formInline.region[0] = vm.allRegionId;
      vm.areaLen = 0;
      vm.tags = [];

      setTimeout(function(){
        vm.search();
      },20)

      // if (this.activeName == "first") {
      //   this.$refs.childPart.$emit("reset");
      // } else if (this.activeName == "second") {
      //   this.$refs.childCrowd.$emit("reset");
      // } else if (this.activeName == "third") {
      //   this.$refs.childCourse.$emit("reset");
      // } else if (this.activeName == "fourth") {
      //   this.$refs.childExam.$emit("reset");
      // }
    },
    exportExcel() {
      if(vm.downloadId == null) {
        //按钮置灰三秒
        vm.exportStatus = true;
        setTimeout(function() {
          vm.exportStatus = false;
        },3000);
        this.dialogVisible = true;
      } else {
        let downloadUrl = vm.timeInfoData.excelDownUrl;
        if(downloadUrl === '' || downloadUrl === null) {
          this.$message('导出失败请联系客服。');
          return;
        }
        setTimeout(() => {
          window.open(downloadUrl);
        }, 500);
      }
    },
    exportHttp() {
      let req = vm.exportReq;
      openLoading(vm);
      vm.POST("stats/export/current", req).then(res => {
        closeLoading(vm);
        if(res.code == "000000") {
          vm.$router.push("export-download?projectId="+vm.projectId+'&listType=1');
        } else {
          vm.$message(res.message)
        }
        vm.dialogVisible = false;
      });
    },
    getCityName() {
      let city = '';
      let region = vm.dialogData.region;
      console.log('region',region,typeof region,region == '');
      if(region != '') {
        city = region.split(' / ').join('');
        console.log('city',city);
      }
      return city;
    },
    toDownload() {
      let checkAll = operationData.hasAll(vm.formInline.organization)
      let routerData = {
        // projectId : vm.projectId,
        projectId : '',
      };
      vm.$router.push({ path: "export-download", query: routerData });
    },
    setDialogData() {
      //传递给dialog数据
      this.dialogData.organization = "";
      for (let x = 0; x < this.tags.length; x++) {
        this.dialogData.organization += this.tags[x].label + "、";
      }
      let len = this.dialogData.organization.length;
      this.dialogData.organization = this.dialogData.organization.substring(
        0,
        len - 1
      );
    },
    changeDate() {
      if (vm.formInline.region.length == 0) {
        const h = this.$createElement;
        vm.$message({
          message: h('p', { style: 'color: #FF3399' }, '请先选择地区后再进行修改 ')
        });
        return;
      }
      this.setDialogData();
      this.dialogUpdate = true;
      this.$nextTick(function() {
        this.$refs.childAlignment.$emit("search");
      });
    },
    exportPDF() {
      openLoading(vm);
      let tabsList = vm.$refs.tabs.$children;
      for(let i= 1;i<tabsList.length;i++) {
        tabsList[i].$el.style.display = 'block';
      }

      let element = '';
      element = document.querySelector('.item-list-tabs .el-tabs__content');
      if(element == null) {
        return
      }
      let opts = {
        // scale:window.devicePixelRatio, // 添加的scale 参数
        // logging: true, //日志开关
        // width:element.offsetWidth, //dom 原始宽度
        // height:element.offsetHeight, //dom 原始高度
        // useCORS: true,
        // taintTest: true, //是否在渲染前测试图片
        // dpi:300,
        background: '#F0F2F5',
      };
      vm.showRadio = 1;
      setTimeout(() => {
        html2Canvas(element,opts).then(function(canvas) {
          let contentWidth = canvas.width;
          let contentHeight = canvas.height;

          //一页pdf显示html页面生成的canvas高度;
          let pageHeight = contentWidth / 592.28 * 841.89;
          //未生成pdf的html页面高度
          let leftHeight = contentHeight;
          //页面偏移
          let position = 0;
          //a4纸的尺寸[595.28,841.89]，html页面生成的canvas在pdf中图片的宽高
          let imgWidth = 595.28;
          let imgHeight = 592.28 / contentWidth * contentHeight;

          // let pageData = canvas.toDataURL('image/jpeg', 1.0);
          let pageData = canvas.toDataURL('image/png');

          let pdf = new JsPDF('', 'pt', [contentWidth*0.8,contentHeight*0.8]);
          
          // pdf.addImage(pageData, 'JPEG', 0, position, contentWidth*0.8, contentHeight*0.8)
          pdf.addImage(pageData, 'PNG', 0, position, contentWidth*0.8, contentHeight*0.8)

          let title = "导出学情报告";
          pdf.save(title + '.pdf');

          for(let i= 1;i<tabsList.length;i++) {
            let idStr = tabsList[i].$el.id;
            // console.log(idStr,vm.activeName);
            if(idStr.indexOf(vm.activeName) == -1) {
              tabsList[i].$el.style.display = 'none';
            }
          }
          vm.showRadio = 0;
          closeLoading(vm);
        });
      }, 100);
    },
  }
};
</script>
<style lang="scss">
.item-list-wrap {
  .el-radio-button__inner:hover {
    color: #449284;
  }
  .is-active {
    .el-radio-button__inner:hover {
      color: #fff;
    }
  }
  .overflow-chart {
    overflow-x: auto;
  }
  .el-radio-button {
    display: contents;
  }
  .component-content {
    // position: relative;
    // background: #fff;
    padding: 10px;
    .header-title {
      padding: 10px 12px;
      font-size: 12px;
      color: #449284;
      border-bottom: 1px solid #efefef;
    }
    .item-form {
      position: relative;
      // margin-bottom: 20px;
      padding: 10px 0 10px 0;
      background: #fff;
      width: 100%;
      border-radius: 4px 4px 0 0;
      .form-text {
        color: #606266;
        font-size: 12px;
      }
      .form-p {
        margin: 17px 0 0 30px;
        line-height:20px;
        font-size:14px;
        color: #666666;
        p { 
          margin-bottom: 12px;
          .span-value {
            margin-left: 20px;
          }
        }
      }
      .buttom-line {
        margin: 30px auto 10px auto;
        height: 1px;
        background: #E4E7ED;
        width: 94.66%
      }
      .form-title {
        position: relative;
        margin: 20px 0 24px 30px;
        height: 25px;
        font-size:18px;
        font-weight:600;
        line-height: 25px;
        color: #000000;
      }
      .el-form-item {
        margin-left: 25px;
      }
      .is-checked {
        .el-checkbox__inner {
          background-color: #449284;
          border-color: #449284;
        }
        .el-checkbox__label {
          color: #449284;
        }
      }
      .form-button {
        position: absolute;
        width: 140px;
        top: 78px;
        right: 10px;
        .el-button--default{
          border:1px solid #449284;
          color: #449284;
        }
        .el-button:hover {
          background: #F1F7F6;
        }
      }
      .col-text {
        font-size: 12px;
      }
    }
    .button-group {
      position: relative;
      // right: 100px;
      float: right;
      margin-right: 20px;
      z-index: 999;
      .el-button {
        border:1px solid #449284;
        color: #449284;
      }
      .is-disabled {
        color: #fff;
      }
      .el-button:hover {
        background: #F1F7F6;
      }
    }
    .choose {
      font-size: 12px;
      margin-bottom: 20px;
    }
    .item-tab {
      width: 100%;
      height: 46px;
      background: #F0F2F5;
      position: absolute;
    }
    .el-tabs__item.is-active {
      color: #449284;
    }
    .el-tabs__item:hover {
      color: #449284;
    }
    .el-tabs__header {
      width: 100%;
      background: #fff;
      margin-bottom: 20px;
      .el-tabs__nav-scroll {
        margin-left: 30px;
      }
    }
    .el-tabs__nav-wrap::after {
      height: 0px;
    }
    .tag-group {
      margin-left: 104px;
      margin-bottom: 20px;
      .el-tag {
        margin-right: 20px;
      }
    }
    .el-tabs__active-bar {
      background-color: #449284;
    }
    .el-tabs__content {
      ::-webkit-scrollbar
      {
        width: 4px;
        height: 10px;
        background-color: #D8D8D8;
      }
      ::-webkit-scrollbar-thumb {
        background-color: #D8D8D8;
      }
    }
  }
}
</style>