From abfd26bb700d93a92da6a04703b0187d4acaaeb5 Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期三, 22 十二月 2021 10:13:02 +0800 Subject: [PATCH] refactor: move ts folder to shared folder --- PAMapp/pages/myConsultantList.vue | 89 ++++++++++++++++++++++++++++++++------------ 1 files changed, 65 insertions(+), 24 deletions(-) diff --git a/PAMapp/pages/myConsultantList.vue b/PAMapp/pages/myConsultantList.vue index 62173cf..687547c 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> @@ -26,44 +26,85 @@ <script lang='ts'> import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator'; -import { Consultants } from '~/assets/ts/api/consultant'; +import { Consultant, ConsultantWithAppointmentId } from '~/shared/models/consultant.model'; @Component export default class myConsultantList extends Vue { - activeTabName = 'consultantList'; - agents: Consultants[] = []; - contactedList: Consultants[] = []; - consultantList: Consultants[] = []; - @State('myConsultantList') myConsultantList!: Consultants[]; - @Action storeConsultantList!: any; + activeTabName = 'consultantList'; + consultantList: Consultant[] = []; + contactedList: ConsultantWithAppointmentId[] = []; + + @State('myConsultantList') + myConsultantList!: Consultant[]; + + @Action + storeConsultantList!: any; + + ////////////////////////////////////////////////////////////////////// + + 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.filterContactedList(); + this.setList(); } - tabClick(path: string) { + clickTab(path: string) { this.activeTabName = path; this.$router.push('/myConsultantList/' + this.activeTabName) } - mounted() { - this.storeConsultantList(); + ////////////////////////////////////////////////////////////////////// - if (this.$route.name) { - this.activeTabName = this.$route.name.split('-')[1] - } - } + private setList() { + // reset contacted list + this.contactedList = []; - filterContactedList() { + // format consultant list 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); + .filter(item => item.contactStatus !== 'contacted') + .map((item) => ({ ...item, formatDate: new Date(item.updateTime || item.createTime)})) + .sort((preItem, nextItem) => +nextItem.formatDate - +preItem.formatDate ); + + // format contacted list + this.myConsultantList.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, + }; + this.contactedList.push(consultantWithAppointmentId); + }) + }); + + this.contactedList = this.contactedList + .filter((appointment) => appointment['appointmentStatus'] === 'contacted') + .map((appointment) => ({ ...appointment, sortTime: new Date(appointment.appointmentDate)})) + .sort((preAppointment, nextAppointment) => +nextAppointment.sortTime - +preAppointment.sortTime); } } -</script> \ No newline at end of file +</script> + -- Gitblit v1.9.3