import {Injectable} from '@angular/core';
import {IUser} from '../model';

@Injectable({
  providedIn: 'root'
})
export class ConfigService {

  constructor() {
  }

  public rootUrl = '/marketing/yinliu'; // 部署路径
  campaignId = localStorage.getItem('campaignId') || '';//'bae3c1e4c6bf4d577f01a6312d30fe41'; // 活动id 1
  reqChannel = 3; // 渠道
  userInfo: IUser | undefined = this.getUserInfo();

  // 获取用户信息
  getUserInfo() {
    // localStorage.setItem('params',`{"participantId":"069c97ff8b3528a5aeb88a2eb69917ae","marketingToken":"f4a739085b894434b506d67b549b4841","campaignId":"bae3c1e4c6bf4d577f01a6312d30fe41","mobile":"15198809242","userName":"ZJ"}`)
    const user = localStorage.getItem('params');
    if (user) {
      return JSON.parse(user);
    }
    return undefined;
  }

  // 注销用户
  exitUser() {
    this.userInfo = undefined;
    localStorage.removeItem('params');
    return undefined;
  }

  // 监听webview获取的数据
  // getWebView() {
  //   try {
  //     window.addEventListener('message', (data) => {
  //       alert(`${data.data.data}`);
  //       window.removeEventListener('message',()=>{});
  //     });
  //   } catch (e) {
  //
  //   }
  // }
}
