import { Component, OnInit } from '@angular/core';
import { FrameRequest } from '../../../../shared/frame/frame-request';
import { AppComponent } from '../../../../app.component';

@Component({
  selector: 'app-thesis',
  templateUrl: './thesis.component.html',
  styleUrls: ['./thesis.component.scss']
})
export class ThesisComponent implements OnInit {

  TEXTBOOK_URL = "pl/plTextbook/exprotDbf.htm";
  CTBOOK_URL = "pl/plTextbook/exportCtbook.htm";
  PUBLISH_PLAN_URL = "pl/mergePublishPlan/exprotDbf.htm";
  EXAM_TIME_URL = "pl/plExamTime/exportDbf.htm";
  COURSE_URL = "pl/plCourse/exportDbf.htm";
  MAJOR_URL = "pl/plMajor/exprotDbf.htm";
  YEAR_CODE_URL = "pl/plExamTime/queryExamYear.htm";

  constructor() { }

  public query = {
    exam_year: 0
  };

  ngOnInit() {
  }

  exportTextbook() {
    if (!this.query.exam_year) {
      AppComponent.alert({ title: "信息提示", text: "请选择年度码!" })
      return;
    }

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.TEXTBOOK_URL, {exam_year:this.query.exam_year}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("教材信息表导出成功");
    });
  }

  exportCtbook() {
    if (!this.query.exam_year) {
      AppComponent.alert({ title: "信息提示", text: "请选择批次!" })
      return;
    }

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.CTBOOK_URL, {exam_year:this.query.exam_year}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("教材配置表导出成功");
    });
  }

  exportPublishPlan() {
    if (!this.query.exam_year) {
      AppComponent.alert({ title: "信息提示", text: "请选择批次!" })
      return;
    }

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.PUBLISH_PLAN_URL, {exam_year:this.query.exam_year}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("当年开考计划导出成功");
    });
  }

  exportExamTime() {
    if (!this.query.exam_year) {
      AppComponent.alert({ title: "信息提示", text: "请选择批次!" })
      return;
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.EXAM_TIME_URL, {exam_year:this.query.exam_year}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("当年考试时间导出成功");
    });
  }

  exportCourse() {
    if (!this.query.exam_year) {
      AppComponent.alert({ title: "信息提示", text: "请选择批次!" })
      return;
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.COURSE_URL, {exam_year:this.query.exam_year}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("课程码表导出成功");
    });
  }

  exportMajor() {
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.MAJOR_URL, {}, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("专业码表导出成功");
    });
  }

}
