保誠-保戶業務員媒合平台
Tomas
2024-01-11 756f8a63347119f511fc964bf1e2ff2417339c56
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
import { AgentInfo } from '~/shared/models/agent-info.model';
import { Appointment } from "../models/appointment.model";
import { Consultant } from "../models/consultant.model";
import { http } from "./httpClient";
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;
    });
  }
 
  async getAllGroupByConsultant(): Promise<Consultant[]> {
    return http.get<Consultant[]>('/appointment/customer/get_all_group_by_consultant').then((res) => 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}`);
  }
 
  // 標記為已聯絡
  async markAsContact(appointmentId: number): Promise<Appointment> {
    try {
      const response = await http.post(`/appointment/markAsContacted/${appointmentId}`);
      if (response !== null) {
        return response.data;
      } else {
        throw new Error('http.post returned null-like value.');
      }
    } catch (error) {
      console.error('An error occurred while marking appointment as contacted:', error);
      // 可以在此處處理錯誤或回傳預設值
      throw error;
    }
  }
 
 
  // 取得顧問頭像
  getConsultantAvatar(agentNo:string):Promise<string>{
    return http.get(`/consultant/avatar/${agentNo}`,{ responseType : 'arraybuffer' })
      .then( response => {
        const toBase64 = window.btoa(
                          Array.from(new Uint8Array(response.data)).reduce((data, byte) =>
                            data + String.fromCharCode(byte), '')
                        );
        const imgSrc = `data:image/png;base64,${toBase64}`;
        return imgSrc;
    });
  }
}
 
export default new MyConsultantService();