保誠-保戶業務員媒合平台
Mila
2021-12-29 cc663139f6abd63f7deac4739b63db754baf595c
PAMapp/pages/myAppointmentList.vue
@@ -1,64 +1,179 @@
<template>
    <div>
        <div class="pam-cus-tabs mb-30">
            <div
                class="cus-tab-item"
                :class="{'is-active': activeTabName === 'appointmentList'}"
                @click="tabClick('appointmentList')"
            >客戶預約
                <span class="p">({{appointmentList.length}})</span>
        <div class="pam-myAppointment-banner"></div>
        <div class="pam-container">
            <div class="pam-cus-tabs mb-30">
                <div
                    class="cus-tab-item"
                    :class="{'is-active': activeTabName === 'appointmentList'}"
                    @click="clickTab('appointmentList')"
                >客戶預約
                    <span class="p">({{appointmentList.length}})</span>
                </div>
                <div
                    class="cus-tab-item"
                    :class="{'is-active': activeTabName === 'contactedList'}"
                    @click="clickTab('contactedList')"
                >已聯絡
                    <span class="p">({{contactedList.length}})</span>
                </div>
            </div>
            <div
                class="cus-tab-item"
                :class="{'is-active': activeTabName === 'contactedList'}"
                @click="tabClick('contactedList')"
            >已聯絡
                <span class="p">({{contactedList.length}})</span>
            </div>
            <NuxtChild keep-alive></NuxtChild>
        </div>
        <NuxtChild
            :contactedList="contactedList"
            :appointmentList="appointmentList"
        ></NuxtChild>
        <!-- DIALOG -->
        <PopUpFrame
             :isOpen.sync="showNewAppointmentHint"
        >
            <div class="text--center mdTxt">
                <p class="mb-50">你有 <span class="text--primary">{{ newAppointmentSum }}</span> 則新的預約</p>
                <div class="text--center">
                    <el-button
                        type="primary"
                        @click="showNewAppointmentHint = false"
                    >我知道了</el-button>
                </div>
            </div>
        </PopUpFrame>
    </div>
</template>
<script lang="ts">
import { Context } from '@nuxt/types';
import { Vue, Component } from 'nuxt-property-decorator';
import { ClientInfo, getMyAppointmentList } from '~/assets/ts/api/appointment';
import { Vue, Component, State, Action, Watch, namespace } from 'nuxt-property-decorator';
@Component
import * as _ from 'lodash';
import { ClientInfo } from '~/shared/models/client.model';
const localStorage = namespace('localStorage');
@Component({
    layout: 'home',
    middleware: 'myAppointment'
})
export default class ClientReservedList extends Vue {
    activeTabName = 'appointmentList';
    appointmentList: ClientInfo[] = [];
    contactedList: ClientInfo[] = [];
    clients: ClientInfo[] = [];
    async asyncData(context: Context) {
        let appointmentList: ClientInfo[] = [];
        let contactedList: ClientInfo[] = [];
        let clients: ClientInfo[] = [];
        await getMyAppointmentList().then((res: any) => clients = res.data)
    @State('myAppointmentList')
    myAppointmentList!: ClientInfo[];
        contactedList = clients
            .filter(item => item.communicateStatus === 'contacted')
            .sort((a, b) => a.appointmentDate > b.appointmentDate ? -1 : 1);
        appointmentList = clients
            .filter(item => item.communicateStatus === 'reserved')
            .sort((a, b) => a.appointmentDate > b.appointmentDate ? -1 : 1);;
    @State('myNewAppointmentSum')
    newAppointmentSum!: number;
        return {
            clients,
            contactedList,
            appointmentList
    @Action
    storeMyAppointmentList!: () => Promise<number>;
    @localStorage.Mutation
    storageClearAppointmentIdFromMsg!: () => void;
    @localStorage.Getter
    currentAppointmentIdFromMsg!: string;
    activeTabName         : string       = 'appointmentList';
    appointmentList       : ClientInfo[] = [];
    clients               : ClientInfo[] = [];
    contactedList         : ClientInfo[] = [];
    showNewAppointmentHint: boolean      = false;
    //////////////////////////////////////////////////////////////////////
    mounted() {
      this.storeMyAppointmentList();
    }
    destroyed() {
        this.storageClearAppointmentIdFromMsg();
    }
    //////////////////////////////////////////////////////////////////////
    @Watch('myAppointmentList')
    onMyAppointmentListChange(): void {
        this.contactedList = this.myAppointmentList
            .filter(item => item.communicateStatus === 'contacted');
        this.appointmentList = this.myAppointmentList
            .filter(item => item.communicateStatus !== 'contacted');
        if (this.currentAppointmentIdFromMsg) {
            this.redirectAppointmentStatus();
        }
    }
    tabClick(path: string) {
        this.activeTabName = path;
        this.$router.push('/myAppointmentList/' + this.activeTabName)
    private redirectAppointmentStatus() {
        const currentAppointmentIndex = this.myAppointmentList
            .findIndex(item => item.id === +this.currentAppointmentIdFromMsg);
        if (currentAppointmentIndex > -1) {
            const communicateStatus = this.myAppointmentList[currentAppointmentIndex].communicateStatus;
            const pathName = communicateStatus === 'reserved' ? 'appointmentList' : 'contactedList';
            this.$router.push(
                {
                    path: '/myAppointmentList/' + pathName,
                    query: {appointmentId: this.currentAppointmentIdFromMsg}
                }
            );
        }
    };
    @Watch('newAppointmentSum')
    newAppointmentSumChange(): void {
      this.showNewAppointmentHint = this.newAppointmentSum > 0;
    }
    @Watch('$route')
    onRouteChange() {
        const routeFullName = this.$route.name;
        if (routeFullName) {
            this.activeTabName = routeFullName.split('-')[1];
        }
    }
    //////////////////////////////////////////////////////////////////////
    clickTab(path: string): void {
      this.activeTabName = path;
      this.$router.push(`/myAppointmentList/${this.activeTabName}`);
    }
    get bannerClassName() {
      const routeName = this.$route.name || '';
      return this.routeFormatBannerClass(routeName);
    };
    // format to {page}-banner or pam-no-banner tag
    private routeFormatBannerClass(route: string): string {
        const needBannerTags = ['myAppointmentList-appointmentList', 'myAppointmentList-contactedList'];
        return _.includes(needBannerTags, route) ? route + '-banner' : 'pam-no-banner';
    };
}
</script>
</script>
<style lang="scss" scoped>
    .pam-myAppointment-banner {
        width              : 100%;
        height             : 120px;
        background-size    : cover;
        background-repeat  : no-repeat;
        background-position: center;
        position           : relative;
        background-image   : url('~/assets/images/myAppointmentList/agent_banner_mob.svg');
    }
    @media (min-width: 768px) {
        .pam-myAppointment-banner {
            background-image: url('~/assets/images/myAppointmentList/agent_banner_web.svg');
        }
    }
    .pam-container {
        margin: 30px 20px;
    }
    @include desktop {
        .pam-container {
            width: 700px;
            margin: 30px auto;
        }
    }
</style>