import { Component, OnInit } from '@angular/core';
import { ActivatedRoute,Router } from "@angular/router";
import { MyService } from '../../my.service';
import { LifeCommonService } from "../../../common/life-common.service";
import { environment } from '../../../../environments/environment';
@Component({
  selector: 'ydlife-invitation',
  templateUrl: './invitation.component.html',
  styleUrls: ['./invitation.component.scss']
})
export class InvitationComponent implements OnInit {
  //判断邀请人/被邀请人
  type: string;
  invitatorName:string;
  lifeCustomerInfo: any;
  deviceType:any;
  
  constructor(private myService: MyService, 
    private activatedRoute: ActivatedRoute,
    public lifeCommonService: LifeCommonService,
    private router: Router) { }

  ngOnInit() {
    this.lifeCustomerInfo = JSON.parse(localStorage.getItem('lifeCustomerInfo')) ? JSON.parse(localStorage.getItem('lifeCustomerInfo')) : null;
    this.type = this.activatedRoute.snapshot.data[0]['type'];
    console.log(this.type)
    this.invitatorName = this.activatedRoute.snapshot.queryParams.name?this.activatedRoute.snapshot.queryParams.name:null;
    this.deviceType = this.lifeCommonService.checkDeviceType();
  }

  //分享邀请
  sandInvitation() {
    if(this.deviceType == 3){
      const imgUrl = this.lifeCustomerInfo.practitionerBasicInfo.headImagePath ? this.lifeCustomerInfo.practitionerBasicInfo.headImagePath : `${environment.ORIGINNAME}/ydLife/assets/images/icons/meng.png`;
      this.lifeCommonService.shareStatusPublish(1);
      this.lifeCommonService.wxShare(
        `${this.lifeCustomerInfo.practitionerBasicInfo.name}`,
        '您的好友向你发出了邀请。加入靠谱的团队、一起做靠谱的事。',
        `https://${window.location.host}/ydLife/invitees?practitionerId=${this.lifeCustomerInfo.practitionerId}`,
        imgUrl);
      }else{
        alert('请在手机微信端发送邀请');
      }
  }
  
  
  register(){
    this.router.navigate(['/register']);
  }
}
