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-init',
  templateUrl: './plan-group-init.component.html',
  styleUrls: ['./plan-group-init.component.scss']
})
export class PlanGroupInitComponent extends FrameDetailComponent implements OnInit {

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

    this.detailForm = fb.group({
      'plan_type': [null, Validators.compose([Validators.required])],
      'qualified_min_score': [null, Validators.compose([Validators.required, Validators.min(0), Validators.max(999)])]
    });
  }


  initDefautEntity() {
    this.currentEntity = {
      plan_type: 'Country',
      qualified_min_score: 60
    };
  }

  saveInit() {
    MsgService.confirmAlert('确定要进行划线初始化吗？', () => {
      AjaxService.request('plan/group/init.htm', this.currentEntity, () => {
        MsgService.successAlert('划线数据已经初始化，请进行分组及计划数设置！');
        this.closeWindow();
      }, {RequestWithLoading: true});
    });
  }

  ngOnInit() {
  }


}
