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-hand',
  templateUrl: './room-interview-judge-hand.component.html',
  styleUrls: ['./room-interview-judge-hand.component.scss']
})
export class RoomInterviewJudgeHandComponent 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],
      'col_num' : [null, null]
    });
   }

  ngOnInit(): void {
    this.getLastStdSeq();
    this.getAllJudge();
  }
  
  //最后一次打印的序号
  getLastStdSeq() {
    this.AjaxService.requestEntity('ly/room/print/get/last/print.htm', {ly_room_id: this.ResponseEntity.ly_room_id}, (entity) => {
      this.currentEntity.start_num = entity.last_seq;
      this.currentEntity.end_num = entity.max_seq;
      this.currentEntity.school_code = entity.school_code;
    });
  }

  //评委列表
  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;
    }
    let std_num, url;
    //中戏-特殊处理
    if(this.currentEntity.school_code && this.currentEntity.school_code === '10048') {
      std_num = 40;
      url = 'ly/room/judge/score/multi/print.htm';
    } else {
      std_num = 20;
      url = 'ly/room/judge/score/print.htm';
    }
    this.AjaxService.requestEntity(url, {
      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 : std_num //每页考生的数目
    }, (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});
  }

}
