From 9bdb95c9e34cef640534e5e5a1e2225a80442000 Mon Sep 17 00:00:00 2001 From: HelenHuang <LinHuang@pollex.com.tw> Date: 星期四, 09 六月 2022 15:48:15 +0800 Subject: [PATCH] TODO#139894 [ footer -最下方說明與保經代合作 ] 文案修改 --- PAMapp/pages/myConsultantList.vue | 140 ++++++++++++++++++++++++++++++---------------- 1 files changed, 92 insertions(+), 48 deletions(-) diff --git a/PAMapp/pages/myConsultantList.vue b/PAMapp/pages/myConsultantList.vue index 81b6e3a..6914ee7 100644 --- a/PAMapp/pages/myConsultantList.vue +++ b/PAMapp/pages/myConsultantList.vue @@ -4,14 +4,14 @@ <div class="cus-tab-item" :class="{'is-active': activeTabName === 'consultantList'}" - @click="tabClick('consultantList')" + @click="clickTab('consultantList')" >憿批�� <span class="p">({{consultantList.length}})</span> </div> <div class="cus-tab-item" :class="{'is-active': activeTabName === 'contactedList'}" - @click="tabClick('contactedList')" + @click="clickTab('contactedList')" >撌脰蝯� <span class="p">({{contactedList.length}})</span> </div> @@ -20,64 +20,108 @@ <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 { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant'; -import { Consultants, getFavoriteConsultant } from '~/assets/ts/api/consultant'; -import { isLogin } from '~/assets/ts/auth'; +import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator'; + +import authService from '~/shared/services/auth.service'; +import { Consultant, ConsultantWithAppointmentId } from '~/shared/models/consultant.model'; @Component export default class myConsultantList extends Vue { - activeTabName = 'consultantList'; - agents: Consultants[] = []; - contactedList: Consultants[] = []; - consultantList: Consultants[] = []; - tabClick(path: string) { + @State('myConsultantList') + myConsultantList!: Consultant[]; + + @State('myAppointmentGroupByConsultantList') + myAppointmentGroupByConsultantList!: ConsultantWithAppointmentId[]; + + @Action + storeConsultantList!: any; + + activeTabName : string = 'consultantList'; + consultantList: Consultant[] = []; + contactedList : ConsultantWithAppointmentId[] = []; + + ////////////////////////////////////////////////////////////////////// + + beforeRouteEnter(to: any, from: any, next: any) { + next((vm: any) => { + if (to.name === 'myConsultantList') { + vm.$router.push('myConsultantList/consultantList'); + return; + } + }) + } + + mounted() { + this.storeConsultantList(); + + if (this.$route.name) { + this.activeTabName = this.$route.name.split('-')[1] + } + } + + ////////////////////////////////////////////////////////////////////// + + @Watch('myConsultantList') + onMyConsultantListChange() { + this.setList(); + } + + @Watch('myAppointmentGroupByConsultantList') + omMyAppointmentGroupByConsultantList() { + this.setContactedList(); + } + + private setList() { + + // format consultant list + this.consultantList = (this.myConsultantList || []) + .filter(item => item.contactStatus !== 'contacted') + .map((item) => ({ ...item, formatDate: new Date(item.updateTime || item.createTime)})) + .sort((preItem, nextItem) => +nextItem.formatDate - +preItem.formatDate ); + } + + private setContactedList() { + // reset contacted list + this.contactedList = []; + + if (authService.isUserLogin()) { + this.myAppointmentGroupByConsultantList.filter((consultant) => consultant.appointments!.length) + .forEach((consultant) => { + consultant.appointments!.forEach((appointment) => { + const consultantWithAppointmentId: ConsultantWithAppointmentId = { + ...consultant, + appointmentId: appointment.id, + appointmentDate: appointment.appointmentDate, + appointmentScore: appointment.satisfactionScore, + appointmentStatus: appointment.communicateStatus, + appointmentLastModifiedDate: appointment.lastModifiedDate + }; + this.contactedList.push(consultantWithAppointmentId); + }) + }); + + this.contactedList = this.contactedList + .filter((appointment) => appointment['appointmentStatus'] !== 'reserved') + .map((appointment) => ({ ...appointment, sortTime: new Date(appointment.appointmentLastModifiedDate)})) + .sort((preAppointment, nextAppointment) => +nextAppointment.sortTime - +preAppointment.sortTime); + } + } + + ////////////////////////////////////////////////////////////////////// + + clickTab(path: string) { this.activeTabName = path; this.$router.push('/myConsultantList/' + this.activeTabName) } - async asyncData(context: Context) { - let agents: Consultants[] = []; - let contactedList: Consultants[] = []; - let consultantList: Consultants[] = []; - - if (isLogin()) { - await getFavoriteConsultant().then((response) => agents = response.data); - } else { - agents = getFavoriteFromStorage(); - } - - contactedList = agents.filter(item => item.contactStatus === 'contacted'); - consultantList = agents.filter(item => item.contactStatus !== 'contacted'); - - return { - agents, - contactedList, - consultantList - } - } - - removeAgent(agentNo: string) { - const fintIndex = this.consultantList.findIndex(item => item.agentNo === agentNo); - this.consultantList.splice(fintIndex, 1); - if (!isLogin()) { - setFavoriteToStorage(this.consultantList); - } - } - - @Watch('$route') watchRouter(currentRoute: Route) { - const pathArray = currentRoute.fullPath.split('/'); - this.activeTabName = pathArray[pathArray.length - 1]; - } } -</script> \ No newline at end of file +</script> + -- Gitblit v1.9.3