import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from 'src/app/routes/frame/core/page/frame.page';
import { StdWithoutExamRemarkComponent } from '../std-without-exam-remark/std-without-exam-remark.component';

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

  total:any;
  aspectArr = [];
  pendArr = [];
  aspect_id: 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.AjaxService.requestArray('std/without/exam/materail/aspect/list.htm',{}, (array) => {
      this.aspectArr = array;
      if(!this.aspect_id && this.aspectArr.length > 0 ) {
        this.aspect_id = this.aspectArr[0].aspect_id;
        this.getTotal();
      }
      this.randomStdMaterial();
    });
  }

  getTotal() {
    //this.AjaxService.requestEntity('std/without/exam/material/total.htm',{aspect_id: this.aspect_id}, (entity) => {
    //this.total = entity;
    //});
  }

  randomStdMaterial() {
    this.pendArr = [];
    this.AjaxService.requestArray('std/without/exam/material/list.htm', {aspect_id: this.aspect_id }, (array) => {
      this.pendArr = array;
    }, {RequestWithLoading: true});
  }


  verifyMaterial(p,status) {
    if(status == 0) {
      this.MsgService.confirmAlert('确定考生材料不符合吗?',() => {
        this.AjaxService.request('std/without/exam/material/refuse.htm',{aspect_id: p.aspect_id, std_id: p.std_id}, () => {
          this.MsgService.successToastr('审核不通过！');
          this.refreshMaterial(p);
          this.getTotal();
        });
      });
    } else {
      this.AjaxService.request('std/without/exam/material/accept.htm',{aspect_id: p.aspect_id, std_id: p.std_id}, () => {
        this.MsgService.successToastr('审核通过！');
        this.refreshMaterial(p);
        this.getTotal();
      });
    }
  }

  refreshMaterial(p) {
    this.AjaxService.requestEntity('std/without/exam/material/get.htm', { enrol_id: p.enrol_id}, (entity) => {
      for(const pend of this.pendArr) {
        if(pend.aspect_id == entity.aspect_id && pend.std_id == entity.std_id) {
            pend.without_exam_admit = entity.without_exam_admit;
            pend.without_exam_remark = entity.without_exam_remark;
            break;
        }
      }
    });
  }

  export() {
    this.FuncService.ajaxDownload('std/without/exam/material/export.htm');
  }

  showRemarkComponent(v) {
    this.onModalClose = () => {
      // this.refreshMaterial(v);
      this.randomStdMaterial();
      this.getTotal();
    };
    this.showComponentModal(StdWithoutExamRemarkComponent, {ResponseEntity: v});
  }

}
