import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FormBuilder, Validators } from '@angular/forms';
import { FlexTableComponent } from '../../../../../shared/common/FlexTable.component';
import { FrameUploaderComponent } from '../../../../../core/uploader/uploader.component';
import { AppComponent } from '../../../../../app.component';
import { FrameRequest } from '../../../../../shared/frame/frame-request';
import { FrameFunction } from '../../../../../shared/frame/frame_function';
import { ByFilesPdfViewerModal } from '../../by-files-pdf-viewer/by-files-pdf-viewer-modal';


@Component({
  selector: 'app-by-roster-query',
  templateUrl: './by-roster-query.component.html',
  styleUrls: ['./by-roster-query.component.scss']
})
export class ByRosterQueryComponent  extends FlexTableComponent implements OnInit {

  public query = {
   
    bysj:"",
    tag:""

  };
  resultList:any;
  FrontFilesList: any;

  batchArr = [];
  tagArr = [];

  /**  暂时无用
   * step:string = 'main';
   * timeList = ['1999年6月','2000年6月','2001年12月','2002年12月']
   */

  QUERY_URL = "by/byRoster/page.htm";
  GET_URL= "by/byRoster/get.htm";


  
  DOWNLOAD_URL = "by/byRoster/download.htm";

  BATCH_URL ="by/byRoster/bysj/list.htm";

  @ViewChild('uploader')
  uploader: FrameUploaderComponent;
  @ViewChild('byFilesPdfModal') byFilesPdfModal: ByFilesPdfViewerModal;

  constructor(public bsModalService: BsModalService, fb: FormBuilder) {
    super();
    this.formModel = fb.group({
    });
   }

  ngOnInit() {
    this.requestBatch();
  }

  requestBatch() {
    FrameRequest.requestArray(this.BATCH_URL, {}, (array)=> {
      this.batchArr = array;
    });
  }

  getTag($event) {
    this.tagArr = [];
    FrameRequest.requestArray('by/byRoster/tag/list.htm', {bysj: $event}, (array)=> {
      this.tagArr = array;
    });
  }

  //检索考生档案
  search(param) {
    
   
    if(!this.query.bysj) {
      this.query.bysj = "";
    }

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

    param.bysj = this.query.bysj;
    param.tag = this.query.tag;


  }

  preShow(id){
    FrameRequest.requestEntity("by/byRoster/byRosterIsExists.htm", {id: id,is_preView:true}, (entity) => {
      if (!entity) {
        this.byFilesPdfModal.ids= id;
        this.byFilesPdfModal.PDF_URL= 'by/byRoster/download.htm';
        this.byFilesPdfModal.show();
      }else{
        AppComponent.alert({title:"信息提示",text:entity});
      }
    });

  }

  listFrontFiles() {
    FrameRequest.requestArray('by/byFiles/query/front.htm', {limit: 6}, (array) => {
      this.FrontFilesList = array;
    });
  }



  /** 暂时无用
  goDetail(type) {
    this.step = type;
  }

  goStep(step) {
    this.step = step;
  }*/

}
