import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { ConfParamPageDetailComponent } from '../conf-param-page-detail/conf-param-page-detail.component';
import { ConfParamSyncComponent } from '../conf-param-sync/conf-param-sync.component';

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

    schoolArray = [];
    param = {
      school_id :''
    };

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

  ngOnInit(): void {
    this.AjaxService.requestArray('./cf/school/list.htm', {}, (array) => {
      this.schoolArray = array;
      if(this.schoolArray && this.schoolArray.length == 1) {
        this.param.school_id = this.schoolArray[0].school_id;
        setTimeout(() => {
          this.requestParam();
        }, 20);
      }
    });
  }

  requestParam() {
    this.pager.reload({school_id : this.param.school_id})
  }

  //刷新缓存
  reloadCache() {
    this.AjaxService.request('ex/param/reload.htm', {}, () => {
      this.MsgService.successToastr('缓存刷新成功！');
    }, {RequestWithLoading: true});
  }

  //复制参数
  showCopyModal() {
    this.showComponentModal(ConfParamSyncComponent, {ResponseArray: this.schoolArray}, {class:'modal-5p'});
  }

}
