保誠-保戶業務員媒合平台
wayne
2022-01-26 6fa4bba623713c396432ba8b863846883d6a1906
PAMapp/store/index.ts
@@ -1,27 +1,23 @@
import { StrictQueryParams } from '~/shared/models/strict-query.model';
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'
import { getFavoriteFromStorage, setFavoriteToStorage } from '~/shared/storageConsultant';
import myConsultantService from '~/shared/services/my-consultant.service';
import queryConsultantService from '~/shared/services/query-consultant.service';
import appointmentService from '~/shared/services/appointment.service';
import reviewsService from '~/shared/services/reviews.service';
import { Consultant } from '~/shared/models/consultant.model';
import { getFavoriteFromStorage, setFavoriteToStorage } from '~/shared/storageConsultant';
import { AppointmentLog } from '~/shared/models/appointment.model';
import { ClientInfo } from '~/shared/models/client.model';
import { AgentOfStrictQuery } from '~/shared/models/strict-query.model';
import { AgentOfStrictQuery, StrictQueryParams } from '~/shared/models/strict-query.model';
import { NotificationList } from '~/shared/models/reviews.model';
@Module
export default class Store extends VuexModule {
    recommendList: Consultant[] = [];
    strictQueryList: AgentOfStrictQuery[] = [];
    myConsultantList: Consultant[] = [];
    myAppointmentList: ClientInfo[] = [];
    myNewAppointmentSum: number = 0;
    myAppointmentReviewLogList: AppointmentLog[] = [];
    reviewLogList: AppointmentLog[] = [];
    unReviewLogList: AppointmentLog[] = [];
    notificationList: NotificationList[] = [];
    get isUserLogin() {
        return this.context.getters['localStorage/isUserLogin'];
@@ -29,7 +25,7 @@
    @Mutation
    updateRecommend(data: Consultant[]) {
        this.recommendList = data;
      this.recommendList = data;
    }
    @Mutation
@@ -43,18 +39,18 @@
    }
    @Mutation
    updateMyAppointmentList(data: ClientInfo[]) {
        this.myAppointmentList = data;
    updateReviewLog(data: AppointmentLog[]) {
        this.reviewLogList = data;
    }
    @Mutation
    updateMyNewAppointmentSum(newAppointmentSum: number) {
      this.myNewAppointmentSum = newAppointmentSum;
    updateUnReviewLog(data: AppointmentLog[]) {
        this.unReviewLogList = data;
    }
    @Mutation
    updateMyAppointmentReviewLog(data: AppointmentLog[]) {
        this.myAppointmentReviewLogList = data;
    updateNotification(data: NotificationList[]) {
        this.notificationList = data;
    }
    @Action
@@ -126,15 +122,6 @@
    }
    @Action
    storeMyAppointmentList(): void {
      appointmentService.getMyAppointmentList().then((data) => {
            const newAppointmentSum = data.filter(item => !item.consultantViewTime || item.consultantViewTime === null).length;
            this.context.commit('updateMyAppointmentList', data);
            this.context.commit('updateMyNewAppointmentSum', newAppointmentSum);
        });
    }
    @Action
    storeMyAppointmentReviewLog() {
        reviewsService.getMyReviewLog().then((data) => {
            const dataWithLatestDate = data.map((item) => {
@@ -144,15 +131,11 @@
                }
            });
            const sortedData = dataWithLatestDate.sort((a, b) => +b.compareDate - +a.compareDate);
            this.context.commit('updateMyAppointmentReviewLog', sortedData);
            const reviewLog = sortedData.filter(item => item.score);
            const unReviewLog = sortedData.filter(item => !item.score);
            this.context.commit('updateReviewLog', reviewLog);
            this.context.commit('updateUnReviewLog', unReviewLog);
        });
    }
    @Action
    updateMyAppointment(myAppointment: ClientInfo) {
        const data = this.myAppointmentList.filter(item => item.id !== myAppointment.id);
        data.unshift(myAppointment);
        this.context.commit('updateMyAppointmentList', data)
    }
    @Action
@@ -164,4 +147,13 @@
        });
    }
    @Action
    storeMyPersonalNotification() {
        reviewsService.getMyPersonalNotification().then(data => {
            const sortData = data
                .sort((preItem, nextItem) => +new Date(nextItem.createdDate) - +new Date(preItem.createdDate))
            this.context.commit('updateNotification', sortData);
        })
    }
}