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

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


  public query = {
    query: "",
    year_code: 0
  };

  YEAR_CODE_URL = "pl/plExamTime/list.htm";
  LATEST_TIME_URL = "pl/plExamTime/getCurrentYearCode.htm";
  EXPORT_UNIT_URL = "pl/kwExamUnit/exprotDbf.htm";
  LIST_UNIT_URL = "pl/kwExamUnit/listExamUnit.htm";
  EXPORT_TIME_URL = "pl/plExamTime/exportTimeDbf.htm";
  EXPORT_COURSE_URL = "pl/plCourse/exportCourseDbf.htm";
  LIST_COURSE_URL = "pl/plCourse/listCourseDbf.htm";
  EXPORT_DETAIL_URL = "kw/kwLayoutDetail/exportDetailDbf.htm";
  EXPORT_SCORE_URL = "kw/kwLayoutDetail/exportDetailScoreDbf.htm";
  LIST_SCORE_URL = "kw/kwLayoutDetail/listDetailDbfCount.htm";

  constructor() { }

  ngOnInit() {
    setTimeout(() => {
      FrameRequest.requestEntity(this.LATEST_TIME_URL, {}, (entity) => {
        if (entity) {
          this.query.year_code = Number.parseInt(entity);
        }
      });
    }, 200);
  }


  //导出考区码表
  exportUnit() {
    if (!this.query.year_code) {
      AppComponent.alert({ title: '提示', text: '请选择批次信息！' });
      return;
    }
    FrameRequest.requestArray(this.LIST_UNIT_URL, { year_code: this.query.year_code }, (array) => {
      if (!array || array.length === 0) {
        AppComponent.alert({ title: '提示', text: '当前批次下考区码表没有可导出数据！' });
        return;
      } else {
        AppComponent.GobalComponent.setLoading(true);
        FrameRequest.download(this.EXPORT_UNIT_URL, { year_code: this.query.year_code }, () => {
          AppComponent.GobalComponent.setLoading(false);
          AppComponent.GobalComponent.successMsg("考区码表导出成功");
        });
      }
    });

  }

  //导出考试时间码表
  exportTime() {
    if (!this.query.year_code) {
      AppComponent.alert({ title: '提示', text: '请选择批次信息！' });
      return;
    }
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.EXPORT_TIME_URL, { year_code: this.query.year_code }, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("考试时间码表导出成功");
    });
  }

  //导出课程码表
  exportCourse() {
    if (!this.query.year_code) {
      AppComponent.alert({ title: '提示', text: '请选择批次信息！' });
      return;
    }
    FrameRequest.requestArray(this.LIST_COURSE_URL, { year_code: this.query.year_code }, (array) => {
      if (!array || array.length === 0) {
        AppComponent.alert({ title: '提示', text: '当前批次下课程码表没有可导出数据！' });
        return;
      } else {
        AppComponent.GobalComponent.setLoading(true);
        FrameRequest.download(this.EXPORT_COURSE_URL, { year_code: this.query.year_code }, () => {
          AppComponent.GobalComponent.setLoading(false);
          AppComponent.GobalComponent.successMsg("课程码表导出成功");
        });
      }
    });
  }

  //导出座位表
  exportDetail() {
    if (!this.query.year_code) {
      AppComponent.alert({ title: '提示', text: '请选择批次信息！' });
      return;
    }
    FrameRequest.requestEntity(this.LIST_SCORE_URL, { year_code: this.query.year_code }, (entity) => {
      if (!entity || entity === 0) {
        AppComponent.alert({ title: '提示', text: '当前批次下座位表没有可导出数据！' });
        return;
      } else {
        AppComponent.GobalComponent.setLoading(true);
        FrameRequest.download(this.EXPORT_DETAIL_URL, { year_code: this.query.year_code }, () => {
          AppComponent.GobalComponent.setLoading(false);
          AppComponent.GobalComponent.successMsg("座位表导出成功");
        });
      }
    });
  }

  //导出座位表
  exportScore() {
    if (!this.query.year_code) {
      AppComponent.alert({ title: '提示', text: '请选择批次信息！' });
      return;
    }
    FrameRequest.requestEntity(this.LIST_SCORE_URL, { year_code: this.query.year_code }, (entity) => {
      if (!entity || entity === 0) {
        AppComponent.alert({ title: '提示', text: '当前批次下成绩表没有可导出数据！' });
        return;
      } else {
        AppComponent.GobalComponent.setLoading(true);
        FrameRequest.download(this.EXPORT_SCORE_URL, { year_code: this.query.year_code }, () => {
          AppComponent.GobalComponent.setLoading(false);
          AppComponent.GobalComponent.successMsg("成绩表导出成功");
        });
      }
    });
  }

}