import {Component, OnInit, ViewChild} from '@angular/core';
import {FramePageComponent} from "../../../frame/core/page/frame.page";
import {BsModalService} from "ngx-bootstrap/modal";
import { AjaxService } from '../../../../core/service/ajax.service';
import { MsgService } from '../../../../core/service/msg.service';
import { FramePager } from '../../../../core/frame/pager/frame-pager/frame-pager';
import { FinalProgressDetailComponent } from '../final-progress-detail/final-progress-detail.component';
import { timeStamp } from 'console';

@Component({
  selector: 'app-final-progress-page',
  templateUrl: './final-progress-page.component.html',
  styleUrls: ['./final-progress-page.component.scss']
})
export class FinalProgressPageComponent extends FramePageComponent implements OnInit {
  schoolArray = [];
  batchArray = [];
  totalMap = {"total_cnt":0, "done_cnt":0, "to_be_cnt":0};
  confirmArray = [];
  query = {
    school_id : '',
    batch_id : '',
    has_confirm: ''
  };
  constructor(private modalService: BsModalService) {
    super(modalService);
    this.modalComponent = FinalProgressDetailComponent;
  }

  ngOnInit() {
    this.confirmArray.push({"confirm_value": "是","confirm_text": "是"}, {"confirm_value": "否","confirm_text": "否"});
    this.AjaxService.requestArray('./cf/school/list.htm', {}, (array) => {
      this.schoolArray = array;
      if (this.schoolArray.length == 1) {
        this.query.school_id = this.schoolArray[0].school_id;
        this.queryBatchArray();
      } 
    });
    AjaxService.requestMap("final/review/progress/total.htm", {school_id: this.query.school_id, batch_id: this.query.batch_id}, (map)=>{
      //debugger;
      _this.totalMap = map;
    });
    let _this = this;
    setInterval(function() {
      _this.pager.reload();
      AjaxService.requestMap("final/review/progress/total.htm", {school_id: _this.query.school_id, batch_id: _this.query.batch_id}, (map)=>{
        //debugger;
        _this.totalMap = map;
      });
    }, 15 * 1000);
  }

  queryBatchArray() {
    //查询班级老师列表
    AjaxService.requestArray("cf/batch/list.htm",{school_id: this.query.school_id},(array)=>{
      this.batchArray = array;
      if (this.batchArray.length >= 1) {
        this.query.batch_id = this.batchArray[0].batch_id;
        this.requestData();
      }
    });   
  }

  requestData() {
    //debugger;
    this.pager.pagerParams["batch_id"] = this.query.batch_id;
    this.pager.reload();
  }

  //已评列表
  showDoneList(v) {
    v.query_type = "done";
    this.showComponentModal(FinalProgressDetailComponent, { 'ResponseEntity': v });
  }

  //未评列表
  showToBeList(v) {
    v.query_type = "un_done";
    this.showComponentModal(FinalProgressDetailComponent, { 'ResponseEntity': v });
  }

  exportProgress() {
    /*let entity = {
      school_id: this.query.school_id,
      batch_id: this.query.batch_id,
      report_name:'FinalProgressExport',
      report_title :'学术评审进度导出'
    };
    this.FuncService.ajaxDownload('frame/report/download.htm', entity);*/
    this.FuncService.ajaxDownload('final/review/progress/export.htm', 
      {school_id: this.query.school_id, batch_id: this.query.batch_id, has_confirm: this.query.has_confirm});
  }
}
