import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FrameService } from '../../../../../core/service/frame.service';
import { Router } from '@angular/router';
import { ExamJudgeScoreRecordDetailComponent } from '../exam-judge-score-record-detail/exam-judge-score-record-detail.component';

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


  roomArr = []; //考场
  agentArr = [];
  dateArray = [];
  agent: any;
  room: any;


  constructor(private router: Router, modalService: BsModalService) {
    super(modalService);
    this.modalComponent = ExamJudgeScoreRecordDetailComponent;
  }

  ngOnInit(): void {
    this.agent = {};
    this.room = {};
    this.AjaxService.requestArray('conf/agent/all.htm', {}, (array) => {
      this.agentArr = array;
      if(this.agentArr.length == 1) {
        this.agent.agent_id = this.agentArr[0].agent_id;
        this.requestDateArray();
      }
    });
  }

  // 获取考试日期
  requestDateArray() {
    AjaxService.requestArray('exam/checkin/init/date.htm', this.agent, (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.room.exam_date = this.dateArray[0].exam_date;
        this.requestRoom();
      }
    });
  }

  requestRoom() {
    this.AjaxService.requestArray('exam/interview/score/room/list.htm', this.agent, (array) => {
      this.roomArr = array;
      for(const room of this.roomArr) {
        room.room_addr = room.group.group_name +'-' + room.room_addr + '第【' + room.room_seq + '】考场';
      }
    });
  }

  requestJudgeScoreRecord() {
    this.pager.reload({room_id: this.room.ly_room_id});
  }

}
