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-exam-course',
  templateUrl: './kw-exam-course.component.html',
  styleUrls: ['./kw-exam-course.component.scss']
})

export class KwExamCourseComponent extends FlexTableComponent implements OnInit {

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

  //TODO
  QUERY_URL = "kw/nomal/opencoursepage.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;
  }

  //课程汇总pdf
  courseTotalPdf() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"请选择考试批次!"});
      return;
    }
    let param = {
      exam_time_id: this.query.exam_time_id
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("kw/nomal/coursetotalpdf.htm",param,()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("下载成功!");
    });
  }

  //开考课程表pdf
  openExamCoursePdf() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"请选择考试批次!"});
      return;
    }
    let param = {
      exam_time_id: this.query.exam_time_id
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("kw/nomal/opencoursepdf.htm",param,()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功!");
    });
  }

  //分段科目表pdf
  examCourseSectionPdf() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"请选择考试批次!"});
      return;
    }
    let param = {
      exam_time_id: this.query.exam_time_id
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("kw/nomal/timeperiodpdf.htm",param,()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功!");
    });
  }

  //时段对照表pdf
  timeComparePdf() {
    if (!this.query.exam_time_id) {
      AppComponent.alert({title:"信息提示",text:"请选择考试批次!"});
      return;
    }
    let param = {
      exam_time_id: this.query.exam_time_id
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download("kw/nomal/timecomparepdf.htm",param,()=>{
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("导出成功!");
    });
  }
}
