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

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

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

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

  HISTROY_SCORE_URL = "kj/kjUnifiedScoreDetail/history.htm";
  PAPER_SCORE_URL = "kj/kjUnifiedScoreDetail/paperScore.htm";



  constructor(private activatedRoute: ActivatedRoute) {
    
   }

  ngOnInit() {
    let query_ticket_no =  this.activatedRoute.snapshot.queryParams["ticket_no"] 

    if(query_ticket_no){
      this.query.ticket_no = query_ticket_no;
      this.searchStdScore();
     
    }
     
  }

  searchStdScore() {
    if(!this.query.std_name && !this.query.ticket_no && !this.query.cert_no && !this.query.old_ticket_no) {
      AppComponent.alert({title:'提示', text: '请输入准考证号或身份证号或老考号'});
      return;
    }
    FrameRequest.requestArray(this.HISTROY_SCORE_URL, {
      std_name : this.query.std_name,
      ticket_no : this.query.ticket_no,
      cert_no : this.query.cert_no,
      old_ticket_no : this.query.old_ticket_no
    }, (array) => {
      this.historyScore = array;
      this.orderNum = array.length;
    });
    FrameRequest.requestArray(this.PAPER_SCORE_URL, {
      ticket_no : this.query.ticket_no,
      cert_no : this.query.cert_no,
      old_ticket_no : this.query.old_ticket_no
    }, (array) => {
      this.paperScore = array;
    });
  }

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


  carouselContentFilter(str) {
    
    if(str){
        var carContent ='';
        if(str.length >= 50){
           
            carContent = str.substring(0,50) + '...';
        }
        else {
            carContent = str
        }
        return carContent;
    }else{
      return str;
    }
}

}
