import { Component, OnInit } from '@angular/core';
import { FrameRequest } from '../../../../../shared/frame/frame-request';
import { AppComponent } from '../../../../..';

@Component({
  selector: 'app-kw-special-layout-result',
  templateUrl: './kw-special-layout-result.component.html',
  styleUrls: ['./kw-special-layout-result.component.scss']
})
export class KwSpecialLayoutResultComponent implements OnInit {
  query = {
    batch_id: '',
    exam_time_id: ''
  };

  EXAM_TIME_URL = "pl/plExamTime/listtime.htm";
  LIST_URL = "kw/kwSpecialLayout/list.htm";
  POINT_LIST_URL = "kw/kwSpecialLayout/listPoint.htm";
  ROOM_LIST_URL = "kw/kwSpecialExamRoom/list.htm";
  RESULT_URL = "kw/kwSpecialLayout/listLayout.htm";
  pointList = [];//考点列表
  roomList = [];//考场列表
  layoutList = [];//编排结果
  room_id: any;

  constructor() { }

  ngOnInit() {
  }

  getPoint(exam_time_id: any) {
    if (exam_time_id) {
      FrameRequest.requestArray(this.POINT_LIST_URL, { exam_time_id: exam_time_id }, (array) => {
        this.pointList = array;
      });
    } else {
      this.pointList = [];
    }
  }

  getLayout(item: any) {
    if (item) {
      this.room_id = item.id;
      FrameRequest.requestArray(this.RESULT_URL, { room_id: item.id }, (array) => {
        this.layoutList = array;
      })
    }
  }

  listRoom() {
    if (!this.nullJudge()) return;
    FrameRequest.requestArray(this.ROOM_LIST_URL, { batch_id: this.query.batch_id }, (array) => {
      this.roomList = array;
    })
  }

  nullJudge(flag?: any) {
    if (!this.query.exam_time_id) {
      AppComponent.alert({ 'title': '提示', 'text': '请选择考试时间' });
      return false;
    }
    if (!this.query.batch_id) {
      AppComponent.alert({ 'title': '提示', 'text': '请选择考点' });
      return false;
    }
    return true;
  }

}
