import {Component, OnInit, ViewChild} from '@angular/core';
import {AdmitWishConfirmComponent} from '../admit-wish-confirm/admit-wish-confirm.component';
import {AdmitProvinceScoreComponent} from '../admit-province-score/admit-province-score.component';
import {AdmitProvinceAspectComponent} from '../admit-province-aspect/admit-province-aspect.component';
import { BsModalService } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../core/service/ajax.service';
import { MsgService } from '../../../../core/service/msg.service';
import { FramePageComponent } from '../../../frame/core/page/frame.page';
import { ModalService } from '../../../../core/service/modal.service';

@Component({
  selector: 'app-admit-province',
  templateUrl: './admit-province.component.html',
  styleUrls: ['./admit-province.component.scss']
})
export class AdmitProvinceComponent extends FramePageComponent implements OnInit {

  // @ViewChild('uploader', {static: false}) uploader: UploaderComponent;

  constructor(private modalService: BsModalService) {
    super(modalService);
  }

  ngOnInit() {
  }

  // 上传志愿
  uploadWish(v) {
    // this.uploader.uploadUrl = './admit/province/wish/upload.htm';
    // this.uploader.uploadFiles({province_id: v.province_id});
  }

  // 确认志愿字段
  afterUpload($event) {
    this.pager.reload();
    this.showComponentModal(AdmitWishConfirmComponent, {
      'mapUrl': 'admit/province/wish/confirm/init.htm',
      'mapParam': {province_id: $event.entity}
    });
  }

  // 确认分数线
  confirmScore(v) {
    this.showComponentModal(AdmitProvinceScoreComponent, {
      'mapUrl': 'admit/province/score/init.htm',
      'mapParam': {province_id: v.province_id}
    });
  }

  // 上传专业代码
  uploadAspect(v) {
    this.showComponentModal(AdmitProvinceAspectComponent, {
      'mapUrl': 'admit/province/aspect/init.htm',
      'mapParam': {province_id: v.province_id}
    });

  }

  makeAllWish() {
    MsgService.confirmAlert('确定要合成所有省份的考生志愿吗？需要运行很长时间！', () => {
      AjaxService.request('admit/province/wish/make.htm', {}, (data) => {
        // this.showThreadRunning(data.entity);
        ModalService.showThreadWindow(this.bsService,data.entity);
      });
    });

  }

  admitAllWish() {
    MsgService.confirmAlert('确定要进行拟录取判断吗？需要运行很长时间！', () => {
      AjaxService.request('admit/wish/make.htm', {}, (data) => {
        // this.showThreadRunning(data.entity);
        ModalService.showThreadWindow(this.bsService,data.entity);
      }, {RequestWithLoading: true});
    });
  }

}
