<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="选择地区：">
          <el-col :span="12">
            <el-select
              size="small"
              v-model:value="timeFlag2"
              placeholder="请选择"
              style="width: 330px"
            >
              <el-option
                v-for="item in timeFlagList2"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-col>
          <el-col v-show="timeFlag2 == 2" :span="12">
            <el-cascader
              size="small"
              ref="cascaderRegion"
              :options="optionsRegion"
              :props="props"
              v-model:value="formInline.region"
              @change="handleChange"
              filterable
              change-on-select
              placeholder="请先选择地区后再进行查询"
              style="width: 330px"
            >
              <template v-slot="{ node, data }">
                <span
                  :class="{ 'my-ower': node.level == 1 && data.degree == 5 }"
                  >{{ data.label }}</span
                >
                <span
                  class="spe-label"
                  v-if="node.level == 1 && data.degree == 5"
                  >我所在机构</span
                >
              </template>
            </el-cascader>
          </el-col>
          <el-col v-show="timeFlag2 == 1" :span="12">
            <el-select
              size="small"
              v-model:value="timeFlag3"
              placeholder="请选择"
              style="width: 330px"
              @change="changeTimeFlag3"
            >
              <el-option
                v-for="item in hslist"
                :key="item.value"
                :label="item.hospitalName"
                :value="item.hospitalId"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-col :span="6">
            <el-checkbox
              v-if="showOriginal == 1"
              size="small"
              v-model:value="formInline.checked"
              >查看原始数据</el-checkbox
            >
          </el-col>
        </el-form-item>
        <el-form-item label="选择时间：">
          <el-col :span="12">
            <el-select
              size="small"
              v-model:value="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:value="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>
        <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:value="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="提示"
        v-model:visible="dialogVisible"
        width="30%"
        center
      >
        <p style="text-align: center">
          您的导出预计将在24小时内完成，是否继续？
        </p>
        <template v-slot:footer>
          <span class="dialog-footer">
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="exportHttp()">继续导出</el-button>
          </span>
        </template>
      </el-dialog>
      <el-dialog title="提示" v-model:visible="dialogSearch" width="30%" center>
        <p style="text-align: center">
          您的报告预计将在24小时内生成，是否继续？
        </p>
        <template v-slot:footer>
          <span class="dialog-footer">
            <el-button @click="dialogSearch = false">取消</el-button>
            <el-button type="primary" @click="exportTime()">继续生成</el-button>
          </span>
        </template>
      </el-dialog>
      <el-dialog title v-model:visible="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 { $on, $off, $once, $emit } from '../../../utils/gogocodeTransfer'
import { $children } from '../../../utils/gogocodeTransfer'
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: '/item-manager',
      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,
      originalFlag: null,
      roleType: '',
      formInline: {
        region: [],
        date: '',
        organization: [],
        checked: false,
        timeFlag: 1,
        during: null,
        pageNo: 1,
        pageSize: 20,
        selectRegionId: '', //新增选择的地区id
        orgId: '', //新增机构Id,
        // showOriginal: 2,
        // originalFlag: null,
      },
      organizationNotice: '选择地区筛选到区才能选择机构',
      dialogData: {
        region: '全部',
        // regionData: "",
        organization: '',
        // organizationData: "",
      },
      tags: [],
      activeName: 'zero',
      organizationNum: 0,
      dialogVisible: false,
      dialogUpdate: false,
      displayExam: 1,
      flag: 1,
      //v2.0更新data部分
      timeFlagList: [],
      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: '',
      selectRegionId: '',
      orgId: '',
      containOfficialFlag: 1,
      showRadio: 0,
      containHospitalFlag: null, //新增判断是否当前有机构
      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
          )
        },
      },
      timeFlagList2: [
        { value: 1, label: '层级' },
        { value: 2, label: '地区' },
      ],
      timeFlag2: 2,
      timeFlag3: '',
      currentTimeFlag3: {},
      hslist: [],
    }
  },
  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.getRegionOption2()
  },
  mounted: function () {
    commonUtil.resizeHeight()
  },
  methods: {
    checkShowType() {
      if (vm.downloadId == null) {
        vm.getDisplay()

        vm.curmbSecond = '项目管理'
        vm.jumPathThird = '/item-manager'
      }
      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 () {
            $emit(vm.$refs.childDataAll, 'static')
            $emit(vm.$refs.childCrowd, 'static')
            if (doctorInfoRep.existCourse == 1) {
              $emit(vm.$refs.childCourse, 'static')
            }
            if (doctorInfoRep.existExam == 1) {
              $emit(vm.$refs.childExam, 'static')
            }
            if (doctorInfoRep.existEffect == 1) {
              $emit(vm.$refs.childEffect, 'static')
            }
          }, 20)
        } else {
          vm.$message(res.message)
        }
      })
    },
    setTimeFlagList() {
      if (vm.finalDateFlag == 1) {
        vm.timeFlagList = [
          {
            value: 1,
            label: '截至昨日',
          },
          {
            value: 2,
            label: '自定义时间',
          },
        ]
      } else if (vm.finalDateFlag == 2) {
        vm.timeFlagList = [
          {
            value: 1,
            label: '截止项目结束',
          },
          {
            value: 2,
            label: '自定义时间',
          },
        ]
      }
    },
    getDisplay(type) {
      //获取地区
      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.tags = []
      let node = this.$refs.cascaderRegion.getCheckedNodes()[0] //级联当前选中的值
      console.log('node change', node)
      //获取选中的inputValue
      setTimeout(function () {
        vm.dialogData.region = vm.$refs['cascaderRegion'].inputValue
      }, 20)

      if (node.label !== '全部') {
        let areaArr = value[value.length - 1].split('_')
        vm.areaLen = areaArr.length
        // V2.1修改废弃
        // if (areaArr.length >= 3) {
        //   this.getOrganizationList();
        //   this.organizationNotice = "请选择机构";
        // } else {
        //   this.organizationNotice = "选择地区筛选到区才能选择机构";
        // }
      } else {
        vm.areaLen = 1
        vm.organizationNotice = '选择地区筛选到区才能选择机构'
      }
      //添加子节点
      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)
        })
      }
      vm.formInline.organization = [] //选择的机构
      //这里需要判断当前选中项的degree，如果是5那就不需要再调接口
      if (node.data && node.data.id && node.data.degree == 5) {
        let changeItemData = node.data.id
        let subIndex = changeItemData.lastIndexOf('_')
        vm.formInline.selectRegionId = changeItemData.slice(0, subIndex)
        vm.formInline.orgId = changeItemData.slice(subIndex + 1)
        vm.formInline.organization.push(vm.formInline.orgId)
        vm.hospitalCnt = 1
        vm.search()
      } else {
        vm.formInline.selectRegionId = node.data.id
        vm.formInline.orgId = ''
        vm.gethHspitalsCnt()
      }
    },
    //给级联插入新获取数据的操作-即添加子节点
    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 == 0 || obj.degree == 5) {
          obj.leaf = true
        }
        option.push(obj)
      }
      return option
    },
    //选择机构操作-old
    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') {
          //containHospitalFlag判断自己是否有机构,1-有机构
          this.containHospitalFlag = res.data.containHospitalFlag

          let doctorInfoRep = res.data.doctorInfoRep
          vm.showOriginal = doctorInfoRep.status //判断是否显示原始数据
          vm.originalFlag = doctorInfoRep.originalFlag
          vm.roleType = doctorInfoRep.roleType
          vm.displayCourse = doctorInfoRep.existCourse
          vm.displayExam = doctorInfoRep.existExam
          vm.displayEffect = doctorInfoRep.existEffect
          vm.certFlag = doctorInfoRep.certFlag
          vm.maxDate = new Date(doctorInfoRep.maxDate)
          vm.minDate = new Date(doctorInfoRep.minDate)
          vm.containOfficialFlag = doctorInfoRep.containOfficialFlag
          vm.finalDateFlag = doctorInfoRep.finalDateFlag
          // vm.formInline.showOriginal = doctorInfoRep.status;
          // if (vm.showOriginal == 2) {
          //   vm.formInline.originalFlag = vm.originalFlag;
          // }
          vm.setTimeFlagList() //设置选择时间

          if (vm.showOriginal == 2) {
            //不显示原始数据,取接口返回的originalFlag
            if (vm.originalFlag == 1) {
              vm.formInline.checked = true
            } else if (vm.originalFlag == 2) {
              vm.formInline.checked = false
            }
          }

          vm.formInline.region = []
          vm.formInline.region[0] = res.data.list[0].id
          vm.allRegionId = res.data.list[0].id //存储当前所在id
          vm.optionsRegion = operationData.setRegionOptionNew(res.data.list)
          //判断是否有机构,有的情况就需要拆分出regionId和orgId
          let firstItemData = res.data.list[0]
          let value = res.data.list[0].id
          vm.formInline.organization = []
          if (firstItemData.degree == 5) {
            let subIndex = value.lastIndexOf('_')
            vm.formInline.selectRegionId = value.slice(0, subIndex)
            vm.formInline.orgId = value.slice(subIndex + 1)
            vm.hospitalCnt = 1
            vm.formInline.organization.push(vm.formInline.orgId)
            vm.search()
          } else {
            vm.formInline.selectRegionId = value
            vm.formInline.orgId = ''
            vm.gethHspitalsCnt()
          }
          vm.selectRegionId = vm.formInline.selectRegionId //作存储
          vm.orgId = vm.formInline.orgId //作存储
          //初始化判断区域id 是不是有机构id
          // let value = res.data.list[0].id;
          // let areaArr = value.split('_');
          // vm.areaLen = areaArr.length;
          // if (areaArr.length >= 3) { //V2.1舍弃
          //   vm.getOrganizationList();
          //   vm.organizationNotice = "请选择机构";
          // }
          // vm.search(); // deleted by Anndy Yang
        }
      })
    },
    getRegionOption2() {
      vm.GET(
        `hospital/hospitalStats/portal/hospital/deepLowers/${vm.projectId}`,
        '',
        '',
        '',
        true
      ).then((res) => {
        if (res.code == '000000') {
          this.hslist = res.data
        }
      })
    },
    //获取机构
    gethHspitalsCnt() {
      let req = {
        projectId: vm.projectId,
        // regionId: vm.formInline.region[vm.formInline.region.length - 1]
        regionId: vm.formInline.selectRegionId,
      }
      vm.GET('stats/region/hospitals/cnt', req, '', '', false).then((res) => {
        if (res.code == '000000') {
          vm.hospitalCnt = res.data.hospitalCnt
          vm.hospitalCntList = res.data.list //当前选中区域下的机构列表
          vm.formInline.organization = []
          // vm.organizationList = [];//选择机构操作被弃用
          // 选中区域下只有一个机构时，所有请求中要传递机构ID added by Anndy Yang
          if (vm.hospitalCntList.length == 1) {
            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.search() // added by Anndy Yang
        }
      })
    },
    //获取机构列表--V2.1弃用
    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() {
      // let sureOriginalFlag = null;
      // if (vm.formInline.showOriginal == 2) { //如果不显示，则取接口返回的数据
      //   sureOriginalFlag = vm.formInline.originalFlag;
      // }else {
      //   sureOriginalFlag = (vm.formInline.checked == false ? 2 : 1);
      // }
      const hl =
        this.timeFlag2 == 2
          ? vm.formInline.organization
          : [this.currentTimeFlag3.hospitalId]
      const regionId =
        this.timeFlag2 == 2
          ? vm.formInline.selectRegionId
          : this.currentTimeFlag3.regionId
      vm.exportReq = {
        projectId: vm.projectId,
        beginDate: operationData.setDuringTime(vm.formInline.during, 'begin'),
        endDate: operationData.setDuringTime(vm.formInline.during, 'end'),
        hospitalIdList: hl,
        originalFlag: vm.formInline.checked == false ? 2 : 1,
        // regionId: vm.formInline.region[vm.formInline.region.length - 1],
        regionId: regionId,
        timeFlag: vm.formInline.timeFlag,
      }
      console.log('--vm.exportReq ', vm.exportReq)
    },
    changeTimeFlag(value) {
      if (value == 1) {
        vm.formInline.during = null
      }
    },
    changeTimeFlag3(v) {
      const l = this.hslist.filter((i) => {
        return i.hospitalId == this.timeFlag3
      })[0]
      console.log('--v', l, this.timeFlag3)
      this.currentTimeFlag3 = l
      vm.formInline.selectRegionId = this.currentTimeFlag3.regionId
      vm.formInline.organization = [this.currentTimeFlag3.hospitalId]
    },
    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], //id结构修改
        regionId: vm.formInline.selectRegionId,
        timeFlag: vm.formInline.timeFlag,
        hospitalNames: vm.dialogData.organization,
        regionNames: vm.dialogData.region,
      }
      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() {
      if (vm.formInline.timeFlag == 1) {
        //截止昨日
        vm.setExportReq()
        $emit(vm.$refs.childDataAll, 'search')
        $emit(vm.$refs.childCrowd, 'search')
        if (vm.displayCourse == 1) {
          $emit(vm.$refs.childCourse, 'search')
        }
        if (vm.displayExam == 1) {
          $emit(vm.$refs.childExam, 'search')
        }
        if (vm.displayEffect == 1) {
          $emit(vm.$refs.childEffect, 'search')
        }
      } else if (vm.formInline.timeFlag == 2) {
        //开始时间结束时间
        if (vm.formInline.during == null) {
          vm.$message('自定义时间，请选择时间段！')
        } else {
          vm.dialogSearch = true
        }
      }
    },
    //重置
    resetForm() {
      vm.formInline = Object.assign(
        {},
        {
          region: [],
          date: '',
          organization: [],
          checked: false,
          timeFlag: 1,
          during: null,
          pageNo: 1,
          pageSize: 20,
          orgId: '',
          selectRegionId: '',
        }
      )
      vm.formInline.region[0] = vm.allRegionId
      vm.formInline.selectRegionId = vm.selectRegionId
      if (vm.orgId) {
        vm.formInline.organization[0] = vm.orgId
      }
      if (vm.showOriginal == 2) {
        //不显示原始数据,取接口返回的originalFlag
        if (vm.originalFlag == 1) {
          vm.formInline.checked = true
        } else if (vm.originalFlag == 2) {
          vm.formInline.checked = false
        }
      }
      vm.areaLen = 0
      vm.tags = []
      vm.timeFlag2 = 2
      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(); //弃用于V2.1，因为不再使用tags
      this.dialogUpdate = true
      this.$nextTick(function () {
        $emit(this.$refs.childAlignment, 'search')
      })
    },
    exportPDF() {
      openLoading(vm)
      let tabsList = $children(vm.$refs.tabs)
      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)
    },
  },
  emits: ['static', 'search'],
}
</script>

<style lang="scss">
.my-ower::after{display:block;content:"";position:absolute;left:-40px;z-index:10000000;width:200%;border-bottom:1px solid rgba(39,0,8,0.1)!important}/*// .el-cascader-node.is-active,*/
// .el-cascader-node.is-selectable.in-checked-path{}.el-cascader-menu:first-child{.el-cascader-node:first-child{
        height: 50px;
        position: relative;
        padding-top: 16px;
        .spe-label{
          position: absolute;
          top: -8px;
          left: 20px;
          font-size: 12px;
          color: #9B9997;
        }
      }
    /*}*/}.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>
