From 7ef236374431bf2a9ed74dc23e5909c6ef22932d Mon Sep 17 00:00:00 2001
From: Mila <Mila@pollex.com.tw>
Date: 星期二, 04 一月 2022 18:03:30 +0800
Subject: [PATCH] fixed TODO#133629 標註為已連絡時使用API回傳的資料

---
 PAMapp/components/Client/ClientCard.vue |  354 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 279 insertions(+), 75 deletions(-)

diff --git a/PAMapp/components/Client/ClientCard.vue b/PAMapp/components/Client/ClientCard.vue
index 1fffe7c..25c5423 100644
--- a/PAMapp/components/Client/ClientCard.vue
+++ b/PAMapp/components/Client/ClientCard.vue
@@ -1,20 +1,34 @@
 <template>
     <div>
-        <el-row type="flex" class="rowStyle" @click.native="openDetail">
-            <el-col :xs="5" :sm="3">
+        <el-row
+            type="flex"
+            ref="clientCardRef"
+            class="rowStyle cursor--pointer"
+            justify="space-between"
+            :class="{'new': newAppointment }"
+            @click.native="openDetail"
+        >
+            <el-col :xs="1" :sm="1" class="unread" align="middle" v-if="isReserved">
+                <div class="circle" v-if="!isRead"></div>
+            </el-col>
+            <el-col :xs="5" :sm="3" align="middle">
                 <el-avatar
                     :size="50"
-                    src=""
-                    class="cursor--pointer fix-chrome-click--issue"
                 ></el-avatar>
-                <!-- <div class="satisfaction">
-                    <i class="icon-star pam-icon icon--yellow satisfaction"></i>
-                    <span>{{'1'}}</span>
-                </div> -->
+                <div class="satisfaction" v-if="!hideReviews">
+                    <template v-if="client.satisfactionScore">
+                        TODO:���遛��漲
+                        <i class="icon-star pam-icon icon--yellow satisfaction"></i>
+                        <span>{{client.satisfactionScore}}</span>
+                    </template>
+                    <template v-else>
+                        <div class="unfilled">�憛急遛��漲</div>
+                    </template>
+                </div>
             </el-col>
-            <el-col :xs="14" :sm="15">
-                <div class="smTxt_bold name">{{client.name}}</div>
-                <div class="message">������</div>
+            <el-col :xs="14" :sm="14" class="pl-10">
+                <div class="smTxt_bold name">{{ client.name }}</div>
+                <div class="my-10">������</div>
                 <div class="professionals">
                     <template v-if="client.requirement">
                         <span
@@ -29,46 +43,95 @@
                     </template>
                 </div>
             </el-col>
-            <el-col class="flex-column contactInfo" :xs="5" :sm="6">
-                <div class="smTxt_bold cursor--pointer fix-chrome-click--issue"
-                    :class="client.communicateStatus"
-                >{{isReserved ? '撌脤���' : '撌脰蝯�'}}
-                </div>
-                <div class="date xsTxt text--mid_grey">{{date}}</div>
-                <div class="xsTxt text--mid_grey">{{time}}</div>
+            <el-col class="flex-column contactInfo" :xs="4" :sm="6">
+                <div
+                    class="smTxt_bold fix-chrome-click--issue"
+                    :class="{'unread-txt': reservedTxt === '�霈�', 'read-txt': reservedTxt !== '�霈�'}"
+                >{{ reservedTxt }}</div>
+                <div
+                    class="date xsTxt text--mid_grey"
+                >{{ date }}</div>
+                <div
+                    class="xsTxt text--mid_grey"
+                >{{ time }}</div>
             </el-col>
         </el-row>
 
         <Ui-Dialog
             :isVisible.sync="isVisibleDialog"
-            :width="width"
+            :width="dialogWidth"
+            @closeDialog="closeDialog"
             class="pam-myDemand-dialog"
         >
             <h5 class="subTitle text--center mb-30"
-            >{{isReserved ? '������' : '撌脰蝯∟���'}}</h5>
-            <p class="smTxt text-right">{{client.appointmentDate | formatDate}}</p>
+            >{{isReserved ? '������' : '撌脰蝯∟���'}}</h5>
+
+            <p v-if='isReserved'
+                class="smTxt text--right"
+            ><span v-if="isRead">{{client.consultantReadTime | formatDate}}</span> 撌脰�</p>
+            <p
+                v-if="!isReserved"
+                class="smTxt text--right"
+            >{{client.contactTime | formatDate}} �蝯�</p>
+            <p class="smTxt">{{client.appointmentDate | formatDate}} ����</p>
+
             <div class="dialogTxt">
-                <p>憪��{client.name}}</p>
-                <p>�閰梧�{client.phone}}</p>
-                <p>Email嚗{client.email}}</p>
-                <p>�批嚗{gender}}</p>
-                <p>撟湧翩嚗{client.age}}</p>
-                <p>�璆哨�{client.job}}</p>
-                <p>��瘙�{client.requirement.split(',').join('��')}}</p>
-                <p v-for="(item, index) in hopeContactTime" :key="index">��蝯⊥�挾{{index + 1 | formatNumber}}嚗{ item | formatHopeContactTime}}</p>
+                <p>憪���<span>{{client.name}}</span></p>
+                <p>�閰梧��<span>{{client.phone}}</span></p>
+                <p>Email嚗�<span>{{client.email}}</span></p>
+                <p>�批嚗�<span>{{gender}}</span></p>
+                <p>撟湧翩嚗�<span>{{client.age | toAgeLabel }}</span></p>
+                <p>�璆哨��<span>{{client.job}}</span></p>
+                <p>��瘙��<span>{{client.requirement.split(',').join('��')}}</span></p>
+                <p v-for="(item, index) in hopeContactTime"
+                    :key="index"
+                >��蝯⊥�挾{{index + 1 | formatNumber}}嚗�<span>{{ item | formatHopeContactTime}}</span></p>
+            </div>
+            <div class="mt-30">
+                <div class="memoTitleStyle">
+                    <div class="mdTxt">�摰寞�膩</div>
+                    <div
+                        class="smTxt text--bold text--primary cursor--pointer text--underline edit"
+                        @click='editMemo'
+                    >蝺刻摩</div>
                 </div>
-                <div class="mt-30 text--center" v-if="isReserved">
-                    <el-button @click="markAppointment">璅酉�撌脤��蝯�</el-button>
+
+                <el-input
+                    class="mt-10 pam-appointment-textarea"
+                    type="textarea"
+                    :rows="3"
+                    maxlength="100"
+                    placeholder="隢撓�嚗��100摮��"
+                    :disabled="!isEdit"
+                    v-model="memo"
+                >
+                </el-input>
+
+                <div class="mt-10 smTxt text--bold text--primary text--right fixed-Height">
+                    <template v-if="isEdit">
+                        <span class="cursor--pointer" @click="cancelEditMemo">����</span>
+                        <span class="pl-20 cursor--pointer" @click="saveMemo">�摮�</span>
+                    </template>
                 </div>
+            </div>
+            <div class="mt-30 text--center" v-if="isReserved">
+                <el-button @click="markAppointment">璅酉�撌脤��蝯�</el-button>
+            </div>
         </Ui-Dialog>
     </div>
 </template>
 
 <script lang="ts">
-import { Vue, Component, Prop, Mutation, Action } from 'nuxt-property-decorator';
-import { isMobileDevice } from '~/assets/ts/device';
-import { ClientInfo, markAsContact } from '~/assets/ts/api/appointment';
+import { Vue, Component, Prop, Action, namespace, Watch } from 'nuxt-property-decorator';
 
+import appointmentService from '~/shared/services/appointment.service';
+import UtilsService from '~/shared/services/utils.service';
+import { hideReviews } from '~/shared/const/hide-reviews';
+import { AppointmentMemoInfo, ClientInfo } from '~/shared/models/client.model';
+import myConsultantService from '~/shared/services/my-consultant.service';
+import { ElRow } from 'element-ui/types/row';
+
+const localStorage = namespace('localStorage');
 @Component({
     filters: {
         formatNumber(index: number) {
@@ -89,11 +152,58 @@
     }
 })
 export default class ClientList extends Vue {
-    @Action updateMyAppointment!: (data: ClientInfo) => void
+    @Action
+    updateMyAppointment!: (data: ClientInfo) => void;
 
-    @Prop() client!: ClientInfo;
+    @Prop()
+    client!: ClientInfo;
+
+    @localStorage.Mutation
+    storageClearAppointmentIdFromMsg!: () => void;
+
     isVisibleDialog = false;
-    width = '';
+    dialogWidth = '';
+    hideReviews = hideReviews;
+
+    isEdit = false;
+    memoInfo: AppointmentMemoInfo = {
+        appointmentId: 0,
+        content: '',
+        id: 0
+    }
+    memo = '';
+
+    //////////////////////////////////////////////////////////////////////
+
+    @Watch('$route', {immediate: true})
+    onRouteChange() {
+        const appointmentIdFromMsg = this.$route.query.appointmentId;
+        if (appointmentIdFromMsg && +appointmentIdFromMsg === this.client.id) {
+            this.openDetail();
+        }
+    }
+
+    //////////////////////////////////////////////////////////////////////
+
+    mounted() {
+        this.memoInfo = this.client.appointmentMemoList.length > 0
+            ? JSON.parse(JSON.stringify(this.client.appointmentMemoList[0]))
+            : {appointmentId: 0, content: '', id: 0};
+        this.memo = this.memoInfo.content;
+    }
+
+    get newAppointment(): boolean {
+      return !this.client.consultantViewTime
+            && this.client.communicateStatus === 'reserved';
+    }
+
+    get isReserved() {
+      return this.client.communicateStatus === 'reserved';
+    }
+
+    get isRead() {
+      return !!this.client.consultantReadTime;
+    }
 
     get requirements() {
         return this.client.requirement.split(',');
@@ -103,7 +213,7 @@
         if (this.client.gender) {
             return this.client.gender === 'male' ? '���' : '憟單��';
         }
-        return ''
+        return '';
     }
 
     get hopeContactTime() {
@@ -111,37 +221,112 @@
         return contactList.filter(item => !!item && item !== ",")
     }
 
+    get reservedTxt(): string {
+        if (this.isReserved) {
+            return this.client.consultantReadTime ? '撌脰�' : '�霈�';
+        } else {
+            return '撌脰蝯�'
+        }
+    }
+
+    get displayTime(): string {
+        if (this.isReserved) {
+            return this.client.appointmentDate;
+        } else {
+            return this.client.lastModifiedDate;
+        }
+    }
+
     get time() {
-        const formatDate = (this.$options.filters as any).formatDate(this.client.appointmentDate);
+        const formatDate = (this.$options.filters as any).formatDate(this.displayTime);
         return formatDate.split(' ')[1]
     }
 
     get date() {
-        const formatDate = (this.$options.filters as any).formatDate(this.client.appointmentDate);
-        return formatDate.split(' ')[0]
-    }
-
-    get isReserved() {
-        return this.client.communicateStatus === 'reserved';
+        const formatDate = (this.$options.filters as any).formatDate(this.displayTime);
+        return formatDate.split(' ')[0];
     }
 
     openDetail() {
-        this.width = isMobileDevice() ? '80%' : '';
+        setTimeout(() => {
+            (this.$refs.clientCardRef as any).$el.classList.add('currentShowStyle');
+        }, 0)
+        this.dialogWidth = UtilsService.isMobileDevice() ? '80%' : '';
         this.isVisibleDialog = true;
     }
 
     markAppointment() {
-        markAsContact(this.client.id).then(data => {
-            // TODO: 閬敺����� updated client 鞈�� - Ben 2021/11/16
-
-            const updatedClient = {...this.client};
-            updatedClient.communicateStatus = 'contacted';
-            updatedClient.appointmentDate = new Date();
-
-            this.updateMyAppointment(updatedClient);
+        myConsultantService.markAsContact(this.client.id).then(data => {
+            this.updateMyAppointment(data);
             this.isVisibleDialog = false;
-
         })
+    }
+
+    closeDialog(): void {
+      const unread = !this.client.consultantReadTime;
+        if (unread) {
+            appointmentService.recordRead(this.client.id).then((_) => {
+                const updatedClient = {...this.client};
+                updatedClient.consultantReadTime = new Date().toString();
+                this.updateMyAppointment(updatedClient);
+            });
+        };
+        this.isEdit = false;
+        this.clearAppointmentIdFromMsg();
+    }
+
+    private clearAppointmentIdFromMsg() {
+        this.storageClearAppointmentIdFromMsg();
+        this.$router.push({query: {}});
+        setTimeout(() => {
+            (this.$refs.clientCardRef as ElRow).$el.classList.remove('currentShowStyle')
+        },1000)
+    }
+
+    saveMemo() {
+        if (this.client.appointmentMemoList.length > 0) {
+            const params = {
+                content: this.memo,
+                id: this.client.appointmentMemoList[0].id
+            };
+            this.updateMemo(params);
+            return;
+        }
+
+        const params = {
+            content: this.memo,
+            appointmentId: this.client.id,
+        }
+        this.createMemo(params);
+    }
+
+    private createMemo(params) {
+        appointmentService.createMemo(params).then(memoRes => {
+            this.storeMemo(memoRes);
+        });
+    }
+
+    private updateMemo(params) {
+        appointmentService.updateMemo(params).then(memoRes => {
+            this.storeMemo(memoRes);
+        });
+    }
+
+    private storeMemo(memoRes) {
+        this.memoInfo = memoRes;
+        this.memo = this.memoInfo.content;
+        this.client.appointmentMemoList[0] = this.memoInfo;
+        this.isEdit = false;
+    }
+
+    editMemo() {
+        this.isEdit = !this.isEdit;
+        this.memo = this.memoInfo.content;
+    }
+
+    cancelEditMemo() {
+        this.isEdit = false;
+        this.memo = this.memoInfo.content;
     }
 
 }
@@ -149,69 +334,88 @@
 
 <style lang="scss" scoped>
     .rowStyle {
-        padding: 10px;
+        padding: 10px 15px 10px 5px;
         background-color: $PRIMARY_WHITE;
         margin-bottom: 10px;
         display: flex;
         justify-content: space-between;
-
+        transition: background-color 0.5s;
+        &.new {
+            border-left: solid 4px $YELLOW;
+        }
+        &.currentShowStyle {
+            background-color: rgba(236, 195, 178, 0.5);
+            transition: background-color 0.5s;
+        }
+        .unread {
+            align-self: center;
+            .circle {
+                width: 10px;
+                height: 10px;
+                border-radius: 50px;
+                background-color: $PRIMARY_RED;
+                margin: auto;
+            }
+        }
         .satisfaction {
             font-size: 12px;
             font-weight: bold;
             margin-top: 5px;
+            .unfilled {
+                font-weight: lighter;
+                color: $MID_GREY;
+            }
         }
-
-        .message {
-            margin:10px 0;
-        }
-
         .professionals {
             overflow: hidden;
             white-space: nowrap;
             text-overflow: ellipsis;
-
             .professionalsTxt {
                 font-size: 12px;
                 font-weight: bold;
                 margin-right: 5px;
             }
-
             .noProfessionalsTxt {
                 color: $PRUDENTIAL_GREY;
                 font-weight: lighter;
             }
         }
-
         .contactInfo {
             text-align: right;
             .date {
                 font-size: 12px;
             }
         }
-
-        .reserved {
+        .unread-txt {
             @extend .text--primary;
         }
-
-        .contacted {
+        .read-txt {
             color: $SKY_BLUE;
         }
     }
-
     .flex-column {
         display: flex;
         flex-direction: column;
         justify-content: space-between;
     }
-
     .dialogTxt {
         font-size: 20px;
         overflow-y:scroll;
-        height:400px;
+        max-height: 25vh;
+        @include desktop {
+            height: 400px;
+        }
     }
+    .memoTitleStyle {
+        display: flex;
+        flex-direction: row;
+        justify-content: space-between;
 
-
-    .text-right {
-        text-align: right;
+        .edit {
+            align-self: flex-end;
+        }
+    }
+    .fixed-Height {
+        height: 16px;
     }
 </style>

--
Gitblit v1.8.0