import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { MsgService } from '../../../../../core/service/msg.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { ExamInterviewEntranceBatchDetailComponent } from '../exam-interview-entrance-batch-detail/exam-interview-entrance-batch-detail.component';


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

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

  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();
      }
    });
  }

  // 获取考试日期
  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/batch/total.htm', this.exam, (array) => {
      this.groupArray = array;
    });
  }

  ngOnInit() {

  }


  /******************
   * 显示考生信息
   */
  batchEntrance(group?: any) {
    if(group) {
      if(!group.room_total || !group.noroom_std_total){
        MsgService.warningToastr('请填写考场数和要入场的考生数！');
        return;
      }
    }
    
    this.showComponentModal(ExamInterviewEntranceBatchDetailComponent, {
      ResponseEntity: this.exam,
      mapUrl: 'exam/interview/batch/view.htm',
      mapParam: {
        agent_id: this.exam.agent_id, 
        exam_date: this.exam.exam_date,
        json_value: (group === undefined || group === '')  ? JSON.stringify(this.groupArray) : JSON.stringify(group)
       }
    });
  }

}
