import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import { BsModalService } from 'ngx-bootstrap/modal';
import { FrameAjax } from '../../../../../core/frame/ajax/frame-ajax/frame-ajax';
import { AjaxService } from '../../../../../core/service/ajax.service';
import { FramePageComponent } from '../../../../frame/core/page/frame.page';
import { FramePager } from '../../../../../core/frame/pager/frame-pager/frame-pager';

@Component({
  selector: 'app-enrol-works-page',
  templateUrl: './enrol-works-page.component.html',
  styleUrls: ['./enrol-works-page.component.scss']
})
export class EnrolWorksPageComponent extends FramePageComponent implements OnInit {
  agent_id: 0;
  agent: any;
  agentArray = [];
  query = {agent_id:"",query:""};

  constructor(private activateInfo: ActivatedRoute, private router: Router, private modalService: BsModalService) {
    super(modalService);
    let agentTotal = 0;
    AjaxService.requestArray('conf/agent/all.htm', {}, (array) => {
      this.agentArray = array;
      if (this.agentArray.length >= 1) {
        this.query.agent_id = this.agentArray[0].agent_id;
      }
      setTimeout(() => {
        this.rquestQuery();
      }, 500);
    });
  }

  ngOnInit() {

  }

  rquestQuery() {
    debugger;
    this.pager.pagerParams["agent_id"] = this.query.agent_id;
    this.pager.reload();
  }

  //格式化文件名称
  formatFileName(path) {
    if (!path) {
      return "";
    }
    var pos = path.lastIndexOf("/");
    return path.substring(pos+1, path.length);
  }
  
  formatFileSize(size) {
    if (!size) {
      return "";
    }
    var s = parseFloat(size)/(1024 * 1024);
    return s.toFixed(2) + "M";
  }

}
