import { FlexTableComponent } from '../../../../../shared/common/FlexTable.component';
import { Component, OnInit, ViewChild } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal/bs-modal.service';
import { FrameRequest } from '../../../../../shared/frame/frame-request';
import 'ztree';
import * as _ from 'lodash';
import { Validators, FormBuilder } from '@angular/forms';
import { CustomValidators } from 'ng2-validation';
import { AppComponent } from '../../../../../app.component';
declare var $: any;

@Component({
  selector: 'app-kw-sum-bag',
  templateUrl: './kw-sum-bag.component.html',
  styleUrls: ['./kw-sum-bag.component.scss']
})

export class KwSumBagComponent extends FlexTableComponent implements OnInit {

  public query = {
    "exam_time_id": "",
    "exam_agent_id": "",
    "course_code": "",
    "is_net_mark": "",
    "exam_area_id": "",
    "isAreaAllExp": ""
  };

  //TODO
  QUERY_URL = "kw/kwLayoutCourseBagSum/page.htm";
  DELETE_URL = "kw/kwLayoutCourseBagSum/delete.htm";
  GET_URL = "kw/kwLayoutCourseBagSum/get.htm";
  ADD_URL = "kw/kwLayoutCourseBagSum/add.htm";
  EDIT_URL = "kw/kwLayoutCourseBagSum/edit.htm";

  EXAM_AREA_URL = "cf/cfOrganization/list.htm";

  agentArray = [];
  examTimeIdArray = [];
  examAreaArray = [];
  curOrg = {id:"",org_code:"",org_name:"",contact_number:"",org_type:""};//当前登录人的机构

  constructor(
    public bsModalService: BsModalService,
    fb: FormBuilder
  ) {
    super();
    this.formModel = fb.group({
      id: [null],
    });

    FrameRequest.requestArray('pl/plExamTime/listtime.htm', {}, (array) => {
      this.examTimeIdArray = array;
    });
    
    FrameRequest.requestMap('pl/kwLayoutCourseBagSum/basedata.htm', (map)=>{
      this.curOrg = map.curOrg;
      
      this.examTimeIdArray = map.examTimeList;
    });

    FrameRequest.requestArray(this.EXAM_AREA_URL, {org_type: 4,status:1}, (array) => {
      this.examAreaArray = array;
    });
  }

  changePoint(){
    
    if(this.query.exam_time_id){
      if(!this.query.exam_area_id){
        this.query.exam_area_id="";
      }
      
     
      FrameRequest.requestArray('kw/kwExamPoint/listpoint.htm', {exam_time_id:this.query.exam_time_id,org_id:this.query.exam_area_id}, (array) => {
        this.agentArray = array;
        this.query.exam_agent_id = "";
      });
    }
  }

  exportPdf(){
    if(!String(this.query.exam_time_id)){
      AppComponent.alert({text:"请选择考试批次!"})
      return;
    }
    FrameRequest.download("kw/kwLayoutCourseBagSum/exportPdf.htm",this.query);
  }

  exportExcel(){
    if(!String(this.query.exam_time_id)){
      AppComponent.alert({text:"请选择考试批次!"})
      return;
    }
    FrameRequest.download("kw/kwLayoutCourseBagSum/exportExcel.htm",this.query);
  }
}
