import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
import { FormBuilder, Validators } from '@angular/forms';
import { CustomValidators } from 'ng2-validation';
import { BsModalService } from "ngx-bootstrap/modal";
import { FlexTableComponent } from "../../../../shared/common/FlexTable.component";
import { AppComponent } from "../../../../app.component";
import { FrameRequest } from "../../../../shared/frame/frame-request";
import { FramePagerComponent } from "../../../../core/pager/pager.component";
import { FrameValidator } from "../../../../shared/frame/Frame-validator";
import { FlexSelectComponent } from "../../../../shared/components/flexSelect/FlexSelect.component";

@Component({
  selector: "app-kw-checkitem",
  templateUrl: "./checkitem.component.html",
  styleUrls: ["./checkitem.component.scss"]
})
export class CheckItemComponent extends FlexTableComponent
  implements OnInit {

  public query = {
    type: "",
    id: "",
    exam_time_id: ""
  };



  QUERY_URL = "kw/kwCheckItem/page.htm";
  EXPORT_URL = "kw/kwCheckItem/export.htm";
  itemList=[];
  typeList=[];
  fields=[];
  alias=[];

  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) {
    super();
  }

  ngOnInit() {
	
    FrameRequest.requestArray("kw/kwCheckItem/initdata.htm", {}, (array)=>{
		this.typeList = array;
    });
  }

  //分页查询条件
   search(param) {
    if (!this.query.exam_time_id) {
		AppComponent.alert({ title: "信息提示", text: "请选择年度码!" });
		return false;
	}
	if (!this.query.type) {
		AppComponent.alert({ title: "信息提示", text: "请选择业务类型!" });
		return false;
	}
	if (!this.query.id) {
		AppComponent.alert({ title: "信息提示", text: "请选择校验项!" });
		return false;
	}

	param.id = this.query.id;
  param.exam_time_id = this.query.exam_time_id;

  }

  export(){
	if (!this.query.exam_time_id) {
		AppComponent.alert({ title: "信息提示", text: "请选择年度码!" });
		return ;
	}
	if (!this.query.type) {
		AppComponent.alert({ title: "信息提示", text: "请选择业务类型!" });
		return ;
	}
	if (!this.query.id) {
		AppComponent.alert({ title: "信息提示", text: "请选择校验项!" });
		return ;
	}
	let param = {
		id: this.query.id,
		exam_time_id:this.query.exam_time_id
	  }
	  AppComponent.GobalComponent.setLoading(true);
	  FrameRequest.download(this.EXPORT_URL, param, () => {
		AppComponent.GobalComponent.setLoading(false);
		AppComponent.GobalComponent.successMsg("导出成功");
	  });
  }

  typeChange(type_arg){
	if (!type_arg) {
		return ;
	  }
	  let param = {
		type: type_arg
	  }
	  FrameRequest.requestArray("kw/kwCheckItem/itemlist.htm", param, (array)=>{
		  this.itemList = array;
	  });
  }

  itemChange(id){
	if (!id) {
		return ;
	}
	FrameRequest.requestMap("kw/kwCheckItem/header.htm", {id:id},(map)=>{
		this.fields = map.fields;
		this.alias = map.alias;
		this.framePager.records=[];
    });
  }

}