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 { CfMaterialDefDetailComponent } from '../material-def-detail/material-def-detail.component';
import { CfMaterialFeedBackComponent } from '../material-feedback/material-feedback.component';
import { CfMaterialTextAttrComponent } from '../material-textattr/material-textattr.component';

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

  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.requestData();
      }
    });
  }

  changeSchool() {
    this.requestData();
  }

  requestData() {
    this.pager.reload({school_id : this.query.school_id});
  }

  setFeedBack(v) {
    this.showComponentModal(CfMaterialFeedBackComponent, { 'ResponseEntity': v });
  }

  setTextAttr(v: any) {
    this.showComponentModal(CfMaterialTextAttrComponent, { 'ResponseEntity': v });
  }
}
