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 {FrameUpload} from "../../../../../core/frame/upload/frame-upload/frame-upload";
import { AjaxService } from '../../../../../core/service/ajax.service';
import { MsgService } from '../../../../../core/service/msg.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import {ExamJudgeDetailComponent} from '../exam-judge-detail/exam-judge-detail.component';

@Component({
  selector: 'app-exam-judge-page',
  templateUrl: './exam-judge-page.component.html',
  styleUrls: ['./exam-judge-page.component.scss']
})
export class ExamJudgePageComponent extends FramePageComponent implements OnInit {

  FrameUpload = FrameUpload;
  agent: any;
  // 分页组件
 // @ViewChild('uploader', {static: false}) uploader: UploaderComponent;

  constructor(private router: Router, private cookies: CookieService, modalService: BsModalService) {
    super(modalService);
    this.modalComponent = ExamJudgeDetailComponent;//ExamJudgeRuleDetailComponent;
    // 获取缓存中的微信编号
    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;
        setTimeout(() => {
          if (this.ajax) {
            this.ajax.reload();
          }
        }, 1);
      });
    } else {
      this.router.navigate(['/art/layout/agent/page']);
    }
  }

  ngOnInit() {

  }

  afterUpload($event) {
    MsgService.successToastr('导入成功！');
    this.pager.reload({y_agent_id: this.agent.ly_agent_id});
  }

  uploadCallback(ajax) {
    MsgService.successAlert('导入成功！!');
  }

}
