import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FrameService } from '../../../../../core/service/frame.service';
import { Router } from '@angular/router';

declare var $: any;
@Component({
  selector: 'app-exam-judge-art-score',
  templateUrl: './exam-judge-art-score.component.html',
  styleUrls: ['./exam-judge-art-score.component.scss']
})
export class ExamJudgeArtScoreComponent  extends FramePageComponent implements OnInit {

  @ViewChild('scoll', {static: false}) scoll: ElementRef;
  qualified_type:any;
  totalMap = {};
  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 router: Router, modalService: BsModalService) { 
    super(modalService);
  }

  ngOnInit(): void {
    this.std = {};
    this.goInit();
    AjaxService.requestEntity('ex/judge/art/score/get/current.htm', {}, (entity) => {
      this.std = entity;
    });
    setTimeout(()=>{
      $(this.scoll.nativeElement).slimScroll({
        height: window.innerHeight - 50
      });
      },100);
  }

  goInit() {
    this.totalMap = {};
    AjaxService.requestMap('ex/judge/art/score/total.htm', {}, (map) => {
      this.totalMap = map;
    });
  }

  //上一个考生
  preStd() {
    if(this.std.std_seq == 1) {
      this.MsgService.errorAlert('已无上一个考生！');
      return;
    }
    AjaxService.requestEntity('ex/judge/art/score/pre.htm', {
      std_seq: this.std.std_seq-1
    }, (entity) => {
      this.std = entity;
    });
  }

  //下一个考生
  nextStd() {
    if(this.totalMap['total'] == this.std.std_seq) {
      this.MsgService.errorAlert('已无下一个考生！');
      return;
    }
    AjaxService.requestEntity('ex/judge/art/score/next.htm', {
      std_seq: this.std.std_seq+1
    }, (entity) => {
      this.std = entity;
    });
  }

  //判断合格
  scoreQualified(qualified) {
    AjaxService.request('ex/judge/art/score/qualified.htm', {
      score_id : this.std.score_id,
      qualified: qualified
    }, () => {
      this.nextStd();
      this.goInit();
      this.pager.reload();
    });
  }

  currentStd(current) {
    this.std = current;
  }

}
