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';

@Component({
  selector: 'app-exam-video-manual-print',
  templateUrl: './exam-video-manual-print.component.html',
  styleUrls: ['./exam-video-manual-print.component.scss']
})
export class ExamVideoManualPrintComponent 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/video/room/manual/seq.htm', {
      room_id : this.ResponseEntity.ly_room_id
    }, (map) => {
      setTimeout(() => {
        this.currentEntity.start_num = map['last_seq'];
        this.currentEntity.end_num = map['max_seq'];
      }, 50);
    });
  }

  printManual() {
    debugger;
    if(this.currentEntity.start_num > this.currentEntity.end_num) {
      MsgService.errorToastr('结束序号必须>=起始序号！');
      return;
    }
    AjaxService.requestMap('exam/video/manual/print.htm', {
      ly_room_id : this.ResponseEntity.ly_room_id,
      start_num: this.currentEntity.start_num,
      end_num: this.currentEntity.end_num
    }, (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']});
    });
  }

}
