import { ViewChild } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { CookieService } from 'ngx-cookie-service';
import { FramePager } from 'src/app/core/frame/pager/frame-pager/frame-pager';
import { AjaxService } from 'src/app/core/service/ajax.service';
import { MsgService } from 'src/app/core/service/msg.service';
import { FramePageComponent } from 'src/app/routes/frame/core/page/frame.page';

@Component({
  selector: 'app-exam-judge-signin',
  templateUrl: './exam-judge-signin.component.html',
  styleUrls: ['./exam-judge-signin.component.scss']
})
export class ExamJudgeSigninComponent extends FramePageComponent implements OnInit {
  
  agent: any;
  judge: any;
  dateArray = [];
  @ViewChild('noSignInPager', {static: false}) noSignInPager: FramePager;
  @ViewChild('signInPager', {static: false}) signInPager: FramePager;


  constructor(private router: Router, private cookies: CookieService, private modalService: BsModalService) {
    super(modalService);
    this.judge = {};
    this.agent = {};
    const agent_id = this.cookies.get('CurrentAgentId');
    if (agent_id !== undefined && agent_id.length > 0) {
      // 去获取
      AjaxService.requestEntity('layout/agent/find.htm', {ly_agent_id: agent_id}, (entity) => {
        this.agent = entity;
        AjaxService.requestArray('exam/judge/extract/date/list.htm', {ly_agent_id: agent_id}, (array) => {
          this.dateArray = array;
        });
      
      });
    } else {
      this.router.navigate(['/art/layout/agent/page']);
    }
   }

  ngOnInit(): void {
  }

  requestJudge() {
    this.noSignInPager.reload({ly_agent_id: this.agent.ly_agent_id, exam_date: this.judge.exam_date});
    this.signInPager.reload({ly_agent_id: this.agent.ly_agent_id, exam_date: this.judge.exam_date});
  }

  //评委签到
  judgeSign(judge_id?) {
    let msg = "";
    if(!judge_id) {
      msg = "确定要签到【"+ this.judge.exam_date+"】所有的评委吗？";
    } else {
      msg = "确定要签到该评委吗？";
    }
    MsgService.confirmAlert(msg, () => {
      AjaxService.request('./exam/judge/check/in.htm', 
      {
        ly_agent_id: this.agent.ly_agent_id, 
        exam_date: this.judge.exam_date, 
        judge_id: judge_id
      }, () => {
        MsgService.successToastr('签到成功！');
        this.requestJudge();
      }, {RequestWithLoading: true}
      );
    });
  }


}
