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

@Component({
  selector: 'app-enrol-report-agent',
  templateUrl: './enrol-report-agent.component.html',
  styleUrls: ['./enrol-report-agent.component.scss']
})
export class EnrolReportAgentComponent extends FramePageComponent implements OnInit {
  agent_id: 0;
  agent: any;
  agentArray = [];
  batch_id:any;
  batchArr = [];

  @ViewChild('categoryAjax', {static: false}) categoryAjax: FrameAjax;
  @ViewChild('aspectAjax', {static: false}) aspectAjax: FrameAjax;
  @ViewChild('agentAjax', {static: false}) agentAjax: FrameAjax;

  constructor(private activateInfo: ActivatedRoute, private router: Router, private modalService: BsModalService) {
    super(modalService);
    this.batchArr = this.FrameService.DictMap['ExamBatchName'];
    this.batch_id = '1';

    let agentTotal = 0;
    AjaxService.requestArray('conf/agent/all.htm', {}, (array) => {
      array.unshift({agent_id:0, agent_name: '全部'});
      this.agentArray = array;
      setTimeout(() => {
        this.changAgent();
      }, 500);
    });
  }

  ngOnInit() {
  }

  changAgent() {
    this.categoryAjax.reload({agent_id: this.agent_id === 0? undefined:this.agent_id, batch_id: this.batch_id});
    this.aspectAjax.reload({agent_id: this.agent_id === 0? undefined:this.agent_id, batch_id: this.batch_id});
    this.agentAjax.reload({batch_id: this.batch_id});
  }
  
  //下载报表
  downloadReport() {
    this.FuncService.ajaxDownload('enrol/report/agent/aspect/download.htm', {agent_id: this.agent_id === 0? undefined:this.agent_id, batch_id: this.batch_id});
  }

}
