import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { EnrolReportAspectDetailComponent } from '../enrol-report-aspect-detail/enrol-report-aspect-detail.component';

@Component({
  selector: 'app-enrol-report-aspect',
  templateUrl: './enrol-report-aspect.component.html',
  styleUrls: ['./enrol-report-aspect.component.scss']
})
export class EnrolReportAspectComponent extends FramePageComponent implements OnInit {
  category_id: any;
  category: any;
  categoryArray = [];
  batchArr = [];
  batch_id: any;

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

    let categoryTotal = 0;
    AjaxService.requestArray('conf/category/all.htm', {}, (array) => {
      for (const category of array) {
        if(category.category_status =='Active') {
          this.categoryArray.push(category);
        }

        if (category['category_status'] === 'Active') {
          this.category = category;
          this.category_id = category['category_id'];
          categoryTotal++;
        }
      }
      if (categoryTotal > 1) {
        this.category_id = undefined;
        this.category = undefined;
      }
      if (array.length > 1) {
        this.categoryArray.unshift({category_name: '全部'});
      }
      //this.categoryArray = array;
      setTimeout(() => {
        this.changCategory();
      }, 500);
    });
  }

  ngOnInit() {
  }

  changCategory() {
    if (this.category_id === '') {
      this.category_id = undefined;
      this.category = undefined;
    }
    this.pager.reload({category_id: this.category_id, batch_id: this.batch_id});
  }

  downloadReport() {
    this.FuncService.ajaxDownload('enrol/report/aspect/download.htm', {batch_id: this.batch_id, category_id: this.category_id});
  }

  showStudentDetail(v, pay_status, sex, province_flag) {
    if(!v) {
      v = {};
    }
    v.pay_status = pay_status;
    v.std_sex = sex;
    v.province_flag = province_flag;
    this.showComponentModal(EnrolReportAspectDetailComponent, {ResponseEntity: v});
  }

}
