保誠-保戶業務員媒合平台
Tomas
2022-01-13 46da7429ca192bf6a947d79437e8076b94676a05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import _ from "lodash";
 
import { http } from "./httpClient";
import { AgentInfo } from '~/shared/models/agent-info.model';
import { Consultant } from "../models/consultant.model";
import { Appointment } from "../models/appointment.model";
class MyConsultantService {
 
  async getFavoriteConsultantList(): Promise<Consultant[]> {
    return http.get<Consultant[]>('/consultant/favorite').then((res) => {
      const hasNewConsultant = res.data.find((consultant) => !consultant.customerViewTime);
      if (hasNewConsultant) {
        this.viewMyConsultantList();
      };
      return res.data;
    });
  }
 
  private viewMyConsultantList(): void {
    http.post('/consultant/favorite/view');
  }
 
  //顧問詳細資訊
  async getConsultantDetail(agentNo:string): Promise<AgentInfo> {
    return http.get('/consultant/detail', {params:{agentNo:agentNo}}).then((res) => res.data);
  }
 
  // 移除顧問
  async deleteConsultant(agentId: string) {
    return http.delete(`/consultant/favorite/${agentId}`);
  }
 
  // 標記為已聯絡
  markAsContact(appointmentId: number): Promise<Appointment> {
    return http.post(`/appointment/markAsContacted/${appointmentId}`).then(res => res.data);
  }
 
  // 取得顧問頭像
  getConsultantAvatar(agentNo:string):Promise<string>{
    return http.get(`/consultant/avatar/${agentNo}`,{ responseType : 'arraybuffer' })
      .then( response => {
        const toBase64 = window.btoa(
                          _.reduce( new Uint8Array(response.data),(data,byte) =>
                            data + String.fromCharCode(byte),'')
                        );
        const imgSrc = `data:image/png;base64,${toBase64}`;
        return imgSrc;
    });
  }
}
 
export default new MyConsultantService();