import { Component, OnInit, ViewChild } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePager } from 'src/app/core/frame/pager/frame-pager/frame-pager';
import { FramePageComponent } from 'src/app/routes/frame/core/page/frame.page';
import { ConfSchoolBatchDetailComponent } from '../conf-school-batch-detail/conf-school-batch-detail.component';
import { ConfSchoolDetailComponent } from '../conf-school-detail/conf-school-detail.component';
import { ConfSchoolSubjectDetailComponent } from '../conf-school-subject-detail/conf-school-subject-detail.component';
import { ConfSchoolVarietyDetailComponent } from '../conf-school-variety-detail/conf-school-variety-detail.component';

@Component({
  selector: 'app-conf-school-page',
  templateUrl: './conf-school-page.component.html',
  styleUrls: ['./conf-school-page.component.scss']
})
export class ConfSchoolPageComponent extends FramePageComponent implements OnInit {

  @ViewChild('batchPager', { static: false }) batchPager: FramePager;
  @ViewChild('subjectPager', { static: false }) subjectPager: FramePager;
  @ViewChild('varietyPager', { static: false }) varietyPager: FramePager;

  step = 'main';
  query = {
    school_id: '',
    subject_id: ''
  }

  constructor(private modalService: BsModalService) {
    super(modalService);
    this.modalComponent = ConfSchoolDetailComponent;
  }

  ngOnInit(): void {
  }

  detailPage(school_id, detail_step, subject_id?) {
    this.query.school_id = school_id;
    this.query.subject_id = subject_id;
    this.step = detail_step;
  }

  goStep(step) {
    this.step = step;
  }

  //新增批次
  showAddEditBatch(v?) {
    this.onModalClose = () => {
      this.batchPager.reload();
    };
    if (v) {
      this.showComponentModal(ConfSchoolBatchDetailComponent, { 'ResponseEntity': v });
    } else {
      localStorage.setItem('school_id', this.query.school_id);
      this.showComponentModal(ConfSchoolBatchDetailComponent);
    }
  }

  //修改科目
  showEditSubject(v) {
    this.onModalClose = () => {
      this.subjectPager.reload();
    };
    this.showComponentModal(ConfSchoolSubjectDetailComponent, { 'ResponseEntity': v });
  }

  //展示所有的品类
  showVariety(v) {
    this.showComponentModal(ConfSchoolVarietyDetailComponent, {
      'ResponseEntity': v,
      'arrayUrl': 'cf/school/variety/list.htm',
      'arrayParam': {
        subject_id: v.subject_id
      }
    });
  }

}
