保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
PAMapp/pages/myConsultantList.vue
@@ -21,30 +21,31 @@
            :contactedList="contactedList"
            :consultantList="consultantList"
        ></NuxtChild>
    </div>
</template>
<script lang='ts'>
import { Vue, Component, Watch, State, Action } from 'nuxt-property-decorator';
import { Consultant, ConsultantWithAppointmentId } from '~/assets/ts/models/consultant.model';
import authService from '~/shared/services/auth.service';
import { Consultant, ConsultantWithAppointmentId } from '~/shared/models/consultant.model';
@Component
export default class myConsultantList extends Vue {
    activeTabName = 'consultantList';
    consultantList: Consultant[] = [];
    contactedList: ConsultantWithAppointmentId[] = [];
    @State('myConsultantList')
    myConsultantList!: Consultant[];
    @State('myAppointmentGroupByConsultantList')
    myAppointmentGroupByConsultantList!: ConsultantWithAppointmentId[];
    @Action
    storeConsultantList!: any;
    @Watch('myConsultantList')
    onMyConsultantListChange() {
        this.setList();
    }
    activeTabName : string                        = 'consultantList';
    consultantList: Consultant[]                  = [];
    contactedList : ConsultantWithAppointmentId[] = [];
    //////////////////////////////////////////////////////////////////////
@@ -67,45 +68,59 @@
    //////////////////////////////////////////////////////////////////////
    @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)
    }
    //////////////////////////////////////////////////////////////////////
    private setList() {
      // reset contacted list
        this.contactedList = [];
      // 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 );
      // format contacted list
        this.myConsultantList.filter((consultant) => consultant.appointments!.length)
          .forEach((consultant) => {
            const hasAppointment = consultant.appointments?.length;
            if (hasAppointment) {
              consultant.appointments!.forEach((appointment) => {
                const consultantWithAppointmentId: ConsultantWithAppointmentId = {
                  ...consultant,
                  appointmentId: appointment.id,
                  appointmentDate: appointment.appointmentDate,
                  appointmentScore: appointment.satisfactionScore
                };
                this.contactedList.push(consultantWithAppointmentId);
              })
            }
          });
        this.contactedList = this.contactedList
          .filter((appointment) => appointment['contactStatus'] === 'contacted')
          .map((appointment) => ({ ...appointment, sortTime: new Date(appointment.appointmentDate)}))
          .sort((preAppointment, nextAppointment) => +nextAppointment.sortTime - +preAppointment.sortTime);
    }
}
</script>