import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { MsgService } from '../../../../../core/service/msg.service';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';
import { FuncService } from '../../../../../core/service/func.service';

@Component({
  selector: 'app-exam-video-room-score-before',
  templateUrl: './exam-video-room-score-before.component.html',
  styleUrls: ['./exam-video-room-score-before.component.scss']
})
export class ExamVideoRoomScoreBeforeComponent  extends FrameDetailComponent implements OnInit {

  judgeArr = [];

 
  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'start_num' : [null, Validators.required],
      'end_num' : [null, Validators.required],
      'judge_id' : [null, Validators.required]
    });
   }

  ngOnInit() {
    AjaxService.requestMap('exam/score/print/last/seq.htm', {
      room_id : this.ResponseEntity.ly_room_id
    }, (map) => {
      this.currentEntity.start_num = map['last_seq'];
      this.currentEntity.end_num = map['max_seq'];
    });
    AjaxService.requestArray('exam/judge/list/judge.htm', {
      agent_id : this.ResponseEntity.ly_agent_id,
      room_id: this.ResponseEntity.ly_room_id
    }, (array) => {
      this.judgeArr = array;
    })
  }

  printScore() {
    if(this.currentEntity.start_num > this.currentEntity.end_num) {
      MsgService.errorToastr('结束序号必须大于起始序号！');
      return;
    }
    // if(!this.currentEntity.judge_id) {
    //   MsgService.errorToastr('请选择打印的评委');
    //   return;
    // }
    this.closeWindow();
    AjaxService.requestMap('exam/judge/score/before/print/zx.htm', {
      room_id : this.ResponseEntity.ly_room_id,
      start_num: this.currentEntity.start_num,
      end_num: this.currentEntity.end_num,
      judge_id: this.currentEntity.judge_id
    }, (map) => {
      this.currentEntity.start_num = map['last_seq'];
      this.currentEntity.end_num = map['max_seq'];
      FuncService.ajaxDownload('frame/temporary/download.htm', {file_name: map['result']});
    }, {RequestWithLoading: true});
  }

}
