import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { FrameDetailComponent } from '../../../../frame/core/detail/frame.detail';

@Component({
  selector: 'app-room-interview-judge-score',
  templateUrl: './room-interview-judge-score.component.html',
  styleUrls: ['./room-interview-judge-score.component.scss']
})
export class RoomInterviewJudgeScoreComponent  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, null]
    });
  }

  ngOnInit(): void {
    this.getAllJudge();
  }

   //评委列表
   getAllJudge() {
    this.AjaxService.requestArray('ex/judge/room/list.htm', {ly_room_id: this.ResponseEntity.ly_room_id}, (array) => {
      this.judgeArr = array;
      for(const judge of this.judgeArr) {
        judge.judge_full_name = '【'+ judge.judge_seq +'号评委'+'】' + judge.judge_name;
      }
      this.judgeArr.unshift({judge_full_name:'所有', judge_id: null});
    });
  }

  //打印分数
  printScore() {
    if(!this.currentEntity.start_num) {
      this.MsgService.errorToastr('请选择起始序号！');
      return;
    }
    if(!this.currentEntity.end_num) {
      this.MsgService.errorToastr('请选择结束序号！');
      return;
    }
    if(this.currentEntity.start_num > this.currentEntity.end_num) {
      this.MsgService.errorToastr('结束序号必须大于起始序号！');
      return;
    }
    this.AjaxService.requestEntity('ly/room/judge/hand/print.htm', {
      ly_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,
      time_type: this.ResponseEntity.time_type,
      std_num : 20 //每页考生的数目
    }, (entity) => {
      this.currentEntity.start_num = entity.last_seq;
      this.currentEntity.end_num = entity.max_seq;
      this.FuncService.ajaxDownload('frame/temporary/download.htm', {file_name: entity.result});
    }, {RequestWithLoading: true});
  }

}
