import {Component, OnInit, ViewChild} from '@angular/core';
import {Router} from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import {CookieService} from 'ngx-cookie-service';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { FrameService } from '../../../../../core/service/frame.service';
import { ModalService } from '../../../../../core/service/modal.service';
import {LayoutMaterialParamComponent} from '../layout-material-param/layout-material-param.component';
import {LayoutMaterialWrittenSeatComponent} from '../layout-material-written-seat/layout-material-written-seat.component';

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

  agent: any;
  batchNameArray: any;
  openThreadRunningWindow:any;
  searchText:any;
  exam_batch:any;
  // 分页组件
  // @ViewChild('uploader', {static: false}) uploader: UploaderComponent;

  constructor(private router: Router, private cookies: CookieService, modalService: BsModalService) {
    super(modalService);
    this.modalComponent = LayoutMaterialParamComponent;
    // 获取缓存中的微信编号
    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.ajax) {
            this.ajax.reload();
          }
        }, 1);
      });
      const array = [{dict_value: '0', dict_text: '全批次'}];
      for (const v of FrameService.getFrameDictArray('ExamBatchName')) {
        array.push(v);
      }
      this.batchNameArray = array;
    } else {
      this.router.navigate(['/art/layout/agent/page']);
    }
  }

  showMaterialParam(group, params, subject?: any) {
    this.showModal(Object.assign({}, group, params, subject));
  }

  showRoomSeat(group) {
    this.showComponentModal(LayoutMaterialWrittenSeatComponent, {ResponseEntity:group});
  }

  goThreadDownload(url,param?) {
      // 线程模式
      AjaxService.requestEntity(url, param, (entity) => {
        ModalService.showThreadWindow(this.bsService, entity, {threadTitle: '正在整理数据，请稍候'});
      }, {RequestWithLoading: true});
  }

  ngOnInit() {

  }

  downloadSeat(ly_group_id) {
    AjaxService.requestEntity('layout/material/written/seatWithImage.htm', {ly_group_id: ly_group_id}, (entity) => {
      ModalService.showThreadWindow(this.bsService, entity, {threadTitle: '正在整理数据，请稍候'});
    });
  }


}
