import {Component, OnInit} from '@angular/core';
import {FrameDetailComponent} from "../../core/detail/frame.detail";
import {FormBuilder, Validators} from "@angular/forms";
import {AjaxService} from "../../../../core/service/ajax.service";
import {DomSanitizer} from "@angular/platform-browser";
import {FrameService} from "../../../../core/service/frame.service";
import {BsModalRef} from "ngx-bootstrap/modal";
import {FrameDeptDetailComponent} from "../../dept/frame-dept-detail/frame-dept-detail.component";
import {eNameValidator} from "../../../../shared/validators/ename.validator";
import {mobileValidator} from "../../../../shared/validators/mobile.validator";
import {passswordValidator} from "../../../../shared/validators/password.validator";

@Component({
  selector: 'app-frame-optr-create',
  templateUrl: './frame-optr-create.component.html',
  styleUrls: ['./frame-optr-create.component.scss']
})
export class FrameOptrCreateComponent extends FrameDetailComponent implements OnInit {

  deptArray = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'login_name': [null, Validators.compose([eNameValidator, Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      'optr_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(32)])],
      'optr_sex': [null],
      'optr_status': [null],
      'optr_email': [null],
      'optr_mobile': [null, Validators.compose([mobileValidator])],
      'optr_tel': [null],
      'optr_fax': [null],
      'optr_addr': [null],
      'optr_post': [null],
      'optr_dept': [null],
      'optr_desc': [null],
      'passwordGroup': fb.group({
        'password': [null, Validators.compose([Validators.required, Validators.minLength(6)])],
        'pconfirm': [null, Validators.compose([Validators.required, Validators.minLength(6)])]
      }, {validator: passswordValidator})
    });
  }

  ngOnInit() {
    setTimeout(() => {
      // 设置默认值
      this.currentEntity = {optr_status: 'Active', optr_sex: '男', optr_dept: FrameService.FrameOptr.optr_dept}
      AjaxService.requestArray('frame/dept/all.htm', {}, (ResponseArray) => {
        this.deptArray = FrameDeptDetailComponent.makeOptrDeptArray(ResponseArray);
      });
    }, 10);
  }


}
