保誠-保戶業務員媒合平台
Mila
2022-01-20 f90c94f20b5f11d3b3ce0164d619c0112d5158c9
PAMapp/pages/myAppointmentList/contactedList.vue
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,125 @@
<template>
    <div>
        <el-input
            type="text"
            placeholder="請輸入關鍵字"
            class="mb-30 pam-clientReserved-input"
            v-model="keyWord"
            @keyup.enter.native="search"
        >
            <i
                slot="suffix"
                class="icon-search search cursor--pointer"
                @click="search"
            ></i>
        </el-input>
        <div class="sort-indicator mb-10 text--primary text--underline cursor--pointer" @click="changeSortType">
          {{ this.sortType === 'DESC' ? '新->舊' : '舊->新' }}
        </div>
        <ClientList
            :clients="pageList"
            :title="'contactedList'"
        ></ClientList>
        <UiPagination
            v-if="togglePagination"
            :totalList="filterList"
            :currentPage="currentPage"
            @changePage="changePage"
        ></UiPagination>
    </div>
</template>
<script lang="ts">
import { Vue, Component, Watch, namespace } from 'nuxt-property-decorator';
import { Appointment } from '~/shared/models/appointment.model';
const appointmentStore = namespace('appointment.store');
const localStorage     = namespace('localStorage');
@Component
export default class ClientContactedList extends Vue {
    @appointmentStore.State('myAppointmentList')
    myAppointmentList!: Appointment[];
    @localStorage.Getter
    currentAppointmentIdFromMsg!: string;
    contactedList   : Appointment[]  = [];
    currentPage      : number        = 1;
    filterList       : Appointment[] = [];
    keyWord          : string        = '';
    pageList         : Appointment[] = [];
    sortType        : 'ASC' | 'DESC' = 'DESC';
    togglePagination: boolean        = true;
    //////////////////////////////////////////////////////////////////////
    mounted() {
        this.onMyAppointmentListChange();
    }
    //////////////////////////////////////////////////////////////////////
    @Watch('myAppointmentList')
    onMyAppointmentListChange() {
      this.setContactedList();
    }
    @Watch('sortType')
    onSortTypeChange() {
      this.togglePagination = false;
      setTimeout(() => {
      this.togglePagination = true;
        this.currentPage = 1;
        this.setContactedList();
      }, 0)
    }
    private setContactedList(): void {
        this.contactedList = (this.myAppointmentList || [])
            .filter(item => item.communicateStatus === 'contacted')
            .map((item) => ({...item, sortTime: new Date(item.lastModifiedDate)}))
            .sort((prevItem, nextItem) => {
              return this.sortType === 'DESC' ? +nextItem.sortTime - +prevItem.sortTime : +prevItem.sortTime - +nextItem.sortTime
            });
        this.filterList = this.contactedList;
        this.getCurrentPage();
    }
    private getCurrentPage(): void {
        const currentIndex = this.filterList.findIndex(item => item.id === +this.currentAppointmentIdFromMsg);
        const pageSize = 5;
        if (currentIndex > -1) {
            this.currentPage = Math.ceil((currentIndex + 1) / pageSize);
        }
    }
    //////////////////////////////////////////////////////////////////////
    search(): void {
        this.filterList = this.contactedList.filter(item => {
            return item?.name?.match(this.keyWord) || item?.requirement?.match(this.keyWord)
        })
    }
    changePage(pageList: Appointment[]): void {
        this.pageList = pageList;
    }
    changeSortType(): void {
      if (this.sortType === 'DESC') {
        this.sortType = 'ASC';
      } else {
        this.sortType = 'DESC';
      }
    }
}
</script>