From e2b8d0260e54c5dab2a595a3b1cf71b69734f3fb Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期三, 26 一月 2022 14:50:22 +0800
Subject: [PATCH] fixed#134865: [ 顧問管理流程 ] 安琪拉客戶預約熊蔡顧問 , 9:33 新的一筆預約單狀態變為約訪中 , 但歷史紀錄只要是熊蔡的預約單 , 在已聯絡列表中都會顯示 9:33 建立的

---
 PAMapp/pages/myConsultantList.vue |  144 +++++++++++++++++++++++++++---------------------
 1 files changed, 81 insertions(+), 63 deletions(-)

diff --git a/PAMapp/pages/myConsultantList.vue b/PAMapp/pages/myConsultantList.vue
index b8e1ba4..afa5d20 100644
--- a/PAMapp/pages/myConsultantList.vue
+++ b/PAMapp/pages/myConsultantList.vue
@@ -1,17 +1,17 @@
 <template>
     <div>
-        <div class="flex mb-30">
+        <div class="pam-cus-tabs mb-30">
             <div
                 class="cus-tab-item"
                 :class="{'is-active': activeTabName === 'consultantList'}"
-                @click="tabClick('consultantList')"
+                @click="clickTab('consultantList')"
             >憿批��
                 <span class="p">({{consultantList.length}})</span>
             </div>
             <div
                 class="cus-tab-item"
                 :class="{'is-active': activeTabName === 'contactedList'}"
-                @click="tabClick('contactedList')"
+                @click="clickTab('contactedList')"
             >撌脰蝯�
                 <span class="p">({{contactedList.length}})</span>
             </div>
@@ -20,80 +20,98 @@
         <NuxtChild
             :contactedList="contactedList"
             :consultantList="consultantList"
-            @remove="removeAgent"
         ></NuxtChild>
+
     </div>
 </template>
 
 <script lang='ts'>
-import { Context } from '@nuxt/types';
-import { Vue, Component, Watch } from 'vue-property-decorator';
-import { Route } from 'vue-router/types/router.d'
-import { Agents } from '~/plugins/api/home';
+import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator';
+
+import authService from '~/shared/services/auth.service';
+import { Consultant, ConsultantWithAppointmentId } from '~/shared/models/consultant.model';
 
 @Component
 export default class myConsultantList extends Vue {
-    activeTabName = 'consultantList';
-    agents: Agents[] = [];
-    contactedList: Agents[] = [];
-    consultantList: Agents[] = [];
 
-    tabClick(path: string) {
+    @State('myConsultantList')
+    myConsultantList!: Consultant[];
+
+    @Action
+    storeConsultantList!: any;
+
+    activeTabName : string                        = 'consultantList';
+    consultantList: Consultant[]                  = [];
+    contactedList : ConsultantWithAppointmentId[] = [];
+
+    //////////////////////////////////////////////////////////////////////
+
+    beforeRouteEnter(to: any, from: any, next: any) {
+      next((vm: any) => {
+        if (to.name === 'myConsultantList') {
+            vm.$router.push('myConsultantList/consultantList');
+          return;
+        }
+      })
+    }
+
+    mounted() {
+      this.storeConsultantList();
+
+      if (this.$route.name) {
+        this.activeTabName = this.$route.name.split('-')[1]
+      }
+    }
+
+    //////////////////////////////////////////////////////////////////////
+
+    @Watch('myConsultantList')
+    onMyConsultantListChange() {
+        this.setList();
+    }
+
+    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 );
+
+      if (authService.isUserLogin()) {
+        this.myConsultantList.filter((consultant) => consultant.appointments!.length)
+          .forEach((consultant) => {
+            consultant.appointments!.forEach((appointment) => {
+              const consultantWithAppointmentId: ConsultantWithAppointmentId = {
+                ...consultant,
+                appointmentId: appointment.id,
+                appointmentDate: appointment.appointmentDate,
+                appointmentScore: appointment.satisfactionScore,
+                appointmentStatus: appointment.communicateStatus,
+                appointmentLastModifiedDate: appointment.lastModifiedDate
+              };
+              this.contactedList.push(consultantWithAppointmentId);
+            })
+          });
+
+        this.contactedList = this.contactedList
+          .filter((appointment) => appointment['appointmentStatus'] !== 'reserved')
+          .map((appointment) => ({ ...appointment, sortTime: new Date(appointment.appointmentDate)}))
+          .sort((preAppointment, nextAppointment) => +nextAppointment.sortTime - +preAppointment.sortTime);
+      }
+
+    }
+
+    //////////////////////////////////////////////////////////////////////
+
+    clickTab(path: string) {
         this.activeTabName = path;
         this.$router.push('/myConsultantList/' + this.activeTabName)
     }
 
-    async asyncData(context: Context) {
-        let agents: Agents[] = [];
-        let contactedList: Agents[] = [];
-        let consultantList: Agents[] = [];
-
-        await context.$service.home.recommendConsultantList().then((result: Agents[]) => {
-            agents = result;
-        })
-
-        contactedList = agents.filter(item => item.contactStatus === 'contacted');
-        consultantList = agents.filter(item => item.contactStatus !== 'contacted');
-
-        return {
-            agents,
-            contactedList,
-            consultantList
-        }
-    }
-
-    removeAgent(agentNo: number) {
-        const fintIndex = this.consultantList.findIndex(item => item.agentNo === agentNo);
-        this.consultantList.splice(fintIndex, 1);
-    }
-
-    @Watch('$route') watchRouter(currentRoute: Route) {
-        const pathArray = currentRoute.fullPath.split('/');
-        this.activeTabName = pathArray[pathArray.length - 1];
-    }
 
 }
 </script>
 
-<style lang="scss" scoped>
-    .flex {
-        display: flex;
-        width: 100%;
-        height: 45px;
-
-        .cus-tab-item {
-            width: 50%;
-            text-align: center;
-            font-size: 24px;
-            border-bottom: solid 3px $LIGHT_GREY;
-            cursor: pointer;
-        }
-
-        .is-active {
-            font-weight: bold;
-            border-bottom: solid 3px $PRIMARY_BLACK;
-
-        }
-    }
-
-</style>
\ No newline at end of file

--
Gitblit v1.8.0