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

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

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'exam_tracks_num' : [null, Validators.compose([Validators.required])],
      'variety_name' : [null, Validators.compose([Validators.required])]
    });
  }

  ngOnInit(): void {
  }

  saveVariety() {
    for(const r of this.ResponseArray) {
      if(r.variety_order<1  || r.exam_tracks_num <1) {
        MsgService.errorToastr('品种的顺序和抽取的曲目数量，必须大于0!');
        return;
      }
    }
    AjaxService.request('cf/school/variety/save.htm', {
      json_value: JSON.stringify(this.ResponseArray)
    }, () => {
      MsgService.successToastr('品种配置成功！');
      this.closeWindow();
    });
  }

}
