import {Component, OnInit, ViewChild} from '@angular/core';
import { FrameDetailComponent } from '../../../frame/core/detail/frame.detail';
import { BsModalRef } from 'ngx-bootstrap/modal';
import {FormBuilder, Validators} from '@angular/forms';
import { MsgService } from '../../../../core/service/msg.service';
import { AjaxService } from '../../../../core/service/ajax.service';

@Component({
  selector: 'app-score-ym-ems-return',
  templateUrl: './score-ym-ems-return.component.html',
  styleUrls: ['./score-ym-ems-return.component.scss']
})
export class ScoreYmEmsReturnComponent extends FrameDetailComponent implements OnInit {

  std;
  @ViewChild('ems_code', {static: false}) ems_code;
  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'ems_code': [null, Validators.compose([Validators.required, Validators.minLength(13), Validators.maxLength(13)])],

    });
  }


  initDefautEntity() {
  }
  ngOnInit() {

  }

  /***********
   * 修改了身份证号
   */
  changeCertId() {
    if (this.currentEntity.ems_code === undefined || $.trim(this.currentEntity.ems_code).length !== 13)
      return;
    // 提交

    this.currentEntity.requesting = true;
    AjaxService.requestMap('score/ym/ems/query.htm', this.currentEntity, (map) => {

       this.std = map;
       if(this.std === undefined) {
         MsgService.warningToastr(`未找到EMS号码【${ this.currentEntity.ems_code}】对应的专业和考生`);
       }
        this.afertCertIdRequest();
    }, {
      ErrorCallback: this.afertCertIdRequest.bind(this)
    });
  }

  afertCertIdRequest() {
    this.currentEntity.requesting = false;
    this.ems_code.nativeElement.focus();
    this.ems_code.nativeElement.select();

  }

}
