import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from 'src/app/routes/frame/core/page/frame.page';
import { TaskVideoReportDetailComponent } from '../task-video-report-detail/task-video-report-detail.component';

@Component({
  selector: 'app-task-video-report',
  templateUrl: './task-video-report.component.html',
  styleUrls: ['./task-video-report.component.scss']
})
export class TaskVideoReportComponent extends FramePageComponent implements OnInit {

  schoolArr = [];
  batchArr = [];
  task:any;

  constructor(private modalService: BsModalService, private cdr : ChangeDetectorRef) { 
    super(modalService);
  }

  ngOnInit(): void {
    this.task = {};
    this.AjaxService.requestArray('cf/school/list.htm', {}, (array)=> {
      this.schoolArr = array;
      if(this.schoolArr && this.schoolArr.length == 1) {
        this.task.school_id = this.schoolArr[0].school_id;
        this.requestBatch();
      }
    });
  }

   //查找批次
   requestBatch() {
    this.AjaxService.requestArray('cf/school/batch/list.htm', {
      school_id : this.task.school_id
    }, (array) => {
      this.batchArr = array;
      this.cdr.detectChanges();
      if(this.batchArr && this.batchArr.length == 1) {
        this.task.batch_id = this.batchArr[0].batch_id;
        this.ajax.reload({batch_id: this.task.batch_id});
      }
    });
  }

  showLayoutModal(v?) {
    if(!v) {
      v = {};
    }
    v.batch_id = this.task.batch_id;
    this.showComponentModal(TaskVideoReportDetailComponent, {ResponseEntity:v});
  }

}
