From cd4a64b39c429f2f5b45cb042d1b66f1cd3904cd Mon Sep 17 00:00:00 2001
From: 劉鈞霖 <benson@gmail.com>
Date: 星期一, 15 十一月 2021 18:06:40 +0800
Subject: [PATCH] [ Update ] 更新 navbar 清單 根據 角色 顯示清單

---
 PAMapp/pages/index.vue |  182 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 162 insertions(+), 20 deletions(-)

diff --git a/PAMapp/pages/index.vue b/PAMapp/pages/index.vue
index 75158e8..feffa01 100644
--- a/PAMapp/pages/index.vue
+++ b/PAMapp/pages/index.vue
@@ -1,43 +1,185 @@
 <template>
     <div>
         <Ui-Carousel></Ui-Carousel>
-        <h5>���“���</h5>
-        <el-button @click="routerPush('/recommendConsultant')">������</el-button>
-        <el-button @click="routerPush('/quickFilter')">敹恍�祟�</el-button>
-        <h5>���蝯⊥�</h5>
-        <el-button @click="routerPush('/contactList/consultantList')">���憭�</el-button>
-        <el-button @click="routerPush('/communication/consult')">隢株岷</el-button>
-        <h5>��憿批��</h5>
-        <Ui-Swiper :agents="agents"></Ui-Swiper>
+        <div class="page-container">
+            <h5 class="mdTxt mb-30">����憿批��</h5>
+            <el-button
+                class="reserveBtn recommendConsultant"
+                @click="routerPush('/recommendConsultant')"
+            >
+                <p>������</p>
+            </el-button>
+            <el-button
+                class="reserveBtn quickFilter"
+                @click="routerPush('/quickFilter')"
+            >
+                <p>敹恍�祟�</p>
+            </el-button>
+            <el-row class="mb-30 rowStyle">
+                <el-col :span="16">
+                    <span class="mdTxt">���“���</span>
+                    <span class="smTxt_bold amount">� {{consultantList.length}} 蝑�</span>
+                </el-col>
+                <el-col
+                    :span="8"
+                    class="mdTxt readMore"
+                    v-if="consultantList.length > 3"
+                    @click.native="routerPush('/myConsultantList/consultantList')">���憭�</el-col>
+            </el-row>
+            <ConsultantList
+                :agents="consultantList.slice(0, 3)"
+                @removeAgent="removeAgent"
+            ></ConsultantList>
+            <div class='pam-recommend pb-30 pt-30'>
+                <h5 class="mdTxt">��靽憿批��</h5>
+                <img class="absulate img" src="~/assets/images/index_recommend.svg" alt="">
+            </div>
+            <ConsultantSwiper :agents="recommendList"></ConsultantSwiper>
+        </div>
     </div>
 </template>
 
 <script lang="ts">
-import { Vue, Component } from 'nuxt-property-decorator';
-import { Agents } from '~/plugins/api/home';
-import { Context } from '@nuxt/types/app';
+import { Vue, Component, State, Action } from 'nuxt-property-decorator';
+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({
     layout: 'home'
 })
 export default class MainComponent extends Vue {
-    agents: Agents[] = [];
+    consultantList: Consultants[] = [];
+    agents: Consultants[] = [];
+    @State('recommendList') recommendList!: Consultants[];
+    @Action storeRecommendList!: any;
 
-    async asyncData(context: Context) {
-        let agents: Agents[] = [];
+    mounted() {
+        if (!this.recommendList) {
+            this.storeRecommendList();
+        }
 
-        await context.$service.home.recommendConsultantList().then((result: Agents[]) => {
-            agents = result;
-        })
+        if (isLogin()) {
+            this.addFavoriteFromStorageToApi();
+            getFavoriteConsultant().then((response) => this.consultantList = response.data);
+        } else {
+            this.consultantList = getFavoriteFromStorage();
+        }
+    }
 
-        return {
-            agents
+    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: string) {
+        const findIndex = this.consultantList.findIndex((item, i) => {
+            return item.agentNo === agentNo;
+        })
+        this.consultantList.splice(findIndex, 1);
+        if (!isLogin()) {
+            setFavoriteToStorage(this.consultantList)
+        }
+    }
 }
 
-</script>
\ No newline at end of file
+</script>
+
+<style lang="scss" scoped>
+
+    .page-container {
+        padding: 0px 20px 30px 20px;
+    }
+
+    .reserveBtn.el-button--default {
+        width: 100%;
+        height: 110px;
+        border-radius: 10px;
+        margin: 0 auto 17px auto;
+        font-size: 32px;
+        font-weight: 700;
+        background-position: right;
+        background-size: cover;
+        color: #68737A;
+        text-align: left;
+        background-repeat: no-repeat;
+        box-shadow: 0px 0px 6px #a79b9b29;
+        border-width: 0;
+
+        p {
+            text-shadow: 1px 1px 5px $PRIMARY_WHITE;
+        }
+
+        &:nth-child(3) {
+            margin-bottom: 42px;
+        }
+
+    }
+
+    .reserveBtn+.reserveBtn {
+        margin-left: 0px;
+    }
+
+    .quickFilter {
+        background-image: url('~/assets/images/quickFilter/banner_mob.svg');
+    }
+
+    .recommendConsultant {
+        background-image: url('~/assets/images/recommendConsultant/banner_mob.svg');
+    }
+
+    @media (min-width: 576px) and (max-width: 1023px) {
+        .quickFilter.el-button--default {
+            background-image: url('~/assets/images/quickFilter/banner_web.svg');
+        }
+
+        .recommendConsultant.el-button--default {
+            background-image: url('~/assets/images/recommendConsultant/banner_web.svg');
+        }
+    }
+
+    .rowStyle {
+        .amount {
+            color: $PRUDENTIAL_GREY;
+        }
+        .readMore {
+            color: $PRIMARY_RED;
+            cursor: pointer;
+            text-align: right;
+        }
+    }
+
+    @include desktop {
+        .page-container {
+            width: 700px;
+            margin: 0 auto;
+        }
+
+        .reserveBtn {
+            max-width: 340px;
+
+            &:nth-child(2) {
+                margin-right: 15px;
+            }
+        }
+    }
+
+    .pam-recommend {
+        position: relative;
+
+        .img {
+            position: absolute;
+            right: 20px;
+            bottom: 0px;
+        }
+    }
+
+</style>

--
Gitblit v1.8.0