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 { FrameUploaderComponent } from '../../../../core/uploader/uploader.component';
import { FrameRequest } from "../../../../shared/frame/frame-request";
import { FramePagerComponent } from "../../../../core/pager/pager.component";
import { FrameFunction } from "../../../../shared/frame/frame_function";
import * as _ from 'lodash';

@Component({
  selector: "app-pl-inputscore",
  templateUrl: "./inputscore.component.html",
  styleUrls: ["./inputscore.component.scss"]
})
export class InputScoreComponent extends FlexTableComponent implements OnInit {
  
  public queryDetail = {
    is_curr:"",
    query: "",
    year_code: ""

  }

  @ViewChild('uploader')
  uploader: FrameUploaderComponent;
  @ViewChild('detailPager')
  detailPager:FramePagerComponent;

  filePath : String;
  yearCodeList = [];


  QUERY_DETAIL_URL = "kj/kjCollegeScoreDetail/queryInputScore.htm";
  
   // 导出
   EXPORT_URL= "kj/kjCollegeScoreMain/exportInputScore.htm";  


  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) {
    super();
    // CustomValidators.rangeLength([1, 6])
    this.formModel = fb.group({
      id: [null],
      'year_code' : [null, Validators.compose([Validators.required])]
    });
  }

  ngOnInit() {
    let this_ = this;
    this.queryDetail.is_curr="1";

    setTimeout(() => {
        FrameRequest.requestMap("kj/kjCollegeScoreMain/initdata.htm", {}, (map)=>{
            this_.yearCodeList = map["yearCodeList"];
            if (map["year_code"]) {
                this_.queryDetail.year_code = map["year_code"];
                this_.detailPager.reload();
            }
        });
    }, 1000);
  }

  searchDetail(paramDetail) {
  
    if (!this.queryDetail.year_code) {
      this.queryDetail.year_code = "";
    }

    if (!this.queryDetail.is_curr) {
      this.queryDetail.is_curr = "";
    }
    

    paramDetail.query = this.queryDetail.query;
    paramDetail.yearCode = this.queryDetail.year_code;
    paramDetail.is_curr = this.queryDetail.is_curr;
  }



  //重置
  reset() {
   
    this.queryDetail.year_code = "";
    this.queryDetail.is_curr = "1";
    this.queryDetail.query = "";
  }

  //导出
  exportScore() {
    if (!this.queryDetail.year_code) {
      AppComponent.alert({ title: "信息提示", text: "请选择年度码!" });
      return true;
    }

   
    if (!this.queryDetail.year_code) {
      this.queryDetail.year_code = "";
    }

    if (!this.queryDetail.is_curr) {
      this.queryDetail.is_curr = "";
    }
   

    
    AppComponent.GobalComponent.setLoading(true);
    FrameRequest.download(this.EXPORT_URL, {
      yearCode : this.queryDetail.year_code,
      query:this.queryDetail.query,
      is_curr:this.queryDetail.is_curr
    }, () => {
      AppComponent.GobalComponent.setLoading(false);
      AppComponent.GobalComponent.successMsg("非网评登分成绩导出成功");
    });
  }

   
}