import { FlexTableComponent } from '../../../../../shared/common/FlexTable.component';
import { Component, OnInit, ViewChild } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal/bs-modal.service';
import { FrameRequest } from '../../../../../shared/frame/frame-request';
import 'ztree';
import * as _ from 'lodash';
import { Validators, FormBuilder } from '@angular/forms';
import { CustomValidators } from 'ng2-validation';
import { AppComponent } from '../../../../../app.component';
declare var $: any;

@Component({
  selector: 'app-kw-security-code',
  templateUrl: './kw-security-code.component.html',
  styleUrls: ['./kw-security-code.component.scss']
})

export class KwSecurityCodeComponent extends FlexTableComponent implements OnInit {

  public query = {
    exam_time_id: "",
    query: "",
  };

  //TODO
  QUERY_URL = "kw/nomal/securitycode/page.htm";


  agentArray = []
  examTimeIdArray = []

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

    /*FrameRequest.requestArray('kw/kwExamPoint/listAll.htm', {}, (array) => {
      this.agentArray = array;
    });*/

    FrameRequest.requestArray('pl/plExamTime/listtime.htm', {}, (array) => {
      this.examTimeIdArray = array;
    });
  }

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

  exportPdf() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"请选择考试批次!"});
      return;
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("kw/nomal/securitycode/exportpdf.htm",this.query,()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功!");
    });
  }

  exportExcel() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"请选择考试批次!"});
      return;
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("kw/nomal/securitycode/exportxls.htm",this.query,()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功!");
    });
  }
}
