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/index.vue | 67 +++++++-------------------------- 1 files changed, 15 insertions(+), 52 deletions(-) diff --git a/PAMapp/pages/index.vue b/PAMapp/pages/index.vue index 6b0c73c..9ec3c7c 100644 --- a/PAMapp/pages/index.vue +++ b/PAMapp/pages/index.vue @@ -1,7 +1,5 @@ <template> <div> - <el-button @click="login">��</el-button> - <el-button @click="remove">��</el-button> <Ui-Carousel></Ui-Carousel> <div class="page-container"> <h5 class="mdTxt mb-30">����憿批��</h5> @@ -30,7 +28,6 @@ </el-row> <ConsultantList :agents="consultantList.slice(0, 3)" - @removeAgent="removeAgent" ></ConsultantList> <div class='pam-recommend pb-30 pt-30'> <h5 class="mdTxt">��靽憿批��</h5> @@ -42,11 +39,8 @@ </template> <script lang="ts"> -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'; +import { Vue, Component, State, Action, Watch } from 'nuxt-property-decorator'; +import { Consultants } from '~/assets/ts/api/consultant'; @Component({ layout: 'home' @@ -57,57 +51,26 @@ @State('recommendList') recommendList!: Consultants[]; @Action storeRecommendList!: any; + @State('myConsultantList') myConsultantList!: Consultants[]; + @Action storeConsultantList!: any; + + @Watch('myConsultantList') + onMyConsultantListChange() { + this.consultantList = (this.myConsultantList || []) + .filter(item => item.contactStatus !== 'contacted') + .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1) + } + mounted() { - if (!this.recommendList) { + if (!this.recommendList?.length) { 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'); - } + this.storeConsultantList(); } 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) - } - } - - // TODO: ��TP隤����� ���蝙� - login() { - const user = { - username: "user", - password: "user" - } - login(user).then((res) => { - localStorage.setItem('id_token', res.data.id_token); - this.$router.go(0); - }) - } - - // TODO: ��TP隤����� ���蝙� - remove() { - localStorage.removeItem('id_token'); - this.$router.go(0) } } @@ -157,7 +120,7 @@ background-image: url('~/assets/images/recommendConsultant/banner_mob.svg'); } - @media (min-width: 576px) and (max-width: 1023px) { + @media (min-width: 576px) and (max-width: 768px) { .quickFilter.el-button--default { background-image: url('~/assets/images/quickFilter/banner_web.svg'); } -- Gitblit v1.8.0