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 { FrameService } from '../../../../../core/service/frame.service';

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

  checkin: any;
  agentArray = [];
  dateArray = [];
  roomArray = [];
  stdSubjectArray = [];

  private intervalId: any;
  constructor(modalService: BsModalService) { 
    super(modalService);
    this.goInit();
  }

  ngOnInit() {
  }

  goInit() {
    this.agentArray = [];
    this.dateArray = [];
    this.checkin = {};

    // 获取所有考点
    AjaxService.requestArray('exam/checkin/init/agent.htm', {}, (array) => {
      this.agentArray = array;
      debugger;
      if (this.agentArray.length === 1) {
        this.checkin.agent_id = this.agentArray[0].ly_agent_id;
        this.checkin.ly_agent_id = this.agentArray[0].ly_agent_id;
        this.requestDateArray();
      }
    });
  }

  // 获取考试日期
  requestDateArray() {
    debugger;
    AjaxService.requestArray('exam/checkin/init/date.htm', this.checkin, (array) => {
      if (FrameService.FrameOptr.optr_id !== 0) {
        for (const d of array) {
          if (d.ly_room_id === 0) {
            const s = new Array();
            s.push(d);
            this.dateArray = s;
            break;
          }
        }
        if (this.dateArray === undefined || this.dateArray.length == 0) {
          this.dateArray = array;
        }
      } else {
        this.dateArray = array;
      }
      if (this.dateArray.length >= 1) {
        this.checkin.exam_date = this.dateArray[0].exam_date;
        this.pager.clear();
        this.queryVideoRoom();
      }
    });
  }

  changeDate() {
    this.queryVideoRoom();
  }

  //查询考场
  queryVideoRoom() {
    debugger;
    this.checkin.exam_date = this.dateArray[0].exam_date;
    AjaxService.requestArray('exam/interview/room/list.htm', this.checkin, (array) => {
      for(let obj of array){
        obj.room_addr = obj.group.group_name;
      }
      this.roomArray = array;
    });
  }

  //查询编排详情
  changeRoom() {
    this.pager.pagerParams["ly_room_id"] = this.checkin.ly_room_id;
    this.pager.reload();
  }


  ngOnDestroy(): void {

  }


}
