import {Component, OnInit} from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page'
import { ExamInterviewTotalStdComponent } from '../exam-interview-total-std/exam-interview-total-std.component';

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

  exam;
  agentArray = [];
  dateArray = [];
  groupArray = [];
  timeArray = [];

  constructor(modalService: BsModalService) {
    super(modalService);
    this.exam = {};
    AjaxService.requestArray('exam/checkin/init/agent.htm', {}, (array) => {
      this.agentArray = array;
      if (this.agentArray.length === 1) {
        this.exam.agent_id = this.agentArray[0].ly_agent_id;
        this.exam.ly_agent_id = this.agentArray[0].ly_agent_id;
        this.requestDateArray();
      }
    });
    const array = this.FrameService.getFrameDictArray('ExamTimeType');
    this.timeArray = array;
    if(this.timeArray.length>0 && this.timeArray[0].dict_text !== '全天') {
      this.timeArray.splice(0, 0, {dict_text: '全天', dict_value: undefined});
    }
  }

  // 获取考试日期
  requestDateArray() {
    AjaxService.requestArray('exam/checkin/init/date.htm', this.exam, (array) => {
      this.dateArray = array;
      if (this.dateArray.length === 1) {
        this.exam.exam_date = this.dateArray[0].exam_date;
        this.requestTotal();
      }
    });
  }

  requestTotal() {
    AjaxService.requestArray('exam/interview/total.htm', this.exam, (array) => {
      this.groupArray = array;
    });
  }

  ngOnInit() {

  }

  downloadWithoutStd(group?) {
    let entity = {
      agent_id: this.exam.agent_id,
      exam_date: this.exam.exam_date,
      report_name:'ExamMissExamStd',
      report_title :'缺考考生汇总'
    };
    if (group !== undefined){
      entity['ly_group_id'] = group.ly_group_id;
      entity['report_title'] = '缺考考生汇总-' + group.group_name;
    }
    if(this.exam.time_type !==undefined && this.exam.time_type !==null)
      entity['time_type'] = this.exam.time_type;

    this.FuncService.ajaxDownload('frame/report/download.htm', entity);
  }

  /******************
   * 显示考生信息
   */
  showStd(group, type) {
    if(group) {
      group.time_type = this.exam.time_type === undefined ? "" : this.exam.time_type;
      group.exam_date = this.exam.exam_date === undefined ? "" : this.exam.exam_date;
    }
    if(type) {
      group.type = type;
    }
    this.showComponentModal(ExamInterviewTotalStdComponent, {
      ResponseEntity: group
    });
  }
}

