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

declare let laydate;

@Component({
  selector: 'app-cf-aspect-detail',
  templateUrl: './aspect-detail.component.html',
  styleUrls: ['./aspect-detail.component.scss']
})
export class CfAspectDetailComponent extends FrameDetailComponent implements OnInit {
  schoolArray = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'aspect_code': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(12)])],
      'aspect_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(64)])],
      'pass_percent': [null,Validators.compose([Validators.required])],
      'pass_cnt': [null,Validators.compose([Validators.required])]
    });
  }

  ngOnInit() {
    AjaxService.requestArray("cf/school/list.htm",{},(array)=>{
      this.schoolArray = array;
      if (this.schoolArray.length == 1) {
        this.currentEntity.school_id = this.schoolArray[0].school_id;
      }
    }); 
  }

  initDefautEntity() {
    if (this.detailMode === 'add') {

    }
  }

  changePercent() {
    if (this.currentEntity.enrol_cnt && this.currentEntity.pass_percent) {
      //debugger;
      this.currentEntity.pass_cnt = Math.ceil(parseFloat(this.currentEntity.pass_percent)/100 * parseInt(this.currentEntity.enrol_cnt, 10));
    }
  }

}
