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

@Component({
  selector: 'app-plan-group-detail',
  templateUrl: './plan-group-detail.component.html',
  styleUrls: ['./plan-group-detail.component.scss']
})
export class PlanGroupDetailComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);

    this.detailForm = fb.group({
      'pn_name': [null, Validators.compose([Validators.required])],
      'pn_type': [null, Validators.compose([Validators.required])],
      'qualified_min_score': [null, Validators.compose([Validators.required, Validators.min(0), Validators.max(999)])],
      'sex_flag': [null, Validators.compose([Validators.required])],
      'pn_order': [null, Validators.compose([Validators.required])],
      'qualified_subject_param': [null]

    });
  }


  initDefautEntity() {

  }

  ngOnInit() {
  }

  saveGroup() {
    if (!this.validForm())
      return;
    MsgService.confirmAlert('确定要保存划线分组吗？如果没有更改任何信息，请不要点击保存按钮，以免出现不必要的数据校验！', () => {
      this.currentEntity.aspect_json = JSON.stringify(this.ResponseArray);
      AjaxService.request('plan/group/save.htm', this.currentEntity, () => {
        this.closeWindow();
      });
    });
  }

}
