保誠-保戶業務員媒合平台
Tomas
2023-08-05 f3e662798b3b83a83c2d60dc7b4e6cf1ee4f1331
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { http } from "./httpClient";
 
import { Appointment, AppointmentMemoInfo, createdMemoInfo, EditAppointmentParams,  InterviewRecordInfo, ToCloseAppointment, ToDoneAppointment, ToInformAppointment, updatedMemoInfo, UpdateInterviewRecordInfo } from "~/shared/models/appointment.model";
 
class AppointmentService {
 
  // 顧問取得所有自己的預約單API
  async getMyAppointmentList(): Promise<Appointment[]> {
    return http.get('/consultant/getMyAppointment').then((res) => {
      const hasNewAppointment = res.data.find((appointment: Appointment) => !appointment.consultantViewTime);
      if (hasNewAppointment) {
        this.viewAllAppointment();
      }
      return res.data;
    });
  }
 
  // 顧問瀏覽自己所有的預約單紀錄觸發API
  private viewAllAppointment(): void {
    http.post('/consultant/record/allAppointmentsView').then();
  }
 
  // 讀取預約單時觸發,紀錄讀取預約單時間
  recordRead(appointmentId: number): Promise<void> {
    return http.post(`/appointment/recordRead/${appointmentId}`);
  }
 
  // 取得預約單細節
  async getAppointmentDetail(appointmentId: number):Promise<Appointment> {
    return http.get(`/appointment/getDetail/${appointmentId}`).then((res) => res.data);
  }
 
  // 取消預約
  cancelAppointment(appointmentId: number): Promise<void> {
    return http.delete(`/appointment/${appointmentId}`);
  }
 
  // 編輯預約
  editAppointment(editAppointmentParams: EditAppointmentParams) {
    return http.put('/appointment', editAppointmentParams);
  }
 
  /**
   * 新增註記
   * @param memoInfo 包含新增註記相關資訊的物件
   * @returns 回傳新增的註記資訊
   */
  async createMemo(memoInfo: createdMemoInfo): Promise<AppointmentMemoInfo> {
    try {
      const response = await http.post('/appointment/memo/create', memoInfo);
      if (response !== null) {
        return response.data;
      } else {
        throw new Error('http.post returned null-like value.');
      }
    } catch (error) {
      // 可以在此處處理錯誤或回傳預設值
      console.error('An error occurred while creating memo:', error);
      throw error;
    }
  }
 
 
  /**
   * 編輯註記
   * @param memoInfo 包含編輯註記相關資訊的物件
   * @returns 回傳更新後的註記資訊
   */
  async updateMemo(memoInfo: updatedMemoInfo): Promise<AppointmentMemoInfo> {
    try {
      const response = await http.post('/appointment/memo/update', memoInfo);
      if (response !== null) {
        return response.data;
      } else {
        throw new Error('http.post returned null-like value.');
      }
    } catch (error) {
      // 可以在此處處理錯誤或回傳預設值
      console.error('An error occurred while updating memo:', error);
      throw error;
    }
  }
 
 
  // 刪除註記
  deleteMemo(appointmentMemoId: number) {
    return http.delete(`/appointment/memo/${appointmentMemoId}`)
  }
 
  // 預約單結案, 更新結案明細
  async closeAppointment(appointmentInfo: ToDoneAppointment | ToCloseAppointment) {
    return http.post(`/appointment/close`, appointmentInfo).then((res) => res.data);
  }
 
  // 約訪通知 API
  async informAppointment(appointmentInformation: ToInformAppointment) {
    return http.post(`/notice/send`, appointmentInformation).then((res) => res.data);
  }
 
  // 新增約訪記錄
  async createInterviewRecord(interviewRecordInfo: InterviewRecordInfo) {
    return http.post('/interview_record/create', interviewRecordInfo).then(res => res.data);
  }
 
  // 修改約訪記錄
  async updateInterviewRecord(updateInterviewRecordInfo: UpdateInterviewRecordInfo) {
    return http.post('/interview_record/update', updateInterviewRecordInfo)
  }
 
  // 刪除約訪記錄
  async deleteInterviewRecord(interviewRecordId) {
    return http.delete(`/interview_record/${interviewRecordId}`);
  }
 
  // 客戶取得最新預約的未處理預約單
  async getNotContactAppointment(): Promise<Appointment> {
    return http.get(`/appointment/customer/expiring/newest`).then((res) => res.data);
  }
 
  // 顧問取得未處理預約單數量通知
  async getPendingAppointmentSum(): Promise<number> {
    return http.get(`/appointment/consultant/pending/sum`).then((res) => res.data)
  }
 
}
 
export default new AppointmentService();