import {Component, OnInit} from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import {BsModalRef} from 'ngx-bootstrap/modal';
import {FrameDetailComponent} from '../../../frame/core/detail/frame.detail';
import {AjaxService} from '../../../../core/service/ajax.service';
import {FrameDictPipe} from "../../../../shared/pipes/frame.dict";
import {FrameService} from "../../../../core/service/frame.service";


@Component({
  selector: 'app-cf-initial-optr-detail',
  templateUrl: './initial-optr-detail.component.html',
  styleUrls: ['./initial-optr-detail.component.scss']
})
export class CfInitialOptrDetailComponent extends FrameDetailComponent implements OnInit {
  schoolArray = [];


  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);

    this.detailForm = fb.group({
      'school_id': [null, Validators.compose([Validators.required])],
      'std_edu': [null, Validators.compose([Validators.required])],
      'std_edu_name': [null, Validators.compose([Validators.required])]
    });
  }

  ngOnInit() {
    AjaxService.requestArray("cf/school/list.htm", {}, (array) => {
      this.schoolArray = array;
      if (this.schoolArray.length == 1) {
        this.currentEntity.school_id = this.schoolArray[0].school_id;
      }
    });
  }

  initDefautEntity() {
    debugger
    this.currentEntity.std_edu_name=new FrameDictPipe().transform( this.currentEntity.std_edu,'StdEduType');
  }

  reloadDict() {
      AjaxService.request('cf/initial/optr/frame/dict/reload.htm', {}, () => {
       // MsgService.successAlert(`字典加载成功，后台字典已经生效，前端字典需重新登录！`);
        //缓存数据加载
        AjaxService.requestMap('frame/optr/init.htm',{},(map)=>{
          FrameService.LoginInitMap = map;
          // 系统字典
          debugger
          FrameService.DictMap = {};
          for (const v of map['FrameDictArray']) {
            if (!FrameService.DictMap[v['dict_name']]) {
              FrameService.DictMap[v['dict_name']] = [];
            }
            FrameService.DictMap[v['dict_name']].push(v);
          }
        }, {RequestWithLoading: true})

      }, {RequestWithLoading: true});
  }

}
