import { Component, OnInit,Input} from "@angular/core";
import { BsModalService } from "ngx-bootstrap/modal";
import { FlexModalComponent } from "../../../../../shared/common/FlexModal.component";
import { AppComponent } from "../../../../../app.component";
import { FrameRequest } from "../../../../../shared/frame/frame-request";
import { DomSanitizer } from '@angular/platform-browser';

@Component({
  selector: "flex-pdf-viewer-modal",
  templateUrl: "./flex-pdf-viewer-modal.html",
  styleUrls: ["./flex-pdf-viewer-modal.scss"]
})
export class FlexPdfViewerModal extends FlexModalComponent implements OnInit {

  PDF_URL = "by/byApply/getByApplyRegisterPdfForBatch.htm";

//	let checkedArray = this.framePager.getCheckedArray((item)=>item.id);
  @Input()
  pdfCheckedArray: any 

  pdfurl:any;
  pdfname:any;
  constructor(
	public bsModalService: BsModalService,
	private sanitizer: DomSanitizer
  ) {
    super(bsModalService);
  }
  ngOnInit() {

  }

  async preShowModalWin(){
	  
	let checkedArray=[];
	this.pdfCheckedArray.forEach(item => {
		checkedArray.push(item.id);
	});
	if (checkedArray.length == 0) {
	  AppComponent.alert({title:"信息提示",text:"请选择考生毕业申请!"});
	  this._concel();
	  return false;
	}
	AppComponent.GobalComponent.setLoading(true);
	FrameRequest.downloadService(this.PDF_URL, {applyIds: checkedArray.join()}).subscribe(res => {
		let content = res.headers.get('content-disposition');
		this.pdfname = content.substring(content.indexOf("=")+1,content.length);
		let blob = new Blob([res.json()], { type: "application/pdf" });
		let objectUrl = URL.createObjectURL(blob);
		this.pdfurl = this.sanitizer.bypassSecurityTrustResourceUrl(objectUrl); 
		AppComponent.GobalComponent.setLoading(false);
	  });
    return true
  }

}
