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

@Component({
  selector: 'app-std-record-search',
  templateUrl: './std-record-search.component.html',
  styleUrls: ['./std-record-search.component.scss']
})
export class StdRecordSearchComponent extends FlexTableComponent implements OnInit {

  public query = {
    query: "",
    year_code: "",
    school_id: null,
    std_type: "",
    status: "",
    major_code:""
  };

  curOrg = {id:"",org_code:"",org_name:"",contact_number:"",org_type:""};//当前登录人的机构

  QUERY_URL = "pl/plStdRecord/pageSearch.htm";
  SCHOOL_URL = "cf/cfOrganization/list.htm?org_type=1&status=1";
  YEAR_CODE_URL = "pl/plExamTime/list.htm";
  EXPORT_URL = "pl/plStdRecord/export.htm";
  LASTEST_YEAR_CODE_URL = "pl/plStdRecordTime/getBatch.htm";

  constructor() {
    super();
  }

  ngOnInit() {
    this.changeSchool();
    
    setTimeout(
      ()=>{
        FrameRequest.requestEntity(this.LASTEST_YEAR_CODE_URL, {}, (entity) => {
          if (entity) {
            
            this.query.year_code = entity.year_code;
            this.framePager.reload();
          }
        });
      }
      ,300
    )

    
  }

  changeSchool(){
      //if('999'==localStorage.getItem("optr_org_id")){
     //   this.query.school_id =null;
     // }
      //else if(null != localStorage.getItem("optr_org_id")){
      //  this.query.school_id = parseInt(localStorage.getItem("optr_org_id"));
      //}
      
      
      
  }

  //导出
  export() {
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.EXPORT_URL, {
      year_code : this.query.year_code,
      status : this.query.status,
      std_type : this.query.std_type,
      school_id : this.query.school_id,
      major_code:this.query.major_code
    }, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("考生备案导出成功");
    });
  }

  

}
