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

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

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'start_num' : [null, Validators.required],
      'end_num' : [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'];
    });
  }

  printScore() {
    if(this.currentEntity.start_num > this.currentEntity.end_num) {
      MsgService.errorToastr('结束序号必须大于起始序号！');
      return;
    }
    var url = 'exam/judge/score/print.htm';
    if(FrameService.getParamValue('SchoolCode') == '10047' || FrameService.getParamValue('SchoolCode') == '10047FZ' ) {
      url = 'exam/judge/score/print/ym.htm';
    } else {
      url = 'exam/judge/score/print.htm';
    }
    AjaxService.requestMap(url, {
      room_id : this.ResponseEntity.ly_room_id,
      start_num: this.currentEntity.start_num,
      end_num: this.currentEntity.end_num,
      time_type: this.ResponseEntity.time_type
    }, (map) => {
      this.currentEntity.start_num = map['last_seq'];
      this.currentEntity.end_num = map['max_seq'];
      this.FuncService.ajaxDownload('frame/temporary/download.htm', {file_name: map['result']});
    });
  }

}
