保誠-保戶業務員媒合平台
wayne
2022-01-26 6fa4bba623713c396432ba8b863846883d6a1906
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
    <div>
        <el-input
            type="text"
            placeholder="請輸入關鍵字"
            class="mb-30 pam-clientReserved-input"
            v-model="keyWord"
            @input="search"
        >
            <i slot="suffix" class="icon-search search cursor--pointer"></i>
        </el-input>
 
        <ClientList
            :clients="pageList"
            :title="'reservedList'"
        ></ClientList>
 
        <UiPagination
            :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';
import { ContactStatus } from '~/shared/models/enum/contact-status';
 
 
const localStorage     = namespace('localStorage');
const appointmentStore = namespace('appointment.store');
@Component
export default class ClientReservedList extends Vue {
 
    @appointmentStore.State('myAppointmentList')
    myAppointmentList!: Appointment[];
 
    @localStorage.Getter
    currentAppointmentIdFromMsg!: string;
 
    @appointmentStore.Action
    getAppointmentDetail!: () => Promise<Appointment>;
 
    appointmentList: Appointment[]  = [];
    currentPage     : number        = 1;
    filterList      : Appointment[] = [];
    keyWord         : string        = '';
    pageList        : Appointment[] = [];
 
    contactStatus  = ContactStatus;
 
    //////////////////////////////////////////////////////////////////////
 
    mounted() {
        this.onMyAppointmentListChange();
    }
 
    //////////////////////////////////////////////////////////////////////
 
    @Watch('myAppointmentList')
    onMyAppointmentListChange(): void {
      this.appointmentList = this.myAppointmentList
          .filter(item => item.communicateStatus === this.contactStatus.RESERVED)
          .map((item) => ({ ...item, sortTime: new Date(item.lastModifiedDate)}))
          .sort((preItem, nextItem) => +nextItem.sortTime - +preItem.sortTime);
 
      this.filterList = this.appointmentList;
 
      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 {
        if (this.keyWord) {
            this.filterList = this.appointmentList.filter(item => {
                return item.name.match(this.keyWord) || item.requirement.match(this.keyWord);
            })
        } else {
            this.filterList = this.appointmentList;
        }
 
    }
 
    changePage(pageList: Appointment[]): void {
        this.pageList = pageList;
    }
 
}
</script>