import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { ExamVideoNoticeSendComponent } from '../exam-video-notice-send/exam-video-notice-send.component';
import {CookieService} from 'ngx-cookie-service';
import {Router} from '@angular/router';

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

  agentArray = [];
  ly_agent_id;
  wxDefine: any;


  constructor(private router: Router, private cookies: CookieService, private modalService: BsModalService) {
    super(modalService);

    // 获取缓存中的微信编号
    const wx_id = this.cookies.get('CurrentWxId');
    if (wx_id !== undefined && wx_id.length > 0) {
      // 去获取
      AjaxService.requestEntity('weixin/define/find.htm', {wx_id: wx_id}, (entity) => {
        this.wxDefine = entity;
        setTimeout(() => {
          if (this.pager) {
            this.pager.reload({wx_id: this.wxDefine.wx_id});
          }
        }, 1);
      });
    } else {
      this.router.navigate(['/weixin/define/page']);
    }
  }

  ngOnInit() {
    // 获取所有考点
    AjaxService.requestArray('exam/checkin/init/agent.htm', {}, (array) => {
      this.agentArray = array;
      if (this.agentArray.length === 1) {
        this.ly_agent_id = this.agentArray[0].ly_agent_id;
      }
    });
  }

  //发送消息框
  showSendMsg(std: any) {
    this.showComponentModal(ExamVideoNoticeSendComponent, {
      ResponseEntity: this.wxDefine,
      arrayUrl: 'weixin/template/all.htm',
      arrayParam: {wx_id: this.wxDefine.wx_id}
    });
  }


}