import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';

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

  currentStep: any;
  stdArr = [];
  photo: any;
  stdNum: any;
  std: any;
  //作品放大参数
  viewerOptions: any = {
    navbar: false,
    toolbar: {
      zoomIn: 4,
      zoomOut: 4,
      oneToOne: 4,
      reset: 4,
      prev: false,
      play: {
        show: 4,
        size: 'small'
      },
      next: false,
      rotateLeft: 4,
      rotateRight: 4,
      flipHorizontal: 4,
      flipVertical: 4,
    }
  };

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

  ngOnInit(): void {
    this.currentStep = 'score';
    this.photo = {};
    this.std = {};
    this.getStdNum();
    this.initStdPhoto();
  }

  //上一个考生
  preStd() {
    if(this.stdArr && this.stdArr.length>0 && this.stdArr[0].real_exam_seq == 1) {
      this.MsgService.errorToastr('无上一个考生！');
      return ;
    }
    this.AjaxService.requestArray('std/photo/pre/std.htm', {real_exam_seq: this.stdArr[0].real_exam_seq-1}, (array) => {
      this.stdArr = array;
    }, {RequestWithLoading: true});
  }

  //下一个考生
  nextStd() {
    this.AjaxService.requestArray('std/photo/next/std.htm', {real_exam_seq: this.stdArr[0].real_exam_seq+1}, (array) => {
      this.stdArr = array;
    }, {RequestWithLoading: true});
  }

  //根据序号-查询考生
  searchStd() {
    if(this.photo.real_exam_seq) {
      this.AjaxService.requestArray('std/photo/search/by/seq.htm', this.photo, (array) => {
        this.stdArr = array;
      }, {RequestWithLoading: true});
    }
  }

  //考场总人数
  getStdNum() {
    this.AjaxService.requestEntity('std/photo/get/std/num.htm', {}, (entity) => {
      this.stdNum = entity;
    });
  }

  //初始化考生的信息
  initStdPhoto() {
    this.AjaxService.requestArray('std/photo/next/std.htm', {first: 'Active'}, (array) => {
      this.stdArr = array;
      if(this.stdArr && this.stdArr.length > 0 ) {
        this.std = this.stdArr[0];
      }
    });
  }

}
