import { Component, OnInit } from '@angular/core';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { BsModalService } from 'ngx-bootstrap/modal';

@Component({
  selector: 'app-layout-result-conflict',
  templateUrl: './layout-result-conflict.component.html',
  styleUrls: ['./layout-result-conflict.component.scss']
})
export class LayoutResultConflictComponent extends FramePageComponent implements OnInit {

  agentArr = [];
  query = {
    agent_id: '',
    batch_id: ''
  }

  constructor(modalService: BsModalService) { 
    super(modalService);
    this.listAgent();
  }

  ngOnInit(): void {
  }

  listAgent() {
    this.AjaxService.requestArray('conf/agent/all.htm', {}, (array) => {
      this.agentArr = array;
      if(this.agentArr && this.agentArr.length == 1) {
        this.query.agent_id = this.agentArr[0].agent_id;
      }
    });
  }

  requestData() {
    this.pager.reload({ly_agent_id: this.query.agent_id, batch_id: this.query.batch_id});
  }

  detectConflict() {
    if(!this.query.agent_id) {
      this.MsgService.errorAlert('请选择考点');
      return;
    }
    if(!this.query.batch_id) {
      this.MsgService.errorAlert('请选择批次');
      return;
    }
    this.MsgService.confirmAlert('检测冲突，会扫描所有的编排数据，可能需要几分钟，请耐心等待。', () => {
      this.AjaxService.request('layout/appointment/conflict.htm', {ly_agent_id: this.query.agent_id, batch_id: this.query.batch_id}, () => {
        this.MsgService.successToastr('检测冲突完成！');
        this.pager.reload({ly_agent_id: this.query.agent_id, batch_id: this.query.batch_id});
      }, {RequestWithLoading: true});
    });
  }

  export() {
    this.FuncService.ajaxDownload('layout/appointment/conflict/export.htm', {ly_agent_id: this.query.agent_id, batch_id: this.query.batch_id});
  }

}
