From 20b87b7eab9c600e2445548c4306ea1b8b37b275 Mon Sep 17 00:00:00 2001
From: HelenHuang <LinHuang@pollex.com.tw>
Date: 星期一, 06 十二月 2021 12:29:50 +0800
Subject: [PATCH] update#131467: [滿意度評分功能]-客戶進行滿意度評分API串接

---
 PAMapp/pages/myConsultantList.vue |   52 ++++++++++++++++++++--------------------------------
 1 files changed, 20 insertions(+), 32 deletions(-)

diff --git a/PAMapp/pages/myConsultantList.vue b/PAMapp/pages/myConsultantList.vue
index 81b6e3a..061ee19 100644
--- a/PAMapp/pages/myConsultantList.vue
+++ b/PAMapp/pages/myConsultantList.vue
@@ -20,18 +20,14 @@
         <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 { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant';
-import { Consultants, getFavoriteConsultant } from '~/assets/ts/api/consultant';
-import { isLogin } from '~/assets/ts/auth';
+import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator';
+import { Route } from 'vue-router/types/router.d';
+import { Consultants } from '~/assets/ts/models/consultant.model';
 
 @Component
 export default class myConsultantList extends Vue {
@@ -40,38 +36,30 @@
     contactedList: Consultants[] = [];
     consultantList: Consultants[] = [];
 
+    @State('myConsultantList') myConsultantList!: Consultants[];
+    @Action storeConsultantList!: any;
+
+    @Watch('myConsultantList')
+    onMyConsultantListChange() {
+        this.filterContactedList();
+    }
+
     tabClick(path: string) {
         this.activeTabName = path;
         this.$router.push('/myConsultantList/' + this.activeTabName)
     }
 
-    async asyncData(context: Context) {
-        let agents: Consultants[] = [];
-        let contactedList: Consultants[] = [];
-        let consultantList: Consultants[] = [];
-
-        if (isLogin()) {
-            await getFavoriteConsultant().then((response) => agents = response.data);
-        } else {
-            agents = getFavoriteFromStorage();
-        }
-
-        contactedList = agents.filter(item => item.contactStatus === 'contacted');
-        consultantList = agents.filter(item => item.contactStatus !== 'contacted');
-
-        return {
-            agents,
-            contactedList,
-            consultantList
-        }
+    mounted() {
+        this.storeConsultantList();
     }
 
-    removeAgent(agentNo: string) {
-        const fintIndex = this.consultantList.findIndex(item => item.agentNo === agentNo);
-        this.consultantList.splice(fintIndex, 1);
-        if (!isLogin()) {
-            setFavoriteToStorage(this.consultantList);
-        }
+    filterContactedList() {
+        this.consultantList = (this.myConsultantList || [])
+                .filter(item => item.contactStatus !== 'contacted')
+                .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1);
+        this.contactedList = (this.myConsultantList || [])
+                .filter(item => item.contactStatus === 'contacted')
+                .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1);
     }
 
     @Watch('$route') watchRouter(currentRoute: Route) {

--
Gitblit v1.9.3