From f6a21bf37ef56ecab88652b1449da63f73b9648a Mon Sep 17 00:00:00 2001
From: Mila <Mila@pollex.com.tw>
Date: 星期二, 16 十一月 2021 20:59:28 +0800
Subject: [PATCH] update 我的顧問清單: 使用 store 存放 consultantList 以及新增顧問、移除顧問的狀態控制

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

diff --git a/PAMapp/pages/myConsultantList.vue b/PAMapp/pages/myConsultantList.vue
index b8e1ba4..d935c8d 100644
--- a/PAMapp/pages/myConsultantList.vue
+++ b/PAMapp/pages/myConsultantList.vue
@@ -1,6 +1,6 @@
 <template>
     <div>
-        <div class="flex mb-30">
+        <div class="pam-cus-tabs mb-30">
             <div
                 class="cus-tab-item"
                 :class="{'is-active': activeTabName === 'consultantList'}"
@@ -20,51 +20,46 @@
         <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 { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator';
 import { Route } from 'vue-router/types/router.d'
-import { Agents } from '~/plugins/api/home';
+import { Consultants } from '~/assets/ts/api/consultant';
 
 @Component
 export default class myConsultantList extends Vue {
     activeTabName = 'consultantList';
-    agents: Agents[] = [];
-    contactedList: Agents[] = [];
-    consultantList: Agents[] = [];
+    agents: Consultants[] = [];
+    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: 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
-        }
+    mounted() {
+        this.storeConsultantList();
     }
 
-    removeAgent(agentNo: number) {
-        const fintIndex = this.consultantList.findIndex(item => item.agentNo === agentNo);
-        this.consultantList.splice(fintIndex, 1);
+    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) {
@@ -73,27 +68,4 @@
     }
 
 }
-</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
+</script>
\ No newline at end of file

--
Gitblit v1.8.0