<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>
|
|
<ClientList
|
:clients="pageList"
|
:title="'closedList'"
|
></ClientList>
|
|
<UiPagination
|
:totalList="filterList"
|
:currentPage="currentPage"
|
@changePage="changePage"
|
></UiPagination>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import { Vue, Component, Watch, State, namespace } from 'nuxt-property-decorator';
|
|
import { Appointment } from '~/shared/models/appointment.model';
|
import { ContactStatus } from '~/shared/models/enum/contact-status';
|
|
|
const localStorage = namespace('localStorage');
|
@Component
|
export default class ClientContactedList extends Vue {
|
|
@State('myAppointmentList')
|
myAppointmentList!: Appointment[];
|
|
@localStorage.Getter
|
currentAppointmentIdFromMsg!: string;
|
|
contactedList: Appointment[] = [];
|
filterList : Appointment[] = [];
|
keyWord : string = '';
|
pageList : Appointment[] = [];
|
currentPage : number = 1;
|
contactStatus= ContactStatus;
|
|
//////////////////////////////////////////////////////////////////////
|
|
mounted() {
|
this.onMyAppointmentListChange();
|
}
|
|
//////////////////////////////////////////////////////////////////////
|
|
@Watch('myAppointmentList')
|
onMyAppointmentListChange() {
|
this.contactedList = (this.myAppointmentList || [])
|
.filter(item => item.communicateStatus === this.contactStatus.DONE || item.communicateStatus === this.contactStatus.CLOSE)
|
.map((item) => ({...item, sortTime: new Date(item.contactTime)}))
|
.sort((prevItem, nextItem) => +nextItem.sortTime - +prevItem.sortTime);
|
this.filterList = this.contactedList;
|
|
this.getCurrentPage();
|
}
|
|
private getCurrentPage() {
|
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;
|
}
|
|
}
|
</script>
|