From 97e093b1117b68948d0f9adefacc5368014db380 Mon Sep 17 00:00:00 2001
From: Jack <jack.su@pollex.com.tw>
Date: 星期日, 14 十一月 2021 22:43:09 +0800
Subject: [PATCH] Merge branch 'master' of ssh://192.168.0.10:29418/pcalife/PAM

---
 PAMapp/pages/index.vue |   49 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/PAMapp/pages/index.vue b/PAMapp/pages/index.vue
index 041596f..7a5053b 100644
--- a/PAMapp/pages/index.vue
+++ b/PAMapp/pages/index.vue
@@ -1,6 +1,7 @@
 <template>
     <div>
-        <el-button @click="login">��</el-button>
+        <el-button @click="login('user')">摰X��</el-button>
+        <el-button @click="login('admin')">憿批��</el-button>
         <el-button @click="remove">��</el-button>
         <Ui-Carousel></Ui-Carousel>
         <div class="page-container">
@@ -22,7 +23,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 +44,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,43 +59,63 @@
     @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隤����� ���蝙�
-    login() {
+    login(account: string) {
         const user = {
-            username: "user",
-            password: "user"
+            username: account,
+            password: account
         }
         login(user).then((res) => {
             localStorage.setItem('id_token', res.data.id_token);
-            this.$router.go(0);
+
+            if (account === 'admin') {
+                this.$router.push('/myAppointmentList/appointmentList');
+            } else {
+                this.$router.go(0);
+            }
+
         })
+
+
     }
 
     // TODO: ��TP隤����� ���蝙�
     remove() {
-        localStorage.clear();
+        localStorage.removeItem('id_token');
         this.$router.go(0)
     }
 

--
Gitblit v1.8.0