import { Component, OnInit } from '@angular/core';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { AppComponent } from '../../../../..';
import { FrameRequest } from '../../../../../shared/frame/frame-request';
import { FlexTableComponent } from "../../../../../shared/common/FlexTable.component";
import { BsModalService } from "ngx-bootstrap/modal";
import { FormBuilder, Validators } from '@angular/forms';
import { DomSanitizer } from  '@angular/platform-browser';

import { error } from 'protractor';

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

  public query = {
    std_name: "",
    ticket_no: "",
    cert_no: "",
    majorId : ""
  };

  public export_query = {
    major_code: "",
    course_count: "4"
  };

  majorList = [];

  historyScore = []; //考生历史成绩
  paperScore = []; //毕业论文成绩
  orderNum : any;

  HISTROY_SCORE_URL = "kj/kjUnifiedScoreDetail/byPrediction.htm";
 



  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder,
    bfb: FormBuilder,
    private sanitizer: DomSanitizer,
  ) {
    super();
    
  }

  ngOnInit() {

    FrameRequest.requestArray("pl/plMajor/queryMajor.htm", {}, async (array)=>{
      this.majorList  = array;//专业
     
    });
     
  }

  searchStdScore() {
    

    if(!this.query.std_name && !this.query.ticket_no && !this.query.cert_no && !this.query.std_name) {
      AppComponent.alert({title:'提示', text: '请输入考生信息'});
      return;
    }
   
     if(null == this.query.majorId){
      this.query.majorId = "";
    }

    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.requestArray(this.HISTROY_SCORE_URL, {
      std_name : this.query.std_name,
      ticket_no : this.query.ticket_no,
      cert_no : this.query.cert_no,
      major_id : this.query.majorId
    }, (array) => {
      this.historyScore = array;
      this.orderNum = array.length;
      AppComponent.GobalComponent.setLoading(false);
    },(error)=>{
      AppComponent.GobalComponent.setLoading(false);
    }
   );
    
  }

  //重置
  reset() {
    this.query.std_name = "";
    this.query.ticket_no= "";
    this.query.cert_no = "";
    this.query.majorId = "";
    this.historyScore = [];
    this.paperScore = [];
  }


  showByPredictionExportModal(editFormTemplateModal, modalcss?){
    this.shouModalWin(editFormTemplateModal, modalcss);
  }

  byPredictionExport(){
    if(!this.export_query.major_code) {
      this.export_query.major_code = "";
     
    }
    
    if(this.export_query.course_count != '0' && !this.export_query.course_count) {
      AppComponent.alert({title:"信息提示",text:"请填写最多不及格科目数!"});
      return;
    }

    AppComponent.confirm("导出预毕业考生吗?",()=>{
       AppComponent.GobalComponent.setLoading(true);
        FrameRequest.download("kj/kjUnifiedScoreDetail/byPredictionExport.htm", {
          major_code : this.export_query.major_code,
          course_count:this.export_query.course_count
        }, () => {
          AppComponent.GobalComponent.setLoading(false);
          AppComponent.GobalComponent.successMsg("导出预毕业考生成功");
        });
    });  

  }

}
