import { Component, OnInit } from '@angular/core';
import { FormBuilder } 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 { ModalService } from '../../../../../core/service/modal.service';

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


  room_name : any;
  noin_std_total:any; //当天未入场考生数

  constructor(bsModalRef: BsModalRef,  fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      
    });
   }

  ngOnInit() {
  }

  initDefautEntity() {
    this.room_name = this.ResponseEntity.group.group_name + '第' + this.ResponseEntity.room_seq + '考场';
    this.getNoinStdNum();
  }

  //未入场考生数
  getNoinStdNum() {
    AjaxService.requestEntity('exam/interview/room/noin/num.htm', {
      ly_room_id: this.ResponseEntity.ly_room_id
    }, (num) => {
      this.noin_std_total = num;
    });
  }

  //批量入场
  batchInroom() {
    if(!this.ResponseEntity.std_num || this.ResponseEntity.std_num <= 0) {
      MsgService.errorToastr('请填写要入场的考生数量！');
      return;
    }
    if(this.ResponseEntity.std_num > this.noin_std_total) {
      MsgService.errorToastr('要入场的考生数量不能超过未入场的考生数量！');
      return;
    }
    MsgService.confirmAlert('确定要批量入场'+this.ResponseEntity.std_num+'个考生吗？', () => {
      AjaxService.requestEntity('exam/interview/room/batch/in.htm', {
        room_id: this.ResponseEntity.ly_room_id,
        std_num: this.ResponseEntity.std_num
      }, (entity) => {
        if(entity) {
          ModalService.showThreadWindow(this.framePageComponent.bsService, entity, {threadTitle: '正在整理数据，请稍候'});
        } else {
          MsgService.successToastr('批量入场成功!');
        }
        this.closeWindow();
      }, { RequestWithLoading: true});
    });
  }

}
