From a8e5dcd396b2934e0abdd97e2241bd020afe569b Mon Sep 17 00:00:00 2001
From: Mila <Mila@pollex.com.tw>
Date: 星期四, 11 十一月 2021 14:49:23 +0800
Subject: [PATCH] TODO#130018 [加入顧問] API 串接

---
 PAMapp/pages/index.vue |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/PAMapp/pages/index.vue b/PAMapp/pages/index.vue
index 041596f..6b0c73c 100644
--- a/PAMapp/pages/index.vue
+++ b/PAMapp/pages/index.vue
@@ -22,7 +22,10 @@
                     <span class="mdTxt">���“���</span>
                     <span class="smTxt_bold amount">� {{consultantList.length}} 蝑�</span>
                 </el-col>
-                <el-col :span="8" class="mdTxt readMore"
+                <el-col
+                    :span="8"
+                    class="mdTxt readMore"
+                    v-if="consultantList.length > 3"
                     @click.native="routerPush('/myConsultantList/consultantList')">���憭�</el-col>
             </el-row>
             <ConsultantList
@@ -40,8 +43,9 @@
 
 <script lang="ts">
 import { Vue, Component, State, Action } from 'nuxt-property-decorator';
-import { Consultants } from '~/assets/ts/api/consultant';
-import { login, recommend, getFavoriteConsultant } from '~/assets/ts/api/consultant';
+import { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant';
+import { addFavoriteConsultant, Consultants } from '~/assets/ts/api/consultant';
+import { login, getFavoriteConsultant } from '~/assets/ts/api/consultant';
 import { isLogin } from '~/assets/ts/auth';
 
 @Component({
@@ -54,26 +58,38 @@
     @Action storeRecommendList!: any;
 
     mounted() {
-
         if (!this.recommendList) {
             this.storeRecommendList();
         }
 
         if (isLogin()) {
+            this.addFavoriteFromStorageToApi();
             getFavoriteConsultant().then((response) => this.consultantList = response.data);
+        } else {
+            this.consultantList = getFavoriteFromStorage();
         }
+    }
 
+    addFavoriteFromStorageToApi() {
+        const agentNoList = getFavoriteFromStorage().map(i => i.agentNo)
+        if (agentNoList.length > 0) {
+            addFavoriteConsultant(agentNoList).then(res => res);
+            localStorage.removeItem('favoriteConsultant');
+        }
     }
 
     routerPush(path: string) {
         this.$router.push(path);
     }
 
-    removeAgent(agentNo: number) {
+    removeAgent(agentNo: string) {
         const findIndex = this.consultantList.findIndex((item, i) => {
             return item.agentNo === agentNo;
         })
-        this.consultantList.splice(findIndex, 1)
+        this.consultantList.splice(findIndex, 1);
+        if (!isLogin()) {
+            setFavoriteToStorage(this.consultantList)
+        }
     }
 
     // TODO: ��TP隤����� ���蝙�
@@ -90,7 +106,7 @@
 
     // TODO: ��TP隤����� ���蝙�
     remove() {
-        localStorage.clear();
+        localStorage.removeItem('id_token');
         this.$router.go(0)
     }
 

--
Gitblit v1.8.0