| | |
| | | <NuxtChild |
| | | :contactedList="contactedList" |
| | | :consultantList="consultantList" |
| | | @remove="removeAgent" |
| | | ></NuxtChild> |
| | | </div> |
| | | </template> |
| | | |
| | | <script lang='ts'> |
| | | import { Vue, Component, Watch } from 'vue-property-decorator'; |
| | | import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator'; |
| | | import { Route } from 'vue-router/types/router.d' |
| | | import { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant'; |
| | | import { addFavoriteConsultant, Consultants, deleteConsultant, getFavoriteConsultant } from '~/assets/ts/api/consultant'; |
| | | import { isLogin } from '~/assets/ts/auth'; |
| | | import { Consultants } from '~/assets/ts/api/consultant'; |
| | | |
| | | @Component |
| | | export default class myConsultantList extends Vue { |
| | |
| | | contactedList: Consultants[] = []; |
| | | consultantList: Consultants[] = []; |
| | | |
| | | @State('myConsultantList') myConsultantList!: Consultants[]; |
| | | @Action storeConsultantList!: any; |
| | | |
| | | @Watch('myConsultantList') |
| | | onMyConsultantListChange() { |
| | | this.filterContactedList(); |
| | | } |
| | | |
| | | tabClick(path: string) { |
| | | this.activeTabName = path; |
| | | this.$router.push('/myConsultantList/' + this.activeTabName) |
| | | } |
| | | |
| | | mounted() { |
| | | if (isLogin()) { |
| | | this.addFavoriteFromStorageToApi(); |
| | | } else { |
| | | this.agents = getFavoriteFromStorage(); |
| | | this.filterContactedList() |
| | | } |
| | | } |
| | | |
| | | addFavoriteFromStorageToApi() { |
| | | const agentNoList = getFavoriteFromStorage().map(i => i.agentNo) |
| | | if (agentNoList.length > 0) { |
| | | addFavoriteConsultant(agentNoList).then(res => this.getMyConsutant()); |
| | | localStorage.removeItem('favoriteConsultant'); |
| | | return; |
| | | } |
| | | this.getMyConsutant(); |
| | | } |
| | | |
| | | getMyConsutant() { |
| | | getFavoriteConsultant().then((response) => { |
| | | this.agents = response.data; |
| | | this.filterContactedList(); |
| | | }); |
| | | this.storeConsultantList(); |
| | | } |
| | | |
| | | filterContactedList() { |
| | | this.consultantList = this.agents |
| | | this.consultantList = (this.myConsultantList || []) |
| | | .filter(item => item.contactStatus !== 'contacted') |
| | | .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1); |
| | | this.contactedList = this.agents |
| | | this.contactedList = (this.myConsultantList || []) |
| | | .filter(item => item.contactStatus === 'contacted') |
| | | .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1); |
| | | } |
| | | |
| | | removeAgent(agentNo: string) { |
| | | if (!isLogin()) { |
| | | const fintIndex = this.consultantList.findIndex(item => item.agentNo === agentNo); |
| | | this.consultantList.splice(fintIndex, 1); |
| | | setFavoriteToStorage(this.consultantList); |
| | | } else { |
| | | deleteConsultant(agentNo).then(res => this.$router.go(0)) |
| | | } |
| | | } |
| | | |
| | | @Watch('$route') watchRouter(currentRoute: Route) { |