From 83757a31e7b1593d2cce267061722c259c0d5800 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期四, 24 三月 2022 23:20:40 +0800
Subject: [PATCH] update: [客戶端] 我的顧問清單 refactoring (已聯絡清單使用新 api)

---
 PAMapp/components/Consultant/ConsultantCard.vue |    2 +-
 PAMapp/store/index.ts                           |   12 +++++++++++-
 PAMapp/pages/myConsultantList.vue               |   18 ++++++++++++++----
 PAMapp/shared/services/my-consultant.service.ts |    4 ++++
 4 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/PAMapp/components/Consultant/ConsultantCard.vue b/PAMapp/components/Consultant/ConsultantCard.vue
index 642c210..6c9bcd2 100644
--- a/PAMapp/components/Consultant/ConsultantCard.vue
+++ b/PAMapp/components/Consultant/ConsultantCard.vue
@@ -1,6 +1,6 @@
 <template>
     <div>
-        <el-row type="flex" class="rowStyle" :class="{'new': !agentInfo.customerViewTime }">
+        <el-row type="flex" class="rowStyle" :class="{'new': !agentInfo.customerViewTime && $route.name !== 'myConsultantList-contactedList' }">
             <el-col class="flex_column pl-5" :xs="5" :sm="3">
                 <UiAvatar
                     :size="50"
diff --git a/PAMapp/pages/myConsultantList.vue b/PAMapp/pages/myConsultantList.vue
index 33caf53..6914ee7 100644
--- a/PAMapp/pages/myConsultantList.vue
+++ b/PAMapp/pages/myConsultantList.vue
@@ -37,6 +37,9 @@
     @State('myConsultantList')
     myConsultantList!: Consultant[];
 
+    @State('myAppointmentGroupByConsultantList')
+    myAppointmentGroupByConsultantList!: ConsultantWithAppointmentId[];
+
     @Action
     storeConsultantList!: any;
 
@@ -70,18 +73,26 @@
         this.setList();
     }
 
+    @Watch('myAppointmentGroupByConsultantList')
+    omMyAppointmentGroupByConsultantList() {
+      this.setContactedList();
+    }
+
     private setList() {
-    // reset contacted list
-      this.contactedList = [];
 
     // format consultant list
       this.consultantList = (this.myConsultantList || [])
         .filter(item => item.contactStatus !== 'contacted')
         .map((item) => ({ ...item, formatDate: new Date(item.updateTime || item.createTime)}))
         .sort((preItem, nextItem) => +nextItem.formatDate - +preItem.formatDate );
+    }
+
+    private setContactedList() {
+      // reset contacted list
+      this.contactedList = [];
 
       if (authService.isUserLogin()) {
-        this.myConsultantList.filter((consultant) => consultant.appointments!.length)
+        this.myAppointmentGroupByConsultantList.filter((consultant) => consultant.appointments!.length)
           .forEach((consultant) => {
             consultant.appointments!.forEach((appointment) => {
               const consultantWithAppointmentId: ConsultantWithAppointmentId = {
@@ -101,7 +112,6 @@
           .map((appointment) => ({ ...appointment, sortTime: new Date(appointment.appointmentLastModifiedDate)}))
           .sort((preAppointment, nextAppointment) => +nextAppointment.sortTime - +preAppointment.sortTime);
       }
-
     }
 
     //////////////////////////////////////////////////////////////////////
diff --git a/PAMapp/shared/services/my-consultant.service.ts b/PAMapp/shared/services/my-consultant.service.ts
index 3d4dd78..b107a8e 100644
--- a/PAMapp/shared/services/my-consultant.service.ts
+++ b/PAMapp/shared/services/my-consultant.service.ts
@@ -16,6 +16,10 @@
     });
   }
 
+  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');
   }
diff --git a/PAMapp/store/index.ts b/PAMapp/store/index.ts
index 9dd6256..f4120ca 100644
--- a/PAMapp/store/index.ts
+++ b/PAMapp/store/index.ts
@@ -3,7 +3,7 @@
 import myConsultantService from '~/shared/services/my-consultant.service';
 import queryConsultantService, { AddFavoriteConsultantItem } from '~/shared/services/query-consultant.service';
 import reviewsService from '~/shared/services/reviews.service';
-import { Consultant } from '~/shared/models/consultant.model';
+import { Consultant, ConsultantWithAppointmentId } from '~/shared/models/consultant.model';
 import { getFavoriteFromStorage, setFavoriteToStorage } from '~/shared/storageConsultant';
 import { AppointmentLog } from '~/shared/models/appointment.model';
 import { AgentOfStrictQuery, StrictQueryParams } from '~/shared/models/strict-query.model';
@@ -14,6 +14,7 @@
     recommendList: Consultant[] = [];
     strictQueryList: AgentOfStrictQuery[] = [];
     myConsultantList: Consultant[] = [];
+    myAppointmentGroupByConsultantList: ConsultantWithAppointmentId[] = [];
 
     reviewLogList: AppointmentLog[] = [];
     unReviewLogList: AppointmentLog[] = [];
@@ -60,6 +61,11 @@
         this.notificationList = data;
     }
 
+    @Mutation
+    updateAppointmentGroupByConsultantList(data: ConsultantWithAppointmentId[]) {
+      this.myAppointmentGroupByConsultantList = data;
+    }
+
     @Action
     storeRecommendList() {
         queryConsultantService.getRecommendConsultantList().then(data => {
@@ -87,6 +93,10 @@
         myConsultantService.getFavoriteConsultantList().then(data => {
             this.context.commit('updateConsultantList', data);
         })
+
+        myConsultantService.getAllGroupByConsultant().then((data) => {
+          this.context.commit('updateAppointmentGroupByConsultantList', data);
+        })
     }
 
     @Action

--
Gitblit v1.8.0