import { Component, OnInit } from '@angular/core';
import { MyService } from '../my.service';
import { ActivatedRoute } from "@angular/router";
import { LifeCommonService } from '../../common/life-common.service';
@Component({
  selector: 'ydlife-sales-detail',
  templateUrl: './sales-detail.component.html',
  styleUrls: ['./sales-detail.component.scss']
})
export class SalesDetailComponent implements OnInit {
  allPerformanceInfo: Array<any>;
  salesDetailList: Array<any>;
  searchType: any;
  performanceList: Array<any>;
  showType: any;
  constructor(private myService: MyService, private activatedRoute: ActivatedRoute, public lifeCommonService: LifeCommonService) {
    this.performanceList = [
      { type: 1, name: '本月' },
      { type: 2, name: '本年度' }
    ]
  }

  ngOnInit() {
    this.searchType = this.activatedRoute.snapshot.queryParams.searchType;
    this.showType = this.activatedRoute.snapshot.queryParams.showType;
    this.practitionerPolicyListQuery();
  }

  //查询保单
  practitionerPolicyListQuery() {
    const practitionerId = JSON.parse(localStorage.getItem('lifeCustomerInfo'))['practitionerId'];
    this.myService.practitionerPolicyListQuery({ practitionerId: practitionerId }).subscribe((res) => {
      if (res['success']) {
        this.allPerformanceInfo = res['data']['policyListInfo'];
        if (this.searchType == 1) {
          if (this.allPerformanceInfo['thisMonthInfo']) {
            this.salesDetailList = this.allPerformanceInfo['thisMonthInfo']['onlineInfo']['fortuneItemList'];
          } else {
            this.salesDetailList = [];
          }
        }
        if (this.searchType == 2) {
          if (this.allPerformanceInfo['thisYearInfo']['onlineInfo']) {
            this.salesDetailList = this.allPerformanceInfo['thisYearInfo']['onlineInfo']['fortuneItemList'];
          } else {
            this.salesDetailList = [];
          }
        }
      }
    })
  }



  selectRang(e) {
    this.searchType = e;
    this.practitionerPolicyListQuery();
  }

  jumpToOrderdetail(orderNo) {
    const customerId = JSON.parse(localStorage.getItem('lifeCustomerInfo')).customerId;
    window.location.href = `https://${window.location.host}/mine/orderdetail/${orderNo}?customerId=${customerId}&isReferral=true&paid=true`;
    // https://mdev.zuihuibi.cn/mine/orderdetail/CP338119110911044108?customerId=41&isReferral=true&paid=true&whichNumber=0&policyHolderType=2
  }
}
