import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { CookieService } from 'ngx-cookie-service';
import { AjaxService } from 'src/app/core/service/ajax.service';
import { FramePageComponent } from 'src/app/routes/frame/core/page/frame.page';
import { LayoutMaterialParamComponent } from '../layout-material-param/layout-material-param.component';

@Component({
  selector: 'app-layout-material-ticket-result',
  templateUrl: './layout-material-ticket-result.component.html',
  styleUrls: ['./layout-material-ticket-result.component.scss']
})
export class LayoutMaterialTicketResultComponent extends FramePageComponent implements OnInit {
  agent: any;
  batchArr = [];
  batch_id: any;

  constructor(private router: Router, private cookies: CookieService, modalService: BsModalService) {
    super(modalService);
    this.modalComponent = LayoutMaterialParamComponent;

    this.batchArr = this.FrameService.DictMap['ExamBatchName'];

    // 获取缓存中的考点编号
    let agent_id = this.cookies.get('CurrentAgentId');
    if (agent_id !== undefined && agent_id.length > 0) {
      // 去获取
      AjaxService.requestEntity('layout/agent/find.htm', { ly_agent_id: agent_id }, (entity) => {
        this.agent = entity;
        setTimeout(() => {
          if (this.pager) {
            this.pager.reload();
          }
        }, 1);
      });
    } else {
      this.router.navigate(['/art/layout/agent/page']);
    }
  }

  ngOnInit(): void {
  }

  downloadTicket(v) {
    window.open(this.FrameService.getParamValue('EnrolMaterialWebPath') + '/' + v.ticket_file_name);
  }

  reloadTicket() {
    this.pager.reload({ batch_id: this.batch_id });
  }

  // 获取准考证数据
  pullTicketData() {
    this.MsgService.confirmAlert('确定要获取准考证数据？', () => {
      // 确认
      this.AjaxService.request('ly/std/ticket/result/pull.htm', { ly_agent_id: this.agent.ly_agent_id, batch_id: this.batch_id }, () => {
        this.MsgService.successToastr('获取准考证数据完成！');
        this.reloadTicket();
      });
    });

  }

}
