import { Component, OnInit } from '@angular/core';
import { FlexTableComponent } from '../../../../shared/common/FlexTable.component';
import { FrameRequest } from '../../../../shared/frame/frame-request';
import { AppComponent } from '../../../..';

@Component({
  selector: 'app-no-enrol-publish-plan',
  templateUrl: './no-enrol-publish-plan.component.html',
  styleUrls: ['./no-enrol-publish-plan.component.scss']
})
export class NoEnrolPublishPlanComponent extends FlexTableComponent implements OnInit {

  public query = {
    query: "",
    year_code: 0
  };
  QUERY_URL = "pl/mergePublishPlan/noEnrolPlan.htm";
  YEAR_CODE_URL = "pl/plExamTime/list.htm";
  LATEST_TIME_URL = "pl/plExamTime/getCurrentYearCode.htm";
  NO_ENROL_NUM_URL = "pl/mergePublishPlan/noEnrolPlanNum.htm"
  EXPORT_URL = "pl/mergePublishPlan/exportNoEnrolPlan.htm";
  noEnrolList = [];
  plan : any;

  constructor() { 
    super();
  }

  ngOnInit() {
    setTimeout(() =>{
      FrameRequest.requestEntity(this.LATEST_TIME_URL, { }, (entity) => {
        if (entity) {
          this.query.year_code = Number.parseInt(entity);
        }
        this.search();
      });
    },200);

    
  }

  search() {
    FrameRequest.requestArray(this.QUERY_URL, {year_code : this.query.year_code}, (array) => {
      this.noEnrolList = array;
    });

    FrameRequest.requestEntity(this.NO_ENROL_NUM_URL, {year_code: this.query.year_code}, (entity) => {
      if(entity) {
        this.plan = entity;
      }else{
        this.plan = {};
      }
    });

  }

  export() {
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.EXPORT_URL, {year_code : this.query.year_code}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("当次无人报考课程导出成功");
    });
  }

}
