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

@Component({
  selector: 'app-point-examroom-num',
  templateUrl: './point-examroom-num.component.html',
  styleUrls: ['./point-examroom-num.component.scss']
})
export class PointExamroomNumComponent implements OnInit {

  QUERY_URL = "kw/kwLayout/pointexamnum.htm";
  EXPORT_URL = "kw/kwLayout/exportroomnum.htm";
  A_roomNum = []; //第一场次
  B_roomNum = []; //第二场次
  C_roomNum = []; //第三场次
  D_roomNum = []; //第四场次
  X_roomNum = []; //第四场次
  Y_roomNum = []; //第四场次
  temp_roomNum = []; //中间变量
  total:any;
  constructor() { }

  ngOnInit() {
    FrameRequest.requestMap(this.QUERY_URL, {}, (map) => {
      if (map) {
        this.A_roomNum = map['A'];
        this.B_roomNum = map['B'];
        this.C_roomNum = map['C'];
        this.D_roomNum = map['D'];
        this.X_roomNum = map['X'];
        this.Y_roomNum = map['Y'];
        this.total = map['total'];
      }
      this.getMaxRoomNum(this.A_roomNum, this.B_roomNum, this.C_roomNum, this.D_roomNum, this.X_roomNum, this.Y_roomNum);
    });
  }
  //取最大的数组
  getMaxRoomNum(A_roomNum: any[], B_roomNum: any[], C_roomNum: any[], D_roomNum: any[], X_roomNum: any[], Y_roomNum: any[]) {
    let a, b, c, d,x,y = 0;
    let m, n;
    let max;
    if (A_roomNum) {
      a = A_roomNum.length;
    }
    if (B_roomNum) {
      b = B_roomNum.length;
    }
    if (C_roomNum) {
      c = C_roomNum.length;
    }
    if (D_roomNum) {
      d = D_roomNum.length;
    }
    if (X_roomNum) {
      x = X_roomNum.length;
    }
    if (Y_roomNum) {
      y = Y_roomNum.length;
    }
    if (a > b) m = a;
    else m = b;
    if (c > d) n = c;
    else n = d;
    if (x > y) n = x;
    else n = y;
    if (m > n) max = m;
    else max = n;
    if (max === a) this.temp_roomNum = A_roomNum;
    if (max === b) this.temp_roomNum = B_roomNum;
    if (max === c) this.temp_roomNum = C_roomNum;
    if (max === d) this.temp_roomNum = D_roomNum;
    if (max === x) this.temp_roomNum = X_roomNum;
    if (max === y) this.temp_roomNum = Y_roomNum;

  }

  //导出考点考场数
  export() {
    FrameRequest.download(this.EXPORT_URL, {}, () => {
      AppComponent.GobalComponent.successMsg('导出成功');
    });
  }

}
