import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from "@angular/router";
import { MyService } from '../my.service';
import { LifeCommonService } from '../../common/life-common.service';

@Component({
  selector: 'ydlife-team-sales-score',
  templateUrl: './team-sales-score.component.html',
  styleUrls: ['./team-sales-score.component.scss']
})
export class TeamSalesScoreComponent implements OnInit {
  showType: any;
  practitionerId: any;
  subordinateSystemName: any;
  playerSalesActivityInfo: Array<any>;
  selectedSalseItem: any;
  salesPerformanceForecastInfos: Array<any>;
  personalList:Array<any>;
  constructor(private activateRoute: ActivatedRoute, private router: Router,
    private myService: MyService, public lifeCommonService: LifeCommonService) { }

  ngOnInit() {
    this.practitionerId = JSON.parse(localStorage.getItem('lifeCustomerInfo'))['practitionerId'];
    this.subordinateSystemName = sessionStorage.getItem('subordinateSystemName');
    //判断显示销售得分还是销售预测
    this.showType = this.activateRoute.snapshot.paramMap.get('type');
    if (this.showType === 'teamSalesScore') {
      this.queryPEPScore();
    }
    if (this.showType === 'forecast') {
      this.salesPerformanceForecastListQuery('m')
    }
  }

  //获取成员销售活动量得分
  // playerSalesActivityQuery() {
  //   this.myService.playerSalesActivityQuery({ practitionerId: this.practitionerId }).subscribe((res) => {
  //     if (res['success']) {
  //       this.playerSalesActivityInfo = res['data']['playerSalesActivityInfo']
  //     }
  //   })
  // }

  salesPerformanceForecastListQuery(type) {
    this.selectedSalseItem = type;
    const param = {
      practitionerId: this.practitionerId,
      time: type
    }
    this.myService.salesPerformanceForecastListQuery(param).subscribe((res) => {
      if (res['success']) {
        this.salesPerformanceForecastInfos = res['data']['salesPerformanceForecastInfos']
      }
    })
  }

  //活动量得分统计
  queryPEPScore(){
    this.myService.queryPEPScore({ practitionerId: this.practitionerId }).subscribe((res)=>{
      if(res['success']){
        this.personalList = res['data']['personalList'];
      }
    })
  }
}
