import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
import { FormBuilder, Validators } from '@angular/forms';
import { BsModalService } from "ngx-bootstrap/modal";
import { FlexTableComponent } from "../../../../../shared/common/FlexTable.component";
import { AppComponent } from "../../../../../app.component";
import {FrameUploaderComponent} from '../../../../../core/uploader/uploader.component';
import { FrameRequest } from "../../../../../shared/frame/frame-request";
import { FramePagerComponent } from "../../../../../core/pager/pager.component";
import { FrameFunction } from "../../../../../shared/frame/frame_function";

@Component({
  selector: "app-by-name-list",
  templateUrl: "./by-name-list.component.html",
  styleUrls: ["./by-name-list.component.scss"]
})
export class ByNameListComponent extends FlexTableComponent implements OnInit {

  @ViewChild('framePager')
  framePager:FramePagerComponent;

  logOrgType = -1;//登录机构类型
  courseList=[];
  //url
  QUERY_URL = "by/byDiaplma/namelistpage.htm";
  EXPORT_URL = "by/byDiaplma/exportnamelist.htm";
  EXPORT_XLS_URL = "by/byDiaplma/exportnamelistForXls.htm";
  EXPORT_JPG_URL = "by/byDiaplma/exportnamelistForJpg.htm";
  ORG_URL = "by/byApply/listauthorg.htm" ;
  SCHOOL_URL = "cf/cfOrganization/list.htm?org_type=1&status=1";

  scoreList = [];
  majorList = [];
  

  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) {
    super();
    this.formModel = fb.group({
      id: [null],

    });
  }

  ngOnInit() {
    //专业
    FrameRequest.requestMap("by/byApply/initdata.htm", {}, async (map)=>{
      this.majorList  = map.majorList;//专业
      this.logOrgType = map.logOrgType;//当前登录机构类型
      this.query.exam_time_id=map.examTimeId;
    });

    //专业
    if (!this.query.exam_time_id) {
      this.query.exam_time_id = "";
    }
    
    FrameRequest.requestMap("by/byApply/listMajorByOrgId.htm", {exam_time_id:this.query.exam_time_id}, async (map)=>{
      this.majorList  = map.majorList;//专业
      
    });
  }
  chooseMajor() {

    if (!this.query.exam_time_id) {
      this.query.exam_time_id = "";
    }

    if (!this.query.org_id) {
      this.query.org_id = "";
    }

    //专业
    FrameRequest.requestMap("by/byApply/listMajorByOrgId.htm", {exam_time_id:this.query.exam_time_id,org_id:this.query.org_id}, async (map)=>{
      this.majorList  = map.majorList;//专业
      
    });
  }

  public query = {
    query: "",
    major_id: "",
    exam_time_id: "",
    std_source: "",
    org_id: "",
    school_id: "",
    status:""
  };

  search(param) {
    param.query=this.query.query;
    if (!this.query.exam_time_id) {
      this.query.exam_time_id="";
    }
    if (!this.query.major_id) {
      this.query.major_id="";
    }
    if (!this.query.std_source) {
      this.query.std_source="";
    }
    if (!this.query.org_id) {
      this.query.org_id="";
    }
    if (!this.query.school_id) {
      this.query.school_id="";
    }
    if (!this.query.status) {
      this.query.status="";
    }
    param.exam_time_id = this.query.exam_time_id;
    param.major_id = this.query.major_id;
    param.std_source = this.query.std_source;
    param.org_id = this.query.org_id;
    param.school_id = this.query.school_id;
    param.status = this.query.status;
  }


  //毕业生名册导出
  exportNameList() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"选择时间批次!"});
      return;
    }
    if (this.logOrgType == 0 && !this.query.org_id) {
      AppComponent.alert({title:"信息提示",text:"选择受理单位!"});
      return;
    }
    //if (!this.query.major_id) {
     // AppComponent.alert({title:"信息提示",text:"选择专业!"});
     // return;
    //}
    var parm = {
      examTimeId: this.query.exam_time_id,
      majorId: this.query.major_id,
      orgId: this.query.org_id,
      schoolId:this.query.school_id,
      status:this.query.status
    };

    AppComponent.confirmForTitle("温馨提醒","毕业生名册打印时，纸张选择A3，方向选择横向，根据打印预览效果，打印方式选择适合打印边际或实际大小。",()=>{
       //下载
      AppComponent.GobalComponent.setLoading(true);
      FrameRequest.download(this.EXPORT_URL, parm, ()=>{
        AppComponent.GobalComponent.setLoading(false);
      });
    });

   
  }

//毕业生名册导出
exportNameListForXls() {
  if (!this.query.exam_time_id) {
    AppComponent.alert({title:"信息提示",text:"选择时间批次!"});
    return;
  }
  
 
  var parm = {
    examTimeId: this.query.exam_time_id,
    majorId: this.query.major_id,
    orgId: this.query.org_id,
    schoolId:this.query.school_id,
    status:this.query.status
  };
  //下载
  AppComponent.GobalComponent.setLoading(true);
  FrameRequest.download(this.EXPORT_XLS_URL, parm, ()=>{
    AppComponent.GobalComponent.setLoading(false);
  });
}

//毕业生照片导出
exportNameListForJpg() {
  if (!this.query.exam_time_id) {
    AppComponent.alert({title:"信息提示",text:"选择时间批次!"});
    return;
  }
  
 
  var parm = {
    examTimeId: this.query.exam_time_id,
    majorId: this.query.major_id,
    orgId: this.query.org_id,
    schoolId:this.query.school_id,
    status:this.query.status
  };
  //下载
  AppComponent.GobalComponent.setLoading(true);
  FrameRequest.download(this.EXPORT_JPG_URL, parm, ()=>{
    AppComponent.GobalComponent.setLoading(false);
  });
}

}