import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FuncService } from '../../../../../core/service/func.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { MsgService } from '../../../../../core/service/msg.service';
import { ModalService } from '../../../../../core/service/modal.service';

@Component({
  selector: 'app-std-reg-video-face',
  templateUrl: './std-reg-video-face.component.html',
  styleUrls: ['./std-reg-video-face.component.scss']
})
export class StdRegVideoFaceComponent extends FramePageComponent implements OnInit {


  private intervalId: any;
  agentArray= [];
  agent_id : any;

  constructor(private modalService: BsModalService) {
    super(modalService);
   }

  ngOnInit() {
    clearTimeout(this.intervalId);
    this.agentArray = [];
    AjaxService.requestArray('conf/agent/list/dept.htm', {}, (array) => {
      this.agentArray = array;
      if (this.agentArray.length === 1) {
        this.agent_id = this.agentArray[0].ly_agent_id;
        this.pager.reload();
      }
    });
  }

  //2张照片间的比对
  validStdPhoto() {
    if(!this.agent_id) {
      MsgService.errorAlert('请选择考点!');
      return;
    }
    MsgService.confirmAlert('确定将所有考生人脸截图进行人脸验证吗？需要消耗较长时间', () => {
      AjaxService.requestEntity('std/reg/video/photo/verify.htm', {flag : 2, agent_id :this.agent_id }, (entity) => {
        ModalService.showThreadWindow(this.modalService, entity, {threadTitle: '正在进行人脸验证，请稍候'});
      });
    });
  }

  //和公安部比对
  validSecurityStdPhoto() {
    if(!this.agent_id) {
      MsgService.errorAlert('请选择考点!');
      return;
    }
    MsgService.confirmAlert('确定将所有考生人脸截图去公安部做人脸验证吗？需要消耗较长时间', () => {
      AjaxService.requestEntity('std/reg/video/photo/verify.htm', {flag : 1, agent_id :this.agent_id }, (entity) => {
        ModalService.showThreadWindow(this.modalService, entity, {threadTitle: '正在进行人脸验证，请稍候'});
      });
    });
  }

  exportFailure() {
    let entity = {
      report_name:'StdVideoFailReport',
      report_title :'认证失败考生汇总'
    };
    FuncService.ajaxDownload('frame/report/download.htm', entity);
  }

  autoValidStd() {
    MsgService.confirmAlert('确定要开启人脸自动比对吗？', () => {
      // this.intervalId = setInterval(this.test.bind(this), 60000);
    });
  }

  requestStd() {
    this.pager.reload({agent_id: this.agent_id});
  }

  ngOnDestroy(): void {
    clearTimeout(this.intervalId);
  }

}
