import { Component, OnInit } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { FuncService } from '../../../../../core/service/func.service';

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

  agent: any;
  categoryArray =[];
  dateArray = [];
  category_id: any;
  exam_date: any;

  constructor(private router: Router,private modalService: BsModalService, private cookies: CookieService) {
    super(modalService);
    // 获取缓存中的考点编号
    const 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;
        AjaxService.requestArray('exam/judge/extract/date/list.htm', {ly_agent_id: agent_id}, (array) => {
          this.dateArray = array;
        });
      });
    } else {
      this.router.navigate(['/art/layout/agent/page']);
    }
   }

  ngOnInit() {
    AjaxService.requestArray('conf/category/all.htm', {}, (array) => {
      if(array && array.length > 0) {
        array.unshift({category_name: '全部'});
      }
      this.categoryArray = array;
    });
  }


  initDefautEntity() {

  }



  changCategoryDate() {
    this.pager.reload({category_id: this.category_id, exam_date: this.exam_date});
  }

  /***********************
   * 导出编排结果
   */ 
 export() {
   FuncService.ajaxDownload('layout/material/search/export.htm', {
     ly_agent_id: this.agent.ly_agent_id,
     category_id: this.category_id === undefined ? "" : this.category_id,
     exam_date: this.exam_date === undefined ? "" : this.exam_date
   });
 }

}
