

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';


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

  constructor(private activateInfo: ActivatedRoute, private router: Router, private modalService: BsModalService) {
    super(modalService);

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

        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 (this.category === undefined && this.categoryArray.length > 0) {
      //   this.category = this.categoryArray[0];
      //   this.category_id = this.categoryArray[0].category_id;
      // }
      if (array.length > 1) {
        array.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 });
  }

}
