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-batch-detail',
  templateUrl: './batch-detail.component.html',
  styleUrls: ['./batch-detail.component.scss']
})
export class CfBatchDetailComponent extends FrameDetailComponent implements OnInit {
  schoolArray = [];
  patternArray = [];

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      school_id: [null, Validators.compose([Validators.required])],
      batch_name: [null, Validators.compose([Validators.required, Validators.minLength(2), Validators.maxLength(64)])],
      upload_start_time: [null,Validators.compose([Validators.required])],
      upload_end_time: [null,Validators.compose([Validators.required])],
      scond_upload_start: [null,Validators.compose([Validators.required])],
      scond_upload_end: [null,Validators.compose([Validators.required])],
      intial_review_start: [null,Validators.compose([Validators.required])],
      intial_review_end: [null,Validators.compose([Validators.required])],
      intial_show_start: [null,Validators.compose([Validators.required])],
      intial_show_end: [null,Validators.compose([Validators.required])],
      profes_review_start: [null,Validators.compose([Validators.required])],
      profes_review_end: [null,Validators.compose([Validators.required])],
      profes_publish_start: [null,Validators.compose([Validators.required])],
      profes_publish_end: [null,Validators.compose([Validators.required])],
      ticket_start_time: [null,Validators.compose([Validators.required])],
      ticket_end_time: [null,Validators.compose([Validators.required])],
      score_public_start: [null,Validators.compose([Validators.required])],
      score_public_end: [null,Validators.compose([Validators.required])],
      pattern_id: [null, Validators.compose([Validators.required])],
      status: [null, Validators.compose([Validators.required])],
      profes_show_start: [null,Validators.compose([Validators.required])],
      profes_show_end: [null, Validators.compose([Validators.required])],
      score_check_start: [null,Validators.compose([Validators.required])],
      score_check_end: [null,Validators.compose([Validators.required])],
      score_check_public_start: [null,Validators.compose([Validators.required])],
      score_check_public_end: [null,Validators.compose([Validators.required])],
      show_upload_start: [null,Validators.compose([Validators.required])],
      show_upload_end: [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;
      }
    });
    AjaxService.requestArray('cf/pattern/list.htm',{},(array)=>{
      this.patternArray = array;
    });
  }

  initDefautEntity() {
    if (this.detailMode === 'add') {

    } else {
      this.currentEntity.status = this.currentEntity.status + '';
    }
  }

  // 初始化时间控件
  getDate() {
    const _this = this;
    setTimeout(() => {
      laydate.render({
        elem:'#upload_start_time',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, upload_start_time)=>{
          _this.currentEntity.upload_start_time = value;
        }
      });
      laydate.render({
        elem:'#upload_end_time',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, upload_end_time)=>{
          _this.currentEntity.upload_end_time = value;
        }
      });
      laydate.render({
        elem:'#scond_upload_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, scond_upload_start)=>{
          _this.currentEntity.scond_upload_start = value;
        }
      });
      laydate.render({
        elem:'#scond_upload_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, scond_upload_end)=>{
          _this.currentEntity.scond_upload_end = value;
        }
      });
      laydate.render({
        elem:'#intial_review_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, intial_review_start)=>{
          _this.currentEntity.intial_review_start = value;
        }
      });
      laydate.render({
        elem:'#intial_review_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, intial_review_end)=>{
          _this.currentEntity.intial_review_end = value;
        }
      });
      laydate.render({
        elem:'#intial_show_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, intial_show_start)=>{
          _this.currentEntity.intial_show_start = value;
        }
      });
      laydate.render({
        elem:'#intial_show_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, intial_show_end)=>{
          _this.currentEntity.intial_show_end = value;
        }
      });
      laydate.render({
        elem:'#profes_review_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_review_start)=>{
          _this.currentEntity.profes_review_start = value;
        }
      });
      laydate.render({
        elem:'#profes_review_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_review_end)=>{
          _this.currentEntity.profes_review_end = value;
        }
      });
      laydate.render({
        elem:'#profes_publish_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_publish_start)=>{
          _this.currentEntity.profes_publish_start = value;
        }
      });
      laydate.render({
        elem:'#profes_publish_end',
        type:'date',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_publish_end)=>{
          _this.currentEntity.profes_publish_end = value;
        }
      });
      laydate.render({
        elem:'#ticket_start_time',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, ticket_start_time)=>{
          _this.currentEntity.ticket_start_time = value;
        }
      });
      laydate.render({
        elem:'#ticket_end_time',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, ticket_end_time)=>{
          _this.currentEntity.ticket_end_time = value;
        }
      });
      laydate.render({
        elem:'#score_public_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, score_public_start)=>{
          _this.currentEntity.score_public_start = value;
        }
      });
      laydate.render({
        elem:'#score_public_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, score_public_end)=>{
          _this.currentEntity.score_public_end = value;
        }
      });
      laydate.render({
        elem:'#profes_show_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_show_start)=>{
          _this.currentEntity.profes_show_start = value;
        }
      });
      laydate.render({
        elem:'#profes_show_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_show_end)=>{
          _this.currentEntity.profes_show_end = value;
        }
      });
      laydate.render({
        elem:'#show_upload_start',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_show_start)=>{
          _this.currentEntity.show_upload_start = value;
        }
      });
      laydate.render({
        elem:'#show_upload_end',
        type:'datetime',
        theme:'#0c6acf',
        format: 'yyyy-MM-dd HH:mm:ss',
        trigger: 'click',
        done:(value, date, profes_show_end)=>{
          _this.currentEntity.show_upload_end = value;
        }
      });
    }, 500);
  }


}
