From ea8c5302eb57600b4380e20600d61b1d115a6b53 Mon Sep 17 00:00:00 2001
From: HelenHuang <LinHuang@pollex.com.tw>
Date: 星期三, 08 十二月 2021 10:32:25 +0800
Subject: [PATCH] Merge branch 'master' of https://192.168.0.10:8443/r/pcalife/PAM

---
 PAMapp/pages/questionnaire/_agentNo.vue |  253 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 178 insertions(+), 75 deletions(-)

diff --git a/PAMapp/pages/questionnaire/_agentNo.vue b/PAMapp/pages/questionnaire/_agentNo.vue
index 547af0a..56f3a85 100644
--- a/PAMapp/pages/questionnaire/_agentNo.vue
+++ b/PAMapp/pages/questionnaire/_agentNo.vue
@@ -92,7 +92,7 @@
         <el-button type="primary"
           :disabled="isDisabledSubmitBtn"
           @click.native="sentDemand">
-          �
+          {{isEditBtn ? '��' : '�'}}
         </el-button>
       </div>
     </div>
@@ -124,20 +124,32 @@
           </el-button>
         </div>
     </PopUpFrame>
+
+    <PopUpFrame :isOpen.sync="isEditPopup">
+      <div class="text--middle mt-30 sendReserve-txt">��蝜潛�楊頛舫��嚗�</div>
+      <div class="text--center mdTxt">
+        <el-button @click="$router.go(-1)">餈��</el-button>
+        <el-button @click="isEditPopup = false" type="primary">蝺刻摩</el-button>
+      </div>
+    </PopUpFrame>
   </div>
 </template>
 
 <script lang="ts">
-  import { Vue, Component } from 'nuxt-property-decorator';
-  import { addFavoriteConsultant, appointmentDemand, AppointmentParams, AppointmentRequests ,RegisterInfo } from '~/assets/ts/api/consultant';
-  import { getRequestsFromStorage, setRequestsToStorage, getRequestQuestionFromStorage, removeRequestQuestionFromStorage  } from '~/assets/ts/storageRequests';
-  import { Gender } from '~/assets/ts/models/enum/Gender';
-  import { ContactType } from '~/assets/ts/models/enum/ContactType';
-  import _ from 'lodash';
-  import { isLogin } from '~/assets/ts/auth';
+import { Vue, Component, State, Action, Watch } from 'nuxt-property-decorator';
+import { addFavoriteConsultant, appointmentDemand, AppointmentParams, AppointmentRequests ,editAppointment,RegisterInfo } from '~/assets/ts/api/consultant';
+import { getRequestQuestionFromStorage, getRequestsFromStorage, removeRequestQuestionFromStorage, setRequestsToStorage } from '~/assets/ts/storageRequests';
+import _ from 'lodash';
+import { isLogin } from '~/assets/ts/auth';
+import { Consultant } from '~/assets/ts/models/consultant.model';
+import { ContactType } from '~/assets/ts/models/enum/ContactType';
+import { Gender } from '~/assets/ts/models/enum/Gender';
 
   @Component
   export default class Questionnaire extends Vue {
+    @State('myConsultantList') myConsultantList!: Consultant[];
+    @Action storeConsultantList!: () => Promise<number>;
+
     genderOptions=[
       {
         title:'���',
@@ -255,6 +267,10 @@
 
     showDrawer= false;
     sendReserve = false;
+    isEditPopup = false;
+    isEditBtn = false;
+
+    appointmentId = 0;
 
     beforeRouteEnter(to: any, from: any, next: any) {
       next(vm => {
@@ -267,6 +283,12 @@
           vm.$router.push('/login');
         }
       })
+    }
+
+    async fetch() {
+      if (isLogin()) {
+        await this.storeConsultantList();
+      };
     }
 
     mounted(): void {
@@ -325,7 +347,12 @@
     }
 
     sentDemand() {
-      addFavoriteConsultant([this.$route.params.agentNo]).then(res => this.sentAppointmentDemand());
+      if (this.isEditBtn) {
+        this.sentEditAppointmentDemand();
+      } else {
+        addFavoriteConsultant([this.$route.params.agentNo]).then(res => this.sentAppointmentDemand());
+      }
+
     }
 
     private sentAppointmentDemand() {
@@ -343,6 +370,21 @@
         });
     }
 
+    private sentEditAppointmentDemand() {
+      const info = {
+          ...this.myRequest,
+          requirement: _.map(this.myRequest.requirement,o=>o).toString(),
+          hopeContactTime: this.myRequest.phone && this.phoneValid ? this.getHopeContactTime() :'',
+          id: this.appointmentId,
+          otherRequirement: null
+        }
+        editAppointment(info).then(res => {
+          this.sendReserve = true;
+          this.myRequest.hopeContactTime = [];
+          setRequestsToStorage(this.myRequest);
+        });
+    }
+
     getHopeContactTime() {
         const selectedHopeContactTime = this.myRequest.hopeContactTime.filter((i) => i.selectWeekOptions?.length && i.selectTimesOptions?.length);
         return selectedHopeContactTime.map(i => {
@@ -355,34 +397,99 @@
         this.$router.push('/')
     }
 
+    private getLatestReserved(agentNo) {
+      const agentInfo = this.myConsultantList.filter(item => item.agentNo === agentNo);
+
+      const appointmentInfo = agentInfo.length > 0 && agentInfo[0].appointments
+        ? agentInfo[0].appointments!
+          .filter((appointment) => appointment.communicateStatus !== 'contacted')
+          .sort((preAppointment, nextAppointment) => {
+              return +nextAppointment.appointmentDate - +preAppointment.appointmentDate
+          })[0]
+        : null;
+
+      return this.getReservedData(appointmentInfo);
+    }
+
+    private getReservedData(appointmentInfo) {
+      if (appointmentInfo) {
+        const hopeContactTime = appointmentInfo!.hopeContactTime.split("'")
+              .filter(item => item && item !== ',');
+        this.appointmentId = appointmentInfo.id;
+        return {
+            age: appointmentInfo.age,
+            agentNo: appointmentInfo.agentNo,
+            contactType: appointmentInfo.contactType,
+            email: appointmentInfo.email || '',
+            gender: appointmentInfo.gender,
+            hopeContactTime: hopeContactTime.map(item => {
+                const info = item.split('��');
+                return {
+                    selectWeekOptions: info[0].split(','),
+                    selectTimesOptions: info[1].split(',')
+                }
+            }),
+            job: appointmentInfo.job,
+            phone: appointmentInfo.phone || '',
+            requirement: appointmentInfo.requirement.split(',')
+          }
+      } else {
+        return {
+          age: '',
+          agentNo: '',
+          contactType: '',
+          email: '',
+          gender: '',
+          hopeContactTime: [],
+          job: '',
+          phone: '',
+          requirement: []
+        }
+      }
+    }
+
+    @Watch('myConsultantList') onMyConsultantListChange() {
+      if (this.isLogin && this.myConsultantList.length > 0) {
+          const editAppointment = this.getLatestReserved(this.$route.params.agentNo);
+
+          if (editAppointment.agentNo) {
+            this.myRequest = JSON.parse(JSON.stringify(editAppointment));
+            if (!this.$route.query || this.$route.query.edit !== 'true') {
+              this.isEditPopup = true;
+            }
+            this.isEditBtn = true;
+            return;
+          }
+      }
+    }
   }
 </script>
 
 <style lang="scss" scoped>
 .sendReserve-txt{
-    display: flex;
-    justify-content: center;
-    margin-top: 10px;
-    margin-bottom: 26px;
+  display: flex;
+  justify-content: center;
+  margin-top: 10px;
+  margin-bottom: 26px;
 }
 
 //drawer��摨���見撘�
 .qa-dialog-footer{
-    display: flex;
-    justify-content: center;
-    margin-bottom: 81px;
-    color: #ED1B2E;
-    cursor: pointer;
+  display: flex;
+  justify-content: center;
+  margin-bottom: 81px;
+  color: #ED1B2E;
+  cursor: pointer;
 }
 
 //����見撘����
 .ques-footer{
-    justify-content: center;
-    margin: 30px 0;
-    display: flex;
-    flex-direction: column;
-    align-items: center;
-    .el-button {
+  justify-content: center;
+  margin: 30px 0;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  .el-button {
     width: 120px;
     height:50px;
     background-color: #ED1B2E;
@@ -410,43 +517,39 @@
 
 //閰喟敦���rawer銝剝�摰寧征��之撠身蝵�
 .qa-dialog{
-    overflow-y:auto;
-    height: 500px;
-    margin-top: 20px;
+  overflow-y:auto;
+  height: 500px;
+  margin-top: 20px;
 }
 
 //閰喟敦���rawer銝餉����
 .qaTextTitle{
-    margin-top:30px;
-    display: flex;
-    justify-content: center;
-}
-
-.el-button+.el-button{
-    margin-left: 0;
+  margin-top:30px;
+  display: flex;
+  justify-content: center;
 }
 
 .datepicker{
-    display: flex;
-    flex-direction: column;
+  display: flex;
+  flex-direction: column;
 }
 
 .required {
-    position: relative;
-    &::before {
-        content: '*';
-        position: absolute;
-        color: #FF0000;
-        transform: translate(-12px, 0);
-    }
+  position: relative;
+  &::before {
+      content: '*';
+      position: absolute;
+      color: #FF0000;
+      transform: translate(-12px, 0);
+  }
 }
 
 .ques-page--reset.pam-page-container {
-    margin: 0px auto;
+  margin: 0px auto;
 }
 
 .ques-header {
-    position: relative;
+  position: relative;
 }
 
 .ques-header__mob-banner {
@@ -459,41 +562,41 @@
   background-position: center;
 }
 
-.ques-header__info {
-  position: relative;
-  padding:30px 20px;
-  margin: 0px 20px;
-  background-color: #B3E7E3;
-  border-radius: 10px;
-}
-
-.ques-header__input-block {
-  display: flex;
-  align-items: center;
-  @extend .text--middle,.mt-10 ;
-  .ques-header__input{
-    &.is-invalid{
-      border: 2px solid $PRIMARY_RED !important;
-    }
-    flex: 1;
-    height: 50px;
+  .ques-header__info {
+    position: relative;
+    padding:30px 20px;
+    margin: 0px 20px;
+    background-color: #B3E7E3;
     border-radius: 10px;
-    border: 1px #CCCCCC solid;
-    background-color: $PRIMARY_WHITE;
-    padding: 15px 10px;
-    box-sizing: border-box;
-    -webkit-box-sizing: border-box;
-    -moz-box-sizing: border-box;
   }
-}
 
-.ques-container {
-  position: relative;
-  margin: 0px 20px;
-}
+  .ques-header__input-block {
+    display: flex;
+    align-items: center;
+    @extend .text--middle,.mt-10 ;
+    .ques-header__input{
+      &.is-invalid{
+        border: 2px solid $PRIMARY_RED !important;
+      }
+      flex: 1;
+      height: 50px;
+      border-radius: 10px;
+      border: 1px #CCCCCC solid;
+      background-color: $PRIMARY_WHITE;
+      padding: 15px 10px;
+      box-sizing: border-box;
+      -webkit-box-sizing: border-box;
+      -moz-box-sizing: border-box;
+    }
+  }
+
+  .ques-container {
+    position: relative;
+    margin: 0px 20px;
+  }
 
 
-@include desktop{
+  @include desktop{
   .ques-header{
     display: flex;
     justify-content: flex-end;

--
Gitblit v1.8.0