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-real-score',
  templateUrl: './exam-judge-art-real-score.component.html',
  styleUrls: ['./exam-judge-art-real-score.component.scss']
})
export class ExamJudgeArtRealScoreComponent extends FramePageComponent  implements OnInit {

  @ViewChild('scoll', {static: false}) scoll: ElementRef;
  totalMap = {};
  std: any;
  judge_score: 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/real/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/real/total.htm', {}, (map) => {
      this.totalMap = map;
    });
  }

   //上一个考生
   preStd() {
    if(this.std.std_seq == 1) {
      this.MsgService.errorAlert('已无上一个考生！');
      return;
    }
    AjaxService.requestEntity('ex/judge/art/score/real/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/real/next.htm', {
      std_seq: this.std.std_seq+1
    }, (entity) => {
      this.std = entity;
    });
  }

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

  //提交分数
  score() {
    if(!this.judge_score) {
      this.MsgService.errorToastr('评分不能为空！');
      return ;
    }
    if(!this.isInteger(this.judge_score)) {
      this.MsgService.errorToastr('分数不能有小数点且只能为数字！');
      return;
    }
    if(this.judge_score< 0 || this.judge_score > 100) {
      this.MsgService.errorToastr('评分分值必须在【0~100】区间！');
      return;
    }
    AjaxService.request('ex/judge/art/score/real/score.htm', {
      real_score_id : this.std.real_score_id,
      judge_score : this.judge_score
    }, () => {
      this.judge_score = '';
      this.nextStd();
      this.goInit();
      this.pager.reload();
    }, {requestWithLoding : true});
  }

  //是否整形
  isInteger(obj) {
    return parseInt(obj, 10) === obj;
  }

  //下一未评分
  nextNoScoreStd() {
    AjaxService.requestEntity('ex/judge/art/score/real/get/current.htm', {
    }, (entity) => {
      if(entity && entity.std_seq == 1 && entity.judge_score) {
        this.MsgService.successAlert("已经完成全部考生的评分！");
        return;
      }
      this.std = entity;
    });
  }

}
