import { Component } from '@angular/core';
import { NavController} from 'ionic-angular';
import { Response } from '@angular/http';
import { AppService } from '../../../service/appHttpService';
import { ActivityTrackPage } from '../../activity-track/activityTrack/activityTrack';
import { ReportTrackPage } from '../../report/reportTrack/reportTrack';

import { ActivityStatisticService } from '../../../service/activityStatisticService';

import { Storage } from '@ionic/storage';

@Component({
  selector: 'page-workbench',
  templateUrl: 'workbench.html'
})
export class WorkbenchPage {

  activitycount:number = 0;
  reportCount:number = 0;

  role:any;

  constructor(
    public navCtrl: NavController,
    public activityStatisticService: ActivityStatisticService,
    public appService: AppService,
    public storage: Storage
  ) {
  
  }

  ionViewDidLoad(){
    //判断角色
    this.queryUserRole();
    //统计活动数目
    this.activityStatisticService.statisticActivityNum((data) => {
      this.activitycount = data; 
    });
    this.getReportCount();
  }

  //统计报备数目
  getReportCount(){
    this.appService.ObserverHttpPost("/wisdomgroup/modules/premanager/getReportCount", null)
    .subscribe((res: Response) => {
      let data = res.json();
      this.reportCount = data;
    }, error => {
      this.appService.alert('网络异常！');
    }
    );
  }

  goActivityTrack(){
    this.navCtrl.push("ActivityTrackPage");
  }

  goReportTrack(){
    this.navCtrl.push("ReportTrackPage");
  }

  //获取角色
  queryUserRole() {
    this.storage.get("userLoginInfo").then((data) => {
      this.appService.ObserverHttpGet("/wisdomgroup/sysmanagement/user/queryRoleByUserid", { userid: data.userid })
        .subscribe((res: Response) => {
          this.role = res.json();

          //this.storage.set("role",this.role);

        }, error => {
          this.appService.alert('网络异常！');
        }
        );
    });
  }
  


}