From ae4db5435180c44b37f521c463b17f2023ac1d8c Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期五, 18 二月 2022 09:25:50 +0800
Subject: [PATCH] [update] 若顧問停用時,將無法登入 (文案待確認)

---
 PAMapp/pages/myAppointmentList/contactedList.vue |  129 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 107 insertions(+), 22 deletions(-)

diff --git a/PAMapp/pages/myAppointmentList/contactedList.vue b/PAMapp/pages/myAppointmentList/contactedList.vue
index 15954b7..5be7e6f 100644
--- a/PAMapp/pages/myAppointmentList/contactedList.vue
+++ b/PAMapp/pages/myAppointmentList/contactedList.vue
@@ -5,60 +5,145 @@
             placeholder="隢撓���摮�"
             class="mb-30 pam-clientReserved-input"
             v-model="keyWord"
-            @keyup.enter.native="search"
+            @input="search"
         >
             <i
                 slot="suffix"
                 class="icon-search search cursor--pointer"
-                @click="search"
             ></i>
         </el-input>
+
+        <div class="mb-10 sort-indicator-container">
+          <a class="sort-indicator cursor--pointer" @click="changeSortType">
+            {{ this.sortType === 'DESC' ? '�->���' : '���->�' }}
+            <i v-if="isSortType" class="icon-sort-add"></i>
+            <i v-else class="icon-sort-decrease"></i>
+          </a>
+        </div>
 
         <ClientList
             :clients="pageList"
             :title="'contactedList'"
+            class="mt-10"
         ></ClientList>
 
         <UiPagination
+            v-if="togglePagination"
             :totalList="filterList"
+            :currentPage="currentPage"
             @changePage="changePage"
         ></UiPagination>
     </div>
 </template>
 
 <script lang="ts">
-import { Vue, Component, Watch, State } from 'nuxt-property-decorator';
-import { ClientInfo } from '~/assets/ts/api/appointment';
+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 {
-    @State('myAppointmentList') myAppointmentList!: ClientInfo[];
 
-    contactedList: ClientInfo[] = [];
-    pageList: ClientInfo[] = [];
-    keyWord: string = '';
-    filterList: ClientInfo[] = [];
+    @appointmentStore.State('myAppointmentList')
+    myAppointmentList!: Appointment[];
 
-    @Watch('myAppointmentList')
-    onMyAppointmentListChange() {
-        this.contactedList = (this.myAppointmentList || [])
-            .filter(item => item.communicateStatus === 'contacted')
-            .sort((a, b) => a.contactTime > b.contactTime ? -1 : 1);
-        this.filterList = this.contactedList;
-    }
+    @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();
     }
 
-    changePage(pageList: ClientInfo[]) {
+    //////////////////////////////////////////////////////////////////////
+
+    @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 {
+        if (this.keyWord) {
+          this.filterList = this.contactedList.filter(item => {
+              return item?.name?.match(this.keyWord) || item?.requirement?.match(this.keyWord)
+          })
+        } else {
+          this.filterList = this.contactedList;
+        }
+    }
+
+    changePage(pageList: Appointment[]): void {
         this.pageList = pageList;
     }
 
-    search() {
-        this.filterList = this.contactedList.filter(item => {
-            return item.name.match(this.keyWord) || item.requirement.match(this.keyWord)
-        })
+    changeSortType(): void {
+      if (this.sortType === 'DESC') {
+        this.sortType = 'ASC';
+      } else {
+        this.sortType = 'DESC';
+      }
     }
+
+    get isSortType () :boolean {
+      return this.sortType === 'DESC';
+    }
+
 }
-</script>
\ No newline at end of file
+</script>
+<style lang="scss" scoped>
+.sort-indicator-container{
+  margin-bottom: 20px;
+}
+.sort-indicator{
+  border-radius:30px;
+  border: 1px solid #D0D0CE;
+  background-color:#fff;
+  padding: 10px 20px;
+  color: #68737A;
+}
+</style>

--
Gitblit v1.8.0