保誠-保戶業務員媒合平台
Mila
2021-12-22 bdae23a40c461c2c6b6ee614f661eac731c949c8
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
<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="'reservedList'"
        ></ClientList>
 
        <UiPagination
            :totalList="filterList"
            @changePage="changePage"
        ></UiPagination>
    </div>
</template>
 
<script lang="ts">
import { Vue, Component, State, Watch } from 'nuxt-property-decorator';
 
import { ClientInfo } from '~/shared/models/client.model';
 
@Component
export default class ClientReservedList extends Vue {
 
    @State('myAppointmentList')
    myAppointmentList!: ClientInfo[];
 
    appointmentList: ClientInfo[] = [];
    pageList: ClientInfo[] = [];
    keyWord: string = '';
    filterList: ClientInfo[] = [];
 
    //////////////////////////////////////////////////////////////////////
 
    mounted() {
        this.onMyAppointmentListChange();
    }
 
    //////////////////////////////////////////////////////////////////////
 
    @Watch('myAppointmentList')
    onMyAppointmentListChange(): void {
      const unViewList = this.myAppointmentList
          .filter((item) => item.communicateStatus !== 'contacted' && !item.consultantViewTime)
          .map((item) => ({ ...item, sortTime: new Date(item.appointmentDate)}))
          .sort((preItem, nextItem) => +nextItem.sortTime - +preItem.sortTime);
 
      const tempViewList = this.myAppointmentList
          .filter(item => item.communicateStatus !== 'contacted' && item.consultantViewTime);
 
      // TODO: 後續如需針對 unreadList 做更細緻的排序,則需請後端提供判斷依據(例如: createTime)。[Tomas, 2021/12/16];å
      const unreadList = tempViewList.filter((item) => !item.consultantReadTime);
      const readList = tempViewList
                    .filter((item) => item.consultantReadTime)
                    .map((item) => ({ ...item, sortTime: new Date(item.consultantReadTime)}))
                    .sort((preItem, nextItem) => +nextItem - +preItem);
 
      this.appointmentList = [...unViewList, ...unreadList, ...readList];
      this.filterList = this.appointmentList;
    }
 
    search(): void {
        this.filterList = this.appointmentList.filter(item => {
            return item.name.match(this.keyWord) || item.requirement.match(this.keyWord)
        })
    }
 
    changePage(pageList: ClientInfo[]): void {
        this.pageList = pageList;
    }
 
}
</script>