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);
|
}
|
|
}
|