保誠-保戶業務員媒合平台
wayne
2022-02-17 a3716f72066d25d745f4d5103ff23a553c3e102b
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
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'
 
import appointmentService from '~/shared/services/appointment.service';
import { ContactStatus } from '~/shared/models/enum/contact-status';
import { Appointment } from '~/shared/models/appointment.model';
 
@Module
export default class AppointmentStore extends VuexModule {
 
  contactStatus = ContactStatus;
 
  appointmentDetail: Appointment | null = JSON.parse(localStorage.getItem('appointment')!);
  myAppointmentList: Appointment[]      = [];
 
  //////////////////////////////////////////////////////////////////////
 
  get appointmentProgress(): ContactStatus {
    return this.appointmentDetail!.communicateStatus;
  }
 
  get newAppointmentSum(): number {
    return this.myAppointmentList.filter(item => !item.consultantViewTime || item.consultantViewTime === null).length;
  }
 
  get appointmentItemSum(): number {
    return this.myAppointmentList.filter(item => item.communicateStatus === this.contactStatus.RESERVED).length;
  }
 
  get contactedItemSum(): number {
    return this.myAppointmentList.filter((item) => item.communicateStatus === this.contactStatus.CONTACTED).length;
  }
 
  get closedItemSum(): number {
    return this.myAppointmentList
    .filter(item => item.communicateStatus === this.contactStatus.DONE || item.communicateStatus === this.contactStatus.CLOSE ).length;
  }
 
  get isCloseAppointment(): boolean {
    const closedStatusList = [this.contactStatus.DONE, this.contactStatus.CLOSE, this.contactStatus.CANCEL];
    return closedStatusList.includes(this.appointmentDetail!.communicateStatus);
  }
 
  //////////////////////////////////////////////////////////////////////
 
  @Mutation
  SET_MY_APPOINTMENT_LIST(appointmentList: Appointment[]): void {
    this.myAppointmentList = appointmentList;
  }
 
  @Mutation
  SET_APPOINTMENT(appointmentDetail: Appointment): void {
    this.appointmentDetail = appointmentDetail;
    localStorage.setItem('appointment', JSON.stringify(appointmentDetail));
  }
 
  //////////////////////////////////////////////////////////////////////
 
  @Action({ commit: 'SET_MY_APPOINTMENT_LIST' })
  async getMyAppointmentList(): Promise<Appointment[]> {
    return await appointmentService.getMyAppointmentList().then((res) => res);
  }
 
  @Action({ commit: 'SET_MY_APPOINTMENT_LIST' })
  updateMyAppointmentList(appointment: Appointment): Appointment[] {
    const tempList = this.myAppointmentList.filter((item) => item.id !== appointment.id);
    tempList.unshift(appointment);
    return tempList;
  }
 
  @Action({ commit: 'SET_APPOINTMENT'})
  async getAppointmentDetail(appointmentId: number): Promise<Appointment> {
    if (this.appointmentDetail && this.appointmentDetail.id === appointmentId) {
      return this.appointmentDetail;
    } else {
      return await appointmentService.getAppointmentDetail(appointmentId).then((res) => res);
    }
  }
 
  @Action({ commit: 'SET_APPOINTMENT'})
  async updateAppointmentDetail(appointmentId: number): Promise<Appointment> {
    return await appointmentService.getAppointmentDetail(appointmentId).then((res) => res);
  }
 
}