import {Component, OnInit} from '@angular/core';
import {StdRegCreateComponent} from '../std-reg-create/std-reg-create.component';
import {ActivatedRoute, Router} from '@angular/router';
import { StdRegCustomExportComponent } from '../std-reg-custom-export/std-reg-custom-export.component';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { MsgService } from '../../../../../core/service/msg.service';
import { FuncService } from '../../../../../core/service/func.service';
import { ModalService } from '../../../../../core/service/modal.service';

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

  aspectArray = []; //专业列表
  provinceArray = []; //省份列表
  varietyArray = [];
  std:any;


  constructor(private activateInfo: ActivatedRoute, private router: Router, private modalService: BsModalService) {
    super(modalService);
    this.modalComponent = StdRegCreateComponent;
  }

  ngOnInit() {
    this.std= {};
    AjaxService.requestArray('conf/aspect/all.htm', {}, (array) => {
      this.aspectArray = array;
    });
    AjaxService.requestArray('frame/region/province/list.htm', {}, (array) => {
      this.provinceArray = array;
      this.provinceArray.unshift({province_id: '', province_abbr: '全部'});
    });
  }

  showStdDetail(std) {
    this.router.navigate(['/art/std/reg/detail',std.std_id], );
  }

  validStdPhoto() {
    MsgService.confirmAlert('确定将所有免冠证件照进行公安验证码？需要消耗较长时间', () => {
      AjaxService.requestEntity('std/reg/NoCrownPhoto/verify.htm', {}, (entity) => {
        ModalService.showThreadWindow(this.modalService, entity, {threadTitle: '正在进行公安验证，请稍候'});
      });
    });
  }

  downloadStdEnrol(suffix: any) {
    let entity = {
      report_name:  suffix === 'xlxs' ? 'StdEnrolReport' : 'StdEnrolDbfReport',
      report_title :'报考数据上报国家库'
    };
    FuncService.ajaxDownload('frame/report/download.htm', entity);
  }

  showExportModal() {
    this.showComponentModal(StdRegCustomExportComponent);
  }

  requestStd() {
    this.pager.reload(this.std);
  }

  getVariety(aspect_id: any) {
    AjaxService.requestArray('conf/aspect/variety/list.htm', {aspect_id : aspect_id}, (array) => {
      this.varietyArray = array;
      //if(this.varietyArray.length == 0) {
        this.requestStd();
      //}
    });
  }

  //同步考生到UMP
  syncStdToUmp(std)  {
    MsgService.confirmAlert('确定要同步考生的报考信息到【在线考试系统】参加视频录制吗？', () => {
      AjaxService.request('enrol/upm/std.htm', {cert_id : std.cert_id}, () => {
        MsgService.successAlert('同步成功！');
      });
    });
  }

  //考生重置密码
  resetPasswd(v) {
    this.MsgService.confirmAlert('确定要重置考生的登录密码吗？重置后的密码默认为身份证后6位。', () => {
      this.AjaxService.request('std/reg/reset/passwd.htm', {std_id: v.std_id}, () => {
        this.MsgService.successToastr('重置成功！');
      }, {RequestWithLoading: true});
    });
  }
}
