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 { MsgService } from '../../../../core/service/msg.service';
import { FramePager } from '../../../../core/frame/pager/frame-pager/frame-pager';
import { CfMaterialRuleDetailComponent } from '../material-rule-detail/material-rule-detail.component';
import { SetAspectComponent } from '../set-aspect/set-aspect.component';
import { SetStdEduComponent } from '../set-stdedu/set-stdedu.component';

@Component({
  selector: 'app-cf-material-rule-page',
  templateUrl: './material-rule-page.component.html',
  styleUrls: ['./material-rule-page.component.scss']
})
export class CfMaterialRulePageComponent extends FramePageComponent implements OnInit {
  schoolArray = [];
  batchArray = [];
  query = {
    school_id : '',
    batch_id : ''
  };
  constructor(private modalService: BsModalService) {
    super(modalService);
    this.modalComponent = CfMaterialRuleDetailComponent;
  }

  ngOnInit() {
    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();
      } 
    });
  }

  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() {
    this.pager.pagerParams["school_id"] = this.query.school_id;
    this.pager.pagerParams["batch_id"] = this.query.batch_id;
    this.pager.reload();
  }

  setStdEduWin(v) {
    this.onModalClose = () => {
      this.pager.reload();
    };
    this.showComponentModal(SetStdEduComponent, { 'ResponseEntity': v });
  }

  setAspectWin(v) {
    this.onModalClose = () => {
      this.pager.reload();
    };
    this.showComponentModal(SetAspectComponent, { 'ResponseEntity': v });
  }


}
