import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page'
import { InterviewStdReportDetailComponent } from '../interview-std-report-detail/interview-std-report-detail.component';

@Component({
  selector: 'app-interview-std-report',
  templateUrl: './interview-std-report.component.html',
  styleUrls: ['./interview-std-report.component.scss']
})
export class InterviewStdReportComponent extends FramePageComponent implements OnInit {

  schoolArr = [];
  batchArr = [];
  dateArr = [];
  timeArr = [];
  groupArr = []; //按照分组统计
  param: any;

  constructor(modalService: BsModalService, private cdr : ChangeDetectorRef) { 
    super(modalService);
  }

  ngOnInit(): void {
    this.param = {};
    this.requestSchool();
    this.requestTimeType();
  }

  //学校
  requestSchool() {
    this.AjaxService.requestArray('cf/school/list.htm',{}, (array) => {
      this.schoolArr = array;
      if(this.schoolArr && this.schoolArr.length == 1) {
        this.param.school_id = this.schoolArr[0].school_id;
        this.requestBatch();
      }
    });
  }

  //批次
  requestBatch() {
    this.AjaxService.requestArray('cf/school/batch/list.htm', {
      school_id : this.param.school_id
    }, (array) => {
      this.batchArr = array;
      this.cdr.detectChanges();
      if(this.batchArr && this.batchArr.length == 1) {
        this.param.batch_id = this.batchArr[0].batch_id;
        this.requestExamDate();
      }
    });
  }

  //通过批次-查找考试日期
  requestExamDate() {
    this.AjaxService.requestArray('ly/checkin/date/list.htm', {
      batch_id : this.param.batch_id
    }, (array) => {
      this.dateArr = array;
      this.cdr.detectChanges();
      if(this.dateArr && this.dateArr.length == 1) {
        this.param.exam_date = this.dateArr[0].exam_date;
        this.requestTotal();
      }
    });
  }

  //时段查询
  requestTimeType() {
    let array = this.FrameService.getFrameDictArray('ExamTimeType');
    this.timeArr = array;
    if(this.timeArr.length>0 && this.timeArr[0].dict_text !== '全天') {
      this.timeArr.splice(0, 0, {dict_text: '全天', dict_value: undefined});
    }
  }

  //面试统计
  requestTotal() {
    this.AjaxService.requestArray('interview/std/report/total.htm',this.param, (array) => {
      this.groupArr = array;
    });
  }

  //显示考生详细信息
  showStd(group, type) {
    if(group) {
      group.time_type = this.param.time_type;
      group.exam_date = this.param.exam_date;
      group.type = type;
    }
    this.showComponentModal(InterviewStdReportDetailComponent, {
      ResponseEntity: group
    });
  }

  //下载考生
 downloadWithoutStd() {
    let entity = {
      batch_id: this.param.batch_id,
      ly_exam_date: this.param.exam_date,
      report_name:'ExamMissExamStd',
      report_title :'缺考考生汇总'
    };
    if(this.param.time_type !==undefined && this.param.time_type !==null) {
      entity['time_type'] = this.param.time_type;
    }
    this.FuncService.ajaxDownload('frame/report/download.htm', entity);
  }

}
