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-pl-diplomaprint",
  templateUrl: "./diploma-print.component.html",
  styleUrls: ["./diploma-print.component.scss"]
})
export class DiplomaPrintComponent extends FlexTableComponent implements OnInit {

  public query = {
    query: "",
    major_id: "",
    school_id: "",
    exam_time_id: "",
	cityOrgId:'',
	org_name:''
  };

  @ViewChild('uploader')
  uploader: FrameUploaderComponent;
  @ViewChild('framePager')
  framePager:FramePagerComponent;

  courseList=[];
  //url
  QUERY_URL = "by/byDiaplma/pagecardcore.htm";
  ORG_LIST_URL = "cf/cfOrganization/list.htm";

  orgList = [];
  authList = [];
  majorList = [];
  masterSchoolList = [];

  applyStatus = {
    NEW_0: 0,
    TO_FIRST_AUDIT_1: 1,
    TO_FINAL_AUDIT_2: 2,
    TO_DISTRIBUTE_3: 3,
    ARCHIVED_4: 4
  };

  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) {
    super();
  }

  ngOnInit() {
    //专业
    var parm = {
      start:0,
      limit:9999,
      nation_exam:"",
      query:"",
      major_level:"",
      year:"",
      status:""
    };
    
    FrameRequest.requestMap("by/byApply/initdata.htm", {}, (map)=>{
      this.majorList  = map.majorList;//专业
      this.orgList = map.cityOrgList;//市考办
      this.masterSchoolList = map.schoolOrgList;//主考学校
      this.query.exam_time_id=map.examTimeId;
      this.framePager.reload();
    });

   
     
  }

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

  //毕业证芯pdf
  cardCorePrint() {
    //let checkedArray = this.framePager.getCheckedArray();
    if (!this.query.exam_time_id) {
      this.query.exam_time_id="";
    }
    if (!this.query.school_id) {
      this.query.school_id="";
    }
    if (!this.query.major_id) {
      this.query.major_id="";
    }
    if (!this.query.cityOrgId) {
		this.query.cityOrgId='';
	}

    let parm = {
      
      query: this.query.query,
      exam_time_id : this.query.exam_time_id,
      school_id: this.query.school_id,
      org_id: this.query.cityOrgId,
      major_id: this.query.major_id
    }
    
    //下载
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("by/byDiaplma/exportcardcorepdf.htm", parm, ()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("下载成功!");
    });
    
  }

    /**
   * 查询列表选择
   */
  orgQueryModal(modal) {
	let codeArray = modal.framePager.getCheckedArray((item)=>item.org_code);
	let checkedArray = modal.framePager.getCheckedArray((item)=>item.id);
	this.query.org_name='';
	this.query.cityOrgId='';
    if (checkedArray.length > 0) {
		this.query.org_name= codeArray.join('|');
		this.query.cityOrgId= checkedArray.join();
      modal.hideModal();
    }
  }
}