import {Component, OnInit, ViewChild} from '@angular/core';
import {FramePageComponent} from "../../../frame/core/page/frame.page";
import {BsModalService} from "ngx-bootstrap/modal";
import { AjaxService } from '../../../../core/service/ajax.service';
import { StdDetailComponent } from '../std-detail/std-detail.component';

@Component({
  selector: 'app-std-page',
  templateUrl: './std-page.component.html',
  styleUrls: ['./std-page.component.scss']
})
export class StdPageComponent extends FramePageComponent implements OnInit {
  schoolArray = [];
  batchArray = [];
  query={
    school_id: '',
    batch_id:'',
    std_type: ''
  };

  
  constructor(private modalService: BsModalService) {
    super(modalService);
    this.modalComponent = StdDetailComponent;
    this.AjaxService.requestArray('./cf/school/list.htm', {}, (array) => {
      this.schoolArray = array;
      if (this.schoolArray.length == 1) {
        this.query.school_id = this.schoolArray[0].school_id;
        this.queryBatchArray();
      } 
    });
  }

  ngOnInit() {
  }

  queryBatchArray() {
    //查询班级老师列表
    AjaxService.requestArray("cf/batch/list.htm",{school_id: this.query.school_id},(array)=>{
      this.batchArray = array;
      if (this.batchArray.length == 1) {
        this.query.batch_id = this.batchArray[0].batch_id;
        this.requestData();
      }
    });   
  }

  requestData() {
    setTimeout(() => {
      this.pager.reload();
    }, 20);
  }

}
