import {Component, OnInit} from '@angular/core';
import {FrameDetailComponent} from "../../core/detail/frame.detail";
import {BsModalRef, BsModalService} from "ngx-bootstrap/modal";
import {FormBuilder, Validators} from "@angular/forms";
import {mobileValidator} from "../../../../shared/validators/mobile.validator";
import {FrameService} from "../../../../core/service/frame.service";
import {MsgService} from "../../../../core/service/msg.service";
import {FrameOptrPasswordComponent} from "../frame-optr-password/frame-optr-password.component";

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

  constructor(modalService: BsModalService, bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'optr_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(32)])],
      'optr_sex': [null],
      'optr_email': [null],
      'optr_mobile': [null, Validators.compose([mobileValidator])],
      'optr_tel': [null],
      'optr_fax': [null],
      'optr_addr': [null],
      'optr_post': [null],
      'optr_desc': [null]
    });
  }

  ngOnInit() {
    this.currentEntity = Object.assign({}, FrameService.FrameOptr);
    this.currentEntity.optr_image = undefined;
    this.currentEntity.dept_name = FrameService.FrameDept.dept_name;
    this.currentEntity.resMap = undefined;
  }

  modifyOptr() {
    this.submitForm('frame/optr/edit.htm', {successMsg: '操作员信息已修改!'}, () => {
      MsgService.successAlert('操作员信息已完善，系统将重新加载！', () => {
        location.reload();
      });
    });
  }

}
