保誠-保戶業務員媒合平台
HelenHuang
2021-12-06 1076fdc06d40646d1d6f125a3ce4d43cf4eac673
PAMapp/pages/myConsultantList.vue
@@ -1,6 +1,6 @@
<template>
    <div>
        <div class="flex mb-30">
        <div class="pam-cus-tabs mb-30">
            <div
                class="cus-tab-item"
                :class="{'is-active': activeTabName === 'consultantList'}"
@@ -20,80 +20,50 @@
        <NuxtChild
            :contactedList="contactedList"
            :consultantList="consultantList"
            @remove="removeAgent"
        ></NuxtChild>
    </div>
</template>
<script lang='ts'>
import { Context } from '@nuxt/types';
import { Vue, Component, Watch } from 'vue-property-decorator';
import { Route } from 'vue-router/types/router.d'
import { Agents } from '~/plugins/api/home';
import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator';
import { Consultant } from '~/assets/ts/models/consultant.model';
@Component
export default class myConsultantList extends Vue {
    activeTabName = 'consultantList';
    agents: Agents[] = [];
    contactedList: Agents[] = [];
    consultantList: Agents[] = [];
    agents: Consultant[] = [];
    contactedList: Consultant[] = [];
    consultantList: Consultant[] = [];
    @State('myConsultantList') myConsultantList!: Consultant[];
    @Action storeConsultantList!: any;
    @Watch('myConsultantList')
    onMyConsultantListChange() {
        this.filterContactedList();
    }
    tabClick(path: string) {
        this.activeTabName = path;
        this.$router.push('/myConsultantList/' + this.activeTabName)
    }
    async asyncData(context: Context) {
        let agents: Agents[] = [];
        let contactedList: Agents[] = [];
        let consultantList: Agents[] = [];
    mounted() {
        this.storeConsultantList();
        await context.$service.home.recommendConsultantList().then((result: Agents[]) => {
            agents = result;
        })
        contactedList = agents.filter(item => item.contactStatus === 'contacted');
        consultantList = agents.filter(item => item.contactStatus !== 'contacted');
        return {
            agents,
            contactedList,
            consultantList
        if (this.$route.name) {
         this.activeTabName = this.$route.name.split('-')[1]
        }
    }
    removeAgent(agentNo: number) {
        const fintIndex = this.consultantList.findIndex(item => item.agentNo === agentNo);
        this.consultantList.splice(fintIndex, 1);
    }
    @Watch('$route') watchRouter(currentRoute: Route) {
        const pathArray = currentRoute.fullPath.split('/');
        this.activeTabName = pathArray[pathArray.length - 1];
    filterContactedList() {
        this.consultantList = (this.myConsultantList || [])
                .filter(item => item.contactStatus !== 'contacted')
                .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1);
        this.contactedList = (this.myConsultantList || [])
                .filter(item => item.contactStatus === 'contacted')
                .sort((a, b) => a.updateTime > b.updateTime ? -1 : 1);
    }
}
</script>
<style lang="scss" scoped>
    .flex {
        display: flex;
        width: 100%;
        height: 45px;
        .cus-tab-item {
            width: 50%;
            text-align: center;
            font-size: 24px;
            border-bottom: solid 3px $LIGHT_GREY;
            cursor: pointer;
        }
        .is-active {
            font-weight: bold;
            border-bottom: solid 3px $PRIMARY_BLACK;
        }
    }
</style>
</script>