| | |
| | | </el-row> |
| | | <ConsultantList |
| | | :agents="consultantList.slice(0, 3)" |
| | | @removeAgent="removeAgent" |
| | | ></ConsultantList> |
| | | <div class='pam-recommend pb-30 pt-30'> |
| | | <h5 class="mdTxt">推薦保險顧問</h5> |
| | |
| | | </template> |
| | | |
| | | <script lang="ts"> |
| | | import { Vue, Component, State, Action } from 'nuxt-property-decorator'; |
| | | import { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant'; |
| | | import { addFavoriteConsultant, Consultants, deleteConsultant } 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' |
| | |
| | | @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(); |
| | | } else { |
| | | this.consultantList = getFavoriteFromStorage(); |
| | | } |
| | | } |
| | | |
| | | getMyConsutant() { |
| | | getFavoriteConsultant().then((response) => { |
| | | this.consultantList = response.data |
| | | .filter(item => item.contactStatus !== 'contacted') |
| | | .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1) |
| | | }); |
| | | } |
| | | |
| | | addFavoriteFromStorageToApi() { |
| | | const agentNoList = getFavoriteFromStorage().map(i => i.agentNo) |
| | | if (agentNoList.length > 0) { |
| | | addFavoriteConsultant(agentNoList).then(res => this.getMyConsutant()); |
| | | localStorage.removeItem('favoriteConsultant'); |
| | | return; |
| | | } |
| | | this.getMyConsutant(); |
| | | this.storeConsultantList(); |
| | | } |
| | | |
| | | routerPush(path: string) { |
| | | this.$router.push(path); |
| | | } |
| | | |
| | | removeAgent(agentNo: string) { |
| | | |
| | | if (!isLogin()) { |
| | | const findIndex = this.consultantList.findIndex((item, i) => { |
| | | return item.agentNo === agentNo; |
| | | }) |
| | | this.consultantList.splice(findIndex, 1); |
| | | setFavoriteToStorage(this.consultantList) |
| | | } else { |
| | | deleteConsultant(agentNo).then(res => this.$router.go(0)) |
| | | } |
| | | } |
| | | } |
| | | |
| | | </script> |