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-score-rate',
  templateUrl: './score-rate.component.html',
  styleUrls: ['./score-rate.component.scss']
})
export class ScoreRateComponent extends FlexTableComponent implements OnInit {

  public query = {
    query: "",
    year_code: 0,
    score_type:"1",
    school_id:"",
    std_type:"",
    major_code:""
  };
  QUERY_URL = "kj/kjUnifiedScoreDetail/pageScore.htm";
  EXPORT_URL = "kj/kjUnifiedScoreDetail/export.htm";
  YEAR_CODE_URL = "pl/plExamTime/list.htm";
  LATEST_TIME_URL = "pl/plExamTime/getCurrentYearCode.htm";

  SCHOOL_URL = "cf/cfOrganization/list.htm?org_type=1&status=1";

  constructor() { 
    super();
  }

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

  
  export() {
    if (!this.query.year_code) {
      AppComponent.alert({title:"信息提示",text:"请选择批次!"});
      return;
    }

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.EXPORT_URL, {year_code:this.query.year_code,score_type:this.query.score_type,school_id:this.query.school_id,std_type:this.query.std_type,major_code:this.query.major_code}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("课程考试情况统计导出成功");
    });
  }

}
