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

@Component({
  selector: 'app-pay-bill-statis-fac',
  templateUrl: './pay-bill-statis-fac.html',
  styleUrls: ['./pay-bill-statis-fac.scss']
})

export class PayBillStatisFacComponent extends FlexTableComponent implements OnInit {

  public query = {
    "exam_time_id": "",
    "exam_agent_id": "",
    "data_type": "",
    "enrolType":""

  };


  QUERY_ALL_URL = "pay/payBillStatis/allListFac.htm";
  DELETE_URL = "";
  GET_URL = "";
  ADD_URL = "";
  EDIT_URL =  "";

  agentArray = []
  examTimeIdArray = []

  enrolList = []
  practiceList = []
  paperlList = []

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

    FrameRequest.requestArray('cf/cfOrganization/list.htm', {org_type:4,status:1}, (array) => {
      this.agentArray = array;
    });

    FrameRequest.requestArray('pl/plExamTime/listtime.htm', {}, (array) => {
      this.examTimeIdArray = array;

      // if(this.examTimeIdArray.length > 0){
      //   this.query.exam_time_id = this.examTimeIdArray[0].id;

      // }
    });

   
    /*
    FrameRequest.requestMap(this.QUERY_ALL_URL, this.query, (map) => {
      this.enrolList = map.enrolList?map.enrolList:[];
      this.practiceList = map.practiceList;
      this.paperlList = map.paperlList?map.paperlList:[];
      });
    */
    
  }

  queryAllList(){
    if(!String(this.query.exam_time_id)){
        AppComponent.alert({title:"信息提示",text:"请选择批次!"});
        return;
    }
    this.enrolList = [];
    this.practiceList = [];
    this.paperlList = [];

    FrameRequest.requestEntity(this.QUERY_ALL_URL, this.query, (entity) => {
      this.enrolList = entity.enrolList;
      this.practiceList = entity.practiceList;
      this.paperlList = entity.paperlList;
    });
  }

  exportPdf(){
    FrameRequest.download("pay/payBillStatis/exportPdfFac.htm",this.query);
  }

  enrolRowspan(enrolList,item,index){
    if(!enrolList || enrolList.length  == 0) return 1;
    if(parseInt(item.f6)>1){
      return item.f6;
    }else{
      return 1;
    }
  }
}
