import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {FrameRequest} from "../../../../../shared/frame/frame-request";
import {FrameFunction} from "../../../../../shared/frame/frame_function";
import {AppComponent} from "../../../../../app.component";

@Component({
  selector: 'app-std-score-review-time',
  templateUrl: './std-score-review-time.component.html',
  styleUrls: ['./std-score-review-time.component.scss']
})
export class StdScoreReviewTimeComponent implements OnInit {


  formModel: FormGroup;
  examtimeList = [];
  item: any;
  operTypeList = [];//业务类型

  TIME_URL = "pl/plExamTime/listtime.htm";
  EDIT_URL = "cf/cfOperateTime/edit.htm";
  ADD_URL = "cf/cfOperateTime/add.htm";
  GET_URL = "cf/cfOperateTime/get.htm";

  constructor(fb: FormBuilder) {
    this.item = {};
    this.formModel = fb.group({
      // oper_type: [null, Validators.compose([Validators.required])],
      exam_time_id: [null, Validators.compose([Validators.required])],
      start_time: [null, Validators.compose([Validators.required])],
      end_time: [null, Validators.compose([Validators.required])],
      // batch_name: [null, Validators.compose([Validators.required])],
      // remark: [null,],
    });
  }

  ngOnInit() {
    //考试日期
    FrameRequest.requestArray(this.TIME_URL, {}, (arrary) => {
      this.examtimeList = arrary;
    });
    //构造业务类型下拉框---参照CfConst.java常量类
    this.item.oper_type='26';

  }

  freshData(oper_type, exam_time_id) {
    if (!oper_type || !exam_time_id) {
      return;
    }
    FrameRequest.requestEntity(this.GET_URL, {oper_type: oper_type, exam_time_id: exam_time_id},
      (entity) => {
    	  debugger
        if (entity) {
          this.item = entity;
        } else {
          this.item = {};
          this.item.oper_type = oper_type;
          this.item.exam_time_id = exam_time_id;
        }
      });
    // FrameRequest.requestEntity(this.GET_URL, {oper_type: oper_type, exam_time_id: exam_time_id},
    //   (map) => {
    //     debugger
    //     if (map&&map.item) {
    //       this.item = map.item;
    //     } else {
    //       this.item = {};
    //       this.item.oper_type = oper_type;
    //       this.item.exam_time_id = exam_time_id;
    //     }
    //     if (map&&map.batch_name) {
    //       this.item.batch_name = map.batch_name;
    //     }
    //     if (map&&map.remark) {
    //       this.item.remark = map.remark;
    //     }
    //   });
  }

  /**
   */
  save() {

    if (!FrameFunction.validForm(this.formModel)) {
      return;
    }
    if (this.item.id) {
      FrameRequest.request(this.EDIT_URL, this.item, () => {
        AppComponent.GobalComponent.successMsg('上报时间设置成功');
      });
    } else {
      FrameRequest.request(this.ADD_URL, this.item, () => {
        AppComponent.GobalComponent.successMsg('上报时间设置成功!');
      });
    }



  }

}
