import { Component, OnInit } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../core/service/ajax.service';
import { MsgService } from '../../../../core/service/msg.service';
import { FrameDetailComponent } from '../../../frame/core/detail/frame.detail';

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

  AspectArray = [];

  constructor(bsModalRef: BsModalRef) {
    super(bsModalRef);
  }

  ngOnInit() {
  }

  afterUpload($event) {
    AjaxService.requestMap('admit/province/aspect/init.htm', {province_id: this.ResponseMap.AmProvince.province_id}, (map) => {
      this.ResponseMap = map;
    });
  }

  saveAspect() {
    for (const s of this.ResponseMap.AspectArray) {
      if (!s.province_aspect_code || s.province_aspect_code.length === 0) {
        MsgService.errorToastr(`请输入【${s.aspect_full_name}】的专业代码`);
        break;
      }
    }

    const fn = () => {
      AjaxService.request('admit/province/aspect/save.htm', {
        aspect_json: JSON.stringify(this.ResponseMap.AspectArray),
        province_id: this.ResponseMap.AmProvince.province_id
      }, () => {
        this.closeWindow();
        MsgService.successAlert(`${this.ResponseMap.AmProvince.province_name} 专业代码保存成功！`);
      }, { RequestWithLoading: true });
    };
    MsgService.confirmAlert('请仔细核对文化线，确定要保存吗？', fn);
  }

}
