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

@Component({
  selector: 'app-std-reg-date-modify',
  templateUrl: './std-reg-date-modify.component.html',
  styleUrls: ['./std-reg-date-modify.component.scss']
})
export class StdRegDateModifyComponent extends FrameDetailComponent implements OnInit {

  roomArr = [];
  timeArr = [];
  dateArr = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) { 
    super(bsModalRef);
    this.detailForm = fb.group({
      'new_ly_exam_date': [null, Validators.required],
      'new_ly_room_id': [null],
      'note': [null, null],
      'time_type': [null, null]
    });
  }

  ngOnInit(): void {
    this.requestTimeType();
    this.requestExamDate();
  }

   //时段查询
   requestTimeType() {
    let array = this.FrameService.getFrameDictArray('ExamTimeType');
    this.timeArr = array;
    if(this.timeArr.length>0 && this.timeArr[0].dict_text !== '全天') {
      this.timeArr.splice(0, 0, {dict_text: '全天', dict_value: undefined});
    }
  }

  //考试日期
  requestExamDate() {
    this.AjaxService.requestArray('ly/room/interview/exam/date/list.htm', {ly_group_id: this.ResponseEntity.ly_group_id}, (array) => {
      this.dateArr = array;
    });
  }

  //根据日期-查询考场
  changeExamDate() {
    if(!this.currentEntity.new_ly_exam_date) return;
    this.AjaxService.requestArray('ly/room/interview/list/by/group/date.htm', {
      ly_group_id: this.ResponseEntity.ly_group_id, 
      exam_date: this.currentEntity.new_ly_exam_date
    }, (array) => {
      this.roomArr = array;
    });
  }

  //更改考试安排
  modifyGroup() {
    if (!this.currentEntity.new_ly_exam_date) {
      this.MsgService.errorToastr('必须指定考试日期！');
      return;
    }
    if (this.currentEntity.ly_room_id !== undefined) {
      if (!this.currentEntity.new_ly_room_id) {
        this.MsgService.errorToastr('必须指定考场信息！');
        return;
      }
    }
    this.MsgService.confirmAlert('确定要更改该项目的考试安排吗？', () => {
      this.AjaxService.requestEntity('std/reg/change/exam/date.htm', this.currentEntity, () => {
        this.MsgService.successToastr('修改成功！');
        this.closeWindow();
      });
    });
  }

}
