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 { FuncService } from '../../../../core/service/func.service';
import { MsgService } from '../../../../core/service/msg.service';

declare let laydate;

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

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'school_id': [null,Validators.compose([Validators.required])],
      'category_name': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(64)])],
      'category_desc': [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(255)])],
      'ord': [null,Validators.compose([Validators.required])]
    });
    this.getDate();
  }

  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() {
    if (this.detailMode === 'add') {
      this.currentEntity.need_face_match = 'Active';
    }
  }

  //初始化时间控件
  getDate() {
    let _this = this;
    setTimeout(() => {
      laydate.render({
        elem:'#startDate',
        type:'date',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd',
        trigger: 'click',
        done:(value, date, startDate)=>{
          _this.currentEntity.start_date = value;
        }
      });
      laydate.render({
        elem:'#endDate',
        type:'date',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd',
        trigger: 'click',
        done:(value, date, endDate)=>{
          _this.currentEntity.end_date = value;
        }
      });        
    }, 500);
  }

}
