From 1592d266eb7cea3a096c17d4ae3c0d01c679da7b Mon Sep 17 00:00:00 2001
From: Mila <Mila@pollex.com.tw>
Date: 星期五, 21 一月 2022 16:15:01 +0800
Subject: [PATCH] update: TODO#134585 串接 顧問主動發送滿意度 API

---
 PAMapp/components/Interview/InterviewAdd.vue |   84 ++++++++++++++++++++----------------------
 1 files changed, 40 insertions(+), 44 deletions(-)

diff --git a/PAMapp/components/Interview/InterviewAdd.vue b/PAMapp/components/Interview/InterviewAdd.vue
index e1227bc..e2d695f 100644
--- a/PAMapp/components/Interview/InterviewAdd.vue
+++ b/PAMapp/components/Interview/InterviewAdd.vue
@@ -1,6 +1,6 @@
 <template>
   <div class="edit-appointment-record">
-      <div class="edit-appointment-record-date" v-if="interviewId">
+      <div class="edit-appointment-record-date" v-if="interviewId && interviewRecord">
           <span>{{interviewRecord.createdDate | formatDate}} 撱箇��</span>
           <span>{{interviewRecord.lastModifiedDate | formatDate}} ��</span>
       </div>
@@ -85,25 +85,26 @@
 
       <InterviewMsg
         :isVisible.sync="showInterviewMsgPopup"
+        :client="appointmentDetail"
         @closeDialog="closePopup"
       ></InterviewMsg>
   </div>
 </template>
 <script lang="ts">
-import { InterviewRecord, InterviewRecordInfo } from '~/shared/models/appointment.model';
-import { Vue, Component, Prop, State, Mutation, Watch, Action } from 'nuxt-property-decorator';
+import { Appointment, InterviewRecord, InterviewRecordInfo } from '~/shared/models/appointment.model';
+import { Vue, Component, Watch, namespace } from 'nuxt-property-decorator';
 import appointmentService from '~/shared/services/appointment.service';
+
+const appointmentStore = namespace('appointment.store');
 
 @Component
 export default class InterviewAdd extends Vue {
-    @State
-    interviewRecord!: InterviewRecord;
 
-    @Mutation
-    updateInterviewRecord!: (data: InterviewRecord) => void;
+    @appointmentStore.State
+    appointmentDetail!: Appointment;
 
-    @Mutation
-    clearInterviewRecord!: () => void;
+    @appointmentStore.Action
+    updateAppointmentDetail!: (id: number) => Appointment;
 
     interviewTime = '';
     content = '';
@@ -119,40 +120,31 @@
     showInterviewMsgPopup = false;
     showFutureDateConfirmPopup = false;
 
-    defaultValue!: Date;
+    defaultValue = '';
+
+    interviewRecord!: InterviewRecord;
 
     ////////////////////////////////////////////////////////////////////
 
     mounted() {
         this.interviewId = this.$route.params.interviewId;
         this.appointmentId = this.$route.params.appointmentId;
-        const isEditPage = this.interviewId && this.interviewRecord;
-        if (isEditPage) {
-            this.checkInterviewRecord();
-        }
-    }
 
-    private checkInterviewRecord() {
-        if (this.interviewRecord.appointmentId !== +this.appointmentId
-                || this.interviewRecord.id !== +this.interviewId) {
-            appointmentService.getAppointmentDetail(+this.appointmentId).then((data) => {
-                const currentInterviewRecord = data.interviewRecordDTOs.filter(item => item.id === +this.interviewId)[0];
-                this.updateInterviewRecord(currentInterviewRecord);
-            })
-        }
-    }
-
-    destroyed() {
-        this.clearInterviewRecord();
+        this.onAppointmentDetailChange();
     }
 
     ////////////////////////////////////////////////////////////////////
 
-    @Watch('interviewRecord', {immediate: true})
-    watchInterviewRecord() {
-        if (this.interviewRecord && this.interviewRecord.content) {
-            this.content = this.interviewRecord.content;
-            this.defaultValue = new Date(this.interviewRecord.interviewDate);
+    @Watch('appointmentDetail', {immediate: true})
+    onAppointmentDetailChange() {
+        if (this.appointmentDetail && this.appointmentDetail.id === +this.appointmentId) {
+            this.interviewRecord = this.appointmentDetail.interviewRecordDTOs
+                .filter(item => item.id === +this.interviewId)[0];
+
+                if (this.interviewRecord && this.interviewId) {
+                    this.content = this.interviewRecord.content;
+                    this.defaultValue = this.interviewRecord.interviewDate;
+                }
         }
     }
 
@@ -177,19 +169,20 @@
 
     private createdRecord(interviewRecordInfo) {
         appointmentService.createInterviewRecord(interviewRecordInfo).then(res => {
-            this.confirmTxt = '�憓���'
-            this.showPopUp();
+            this.showPopUp('�憓���');
         });
     }
 
     private updateRecord(updateInterviewRecord) {
         appointmentService.updateInterviewRecord(updateInterviewRecord).then(res => {
-            this.confirmTxt = '蝺刻摩����';
-            this.showPopUp();
+            this.showPopUp('蝺刻摩����');
         });
     }
 
-    private showPopUp() {
+    private showPopUp(confirmTxt) {
+        this.confirmTxt = confirmTxt;
+        this.updateAppointmentDetail(+this.appointmentId);
+
         if (new Date(this.interviewTime).getTime() >= new Date().getTime()) {
             this.showFutureDateConfirmPopup = true;
         } else {
@@ -197,32 +190,35 @@
         }
     }
 
-    closePopup() {
-        this.$router.push(`/appointment/${this.appointmentId}`);
-    }
-
     deleteInterviewRecord() {
         appointmentService.deleteInterviewRecord(this.interviewId).then(res => {
             this.confirmTxt = '������';
             this.showConfirmPopup = true;
+            this.updateAppointmentDetail(+this.appointmentId);
         });
     }
 
     cancel() {
         if (this.interviewId) {
            this.content = this.interviewRecord.content;
-           this.defaultValue = new Date(this.interviewRecord.interviewDate);
+           this.defaultValue = this.interviewRecord.interviewDate;
            this.isEdit = false;
         } else {
-           this.$router.push(`/appointment/${this.appointmentId}`);
+           this.$router.go(-1);
         }
+    }
+
+    closePopup() {
+        this.$router.go(-1);
     }
 
     ////////////////////////////////////////////////////////////////////
 
     get formatInterviewDate() {
         const interviewDate = new Date(this.interviewRecord.interviewDate);
-        return `${interviewDate.getFullYear()}/${interviewDate.getMonth() + 1}/${interviewDate.getDate()} ${interviewDate.getHours()}:${interviewDate.getMinutes()}`;
+        const hours = interviewDate.getHours();
+        const minutes = interviewDate.getMinutes();
+        return `${interviewDate.getFullYear()}/${interviewDate.getMonth() + 1}/${interviewDate.getDate()} ${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}`;
     }
 
 }

--
Gitblit v1.8.0