import { Component, OnInit, Input, ViewChild, Output, EventEmitter, TemplateRef } from "@angular/core";
import { FlexTableComponent } from "../../../../shared/common/FlexTable.component";
import { FormBuilder, Validators } from '@angular/forms';
import { CustomValidators } from 'ng2-validation';
import { BsModalService } from "ngx-bootstrap/modal";
import { FramePagerComponent } from "../../../../core/pager/pager.component";
import { FrameRequest } from "../../../../shared/frame/frame-request";
import { FrameUploaderComponent } from "../../../../core/uploader/uploader.component";
import { AppComponent, InjectorInstance } from "../../../..";
import { FrameValidator } from "../../../../shared/frame/Frame-validator";
import { FrameFunction } from "../../../../shared/frame/frame_function";
import { FlexSelectComponent } from "../../../../shared/components/flexSelect/FlexSelect.component";

import { DomSanitizer } from  '@angular/platform-browser';
import { RequestOptions } from "@angular/http";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { FrameVariable } from "../../../../shared/frame/frame-variable";
import { FileUploader, FileItem, ParsedResponseHeaders } from "ng2-file-upload";

import * as _ from 'lodash';
declare var webcamInit: any;

@Component({
  selector: "std-healthcode",
  templateUrl: "./std-healthcode.component.html",
  styleUrls: ["./std-healthcode.component.scss"]
})
export class StdHealthcodeComponent extends FlexTableComponent implements OnInit {
 
  public query = {
    "std_name": "",
    "cert_no": "",
    "ticket_no": "",
    "school_id":"",
    'year_code': "",
    "exam_area_id":"",
    "healthcode":"",
    "status":"",
    create_date:""
  };

  QUERY_URL = "std/healthcode/page.htm";
  

  EXAM_AREA_URL = "cf/cfOrganization/list.htm?org_type=4&status=1"; 
  SCHOOL_URL = "cf/cfOrganization/list.htm?org_type=1&status=1"; //主考学校



  @ViewChild('uploader')
  uploader: FrameUploaderComponent;


  

  isSFZ = true;//是否身份证
  
  @ViewChild('exam_time_id')  
  exam_time_id:FlexSelectComponent
  


  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder,
    bfb: FormBuilder,
    private sanitizer: DomSanitizer,
  ) {
    super();
    
  }

  ngOnInit() {
    //自动选择当前批次
    setTimeout(() => {
      FrameRequest.request('pl/plExamTime/getCurrentYearCodeForTicketNo.htm',{}, (resp) => {
        this.exam_time_id.items.forEach((item) => {
          if(item.year_code == resp.entity){
            this.query.year_code = item.year_code;
          }
          
         });
        }
      )
    }, 1000);

   // FrameRequest.requestArray('std/stdRegInfo/queryCity.htm',{}, (array) => {
    //  this.std_citys = array;
    //  }
  //  );

  //  this.initMajorArray();

  //  this.initOptrExamArea();
  }



  exportExcel(){
    let reqParam = this.query;
    reqParam['fileName'] = '考生健康码.xlsx';

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("std/healthcode/export.htm", reqParam, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功");
    });

  }

  
  queryStdHealthcode(){
    AppComponent.confirm("确定更新当天当前批次报考考生的健康码吗?",()=>{
      FrameRequest.request("std/healthcode/queryStdHealthcode.htm", {exam_area_id:this.query.exam_area_id,school_id:this.query.school_id}, (ret) => {
        if (ret.success) {
            //提示
            AppComponent.GobalComponent.successMsg('更新当天当前批次报考考生的健康码提交成功，系统后台正在处理中，预计半小时内完成。');
          
        }else{
          AppComponent.GobalComponent.errorMsg(ret.errorMsg);
        }
      });
  });
  }
  

}
