 
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 '../../../..';
import { error } from 'util';
declare var $: any;

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

export class PayBillStatisSceneComponent extends FlexTableComponent implements OnInit {

  public query = {
    "exam_time_id": ""

  };


  QUERY_ALL_URL = "pay/payBillStatis/allListScene.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 = [];
    

    FrameRequest.requestArray(this.QUERY_ALL_URL, this.query, (array) => {
      this.enrolList = array;
     
    });
  }

  export(){
    if(!String(this.query.exam_time_id)){
      AppComponent.alert({title:"信息提示",text:"请选择批次!"});
      return;
  }
  
    FrameRequest.download("pay/payBillStatis/exportScene.htm",this.query);
  }

  downloadRefund(name){
    if(!String(this.query.exam_time_id)){
      AppComponent.alert({title:"信息提示",text:"请选择批次!"});
      return;
  }


  FrameRequest.request("pay/payBillStatis/checkDownloadRefund.htm", {exam_time_id:this.query.exam_time_id,name:name}, (ret)=>{
    
    if (ret.errorCode == 0) {
        FrameRequest.download("pay/payBillStatis/downloadRefund.htm", {exam_time_id:this.query.exam_time_id,name:name}, ()=>{
        AppComponent.GobalComponent.successMsg("下载成功");

        });
    }else{
      AppComponent.GobalComponent.errorMsg(ret.errorMsg);

    }
  });

    

  }

  
}
