From a7b45caf5b3784f65ba82793d87f5ffb202fca1e Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期五, 21 一月 2022 11:42:07 +0800
Subject: [PATCH] update#134555: [顧問] 預約單結案/編輯結案功能串接

---
 PAMapp/pages/appointment/_appointmentId/close/index.vue |  242 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 192 insertions(+), 50 deletions(-)

diff --git a/PAMapp/pages/appointment/_appointmentId/close/index.vue b/PAMapp/pages/appointment/_appointmentId/close/index.vue
index f67a0b3..956280e 100644
--- a/PAMapp/pages/appointment/_appointmentId/close/index.vue
+++ b/PAMapp/pages/appointment/_appointmentId/close/index.vue
@@ -11,21 +11,32 @@
         </UiField>
       </el-row>
 
-      <template v-if="appointmentCloseInfo.selectCloseOption === 'done'">
+      <template v-if="appointmentCloseInfo.selectCloseOption === contactStatus.DONE">
+        <el-row
+          type="flex"
+          class="pam-paragraph" style="flex-direction: column">
+          <UiField label="靽頨怠�����" :labelSize="20" class="required">
+            <input
+              class="appointment-client-detail-close__input"
+              :class="{'is-invalid':!identityIdValid}"
+              v-model="appointmentCloseInfo.policyholderIdentityId"
+              placeholder="隢撓�"
+              type="text">
+          </UiField>
+          <div class="error mt-5 mb-5" v-show="!identityIdValid">
+            <span>頨怠����撘�炊</span>
+          </div>
+        </el-row>
+
         <el-row
           type="flex"
           class="pam-paragraph">
-          <UiField label="���誨蝣噗lan Code" :labelSize="20">
+          <UiField label="���誨蝣噗lan Code" :labelSize="20" class="required">
             <input
               class="appointment-client-detail-close__input"
               v-model="appointmentCloseInfo.planCode"
               placeholder="隢撓�"
               type="text">
-              <!-- <el-input
-                type="input"
-                placeholder="隢撓�"
-                v-model="appointmentCloseInfo.planCode">
-              </el-input> -->
           </UiField>
         </el-row>
 
@@ -33,37 +44,37 @@
           type="flex"
           class="pam-paragraph">
           <UiField label="�脖辣����" :labelSize="20">
-            <input
-              class="appointment-client-detail-close__input"
-              v-model="appointmentCloseInfo.planCode"
-              placeholder="TBD: ����辣"
-              type="text">
+            <DateTimePicker
+              :defaultValue="appointmentCloseInfo.policyEntryDate"
+              @changeDateTime="appointmentCloseInfo.policyEntryDate = $event"></DateTimePicker>
           </UiField>
         </el-row>
       </template>
 
-      <template v-if="appointmentCloseInfo.selectCloseOption === 'close'">
+      <template v-if="appointmentCloseInfo.selectCloseOption === contactStatus.CLOSE">
         <el-row
           class="pam-paragraph">
-          <UiField label="���漱����" :labelSize="20">
+          <UiField label="���漱����" :labelSize="20" class="required">
           </UiField>
+            <div class="appointment-client-detail-close__select-box">
               <select
                 class="appointment-client-detail-close__select"
-                name="failReason" id="failReason" v-model="appointmentCloseInfo.failReason">
+                name="closedReason" id="closedReason" v-model="appointmentCloseInfo.closedReason">
                 <option :value="failReason.value" v-for="(failReason, index) in appointmentFailReason" :key="index">
                   {{ failReason.key }}
                 </option>
               </select>
-
-              <div style="display: flex" class="mt-10">
-
-                <input
-                  v-if="appointmentCloseInfo.failReason === 'other'"
-                  class="appointment-client-detail-close__input"
-                  v-model="appointmentCloseInfo.otherFailReason"
-                  placeholder="隢撓�������50摮��"
-                  type="text">
-              </div>
+              <i class="icon-down down-icon"></i>
+            </div>
+            <div class="mt-10">
+              <input
+                v-if="appointmentCloseInfo.closedReason === 'other'
+                    || appointmentCloseInfo.closedReason === 'no_suitable_commodity'"
+                class="appointment-client-detail-close__input"
+                v-model="appointmentCloseInfo.closedOtherReason"
+                placeholder="隢撓�������50摮��"
+                type="text">
+            </div>
         </el-row>
       </template>
 
@@ -75,19 +86,9 @@
             type="textarea"
             :rows="3"
             placeholder="隢撓�"
-            v-model="appointmentCloseInfo.archivedDate"
+            v-model="appointmentCloseInfo.remark"
             resize="none">
           </el-input>
-
-          <!-- <textarea
-            v-model="appointmentCloseInfo.archivedDate"
-            class="appointment-close__remark"
-            placeholder="隢撓�"
-            name="remark"
-            id="remark"
-            wrap="off"
-            rows="3">
-          </textarea> -->
         </UiField>
       </el-row>
 
@@ -96,45 +97,147 @@
         justify="center"
         class="pam-paragraph">
         <el-button @click="$router.go(-1)">����</el-button>
-        <el-button @click="$router.go(-1)">蝣箄��</el-button>
+        <el-button @click="closeAppointment" :disabled="isSubmitBtnDisabled">蝣箄��</el-button>
       </el-row>
 
+      <PopUpFrame :isOpen.sync="isShowSuccessAlert">
+        <div class="text--middle invite-review">
+          <div  class="mb-30 mt-10">蝯����</div>
+          <el-button type="primary" @click="closeAlert">蝣箏��</el-button>
+        </div>
+      </PopUpFrame>
   </div>
 </template>
 
 <script lang="ts">
 
+import { namespace } from 'nuxt-property-decorator';
 import { Vue, Component } from 'vue-property-decorator';
+import { Appointment, ToCloseAppointment, ToDoneAppointment } from '~/shared/models/appointment.model';
+
+import appointmentService from '~/shared/services/appointment.service';
+import { appointmentFailReasonList } from '~/shared/const/appointment-fail-reason-list';
+import { ContactStatus } from '~/shared/models/enum/contact-status';
+
+const appointmentStore = namespace('appointment.store');
 
 @Component
 export default class AppointmentDetailCloseComponent extends Vue {
 
+  @appointmentStore.Action
+  updateAppointmentDetail!: (appointmentId: number) => Appointment;
+
+  @appointmentStore.State('appointmentDetail')
+  appointmentDetail!: Appointment;
+
+  contactStatus = ContactStatus;
+
+  appointmentCloseDate = '';
+  isShowSuccessAlert = false;
+
   appointmentCloseInfo = {
-    archivedDate     : '',
-    failReason       : 'other',
-    otherFailReason  : '',
-    planCode         : '',
-    remark           : '',
-    selectCloseOption: 'done',
+    closedOtherReason     : '',
+    closedReason          : 'other',
+    planCode              : '',
+    policyEntryDate       : this.appointmentCloseDate,
+    policyholderIdentityId: '',
+    remark                : '',
+    selectCloseOption     : this.contactStatus.DONE,
   };
 
   closeOptions = [
     {
       title:'��漱',
-      label: 'done',
+      label: this.contactStatus.DONE,
     },
     {
       title:'���漱',
-      label: 'close',
+      label: this.contactStatus.CLOSE,
     }
   ];
 
-  appointmentFailReason = [
-    {
-      key: '�隞�',
-      value: 'other'
+  appointmentFailReason = appointmentFailReasonList;
+
+  //////////////////////////////////////////////////////////////////////
+
+  mounted() {
+    const appointmentId = +this.$route.params.appointmentId;
+    const closedInfo = this.appointmentDetail.appointmentClosedInfo;
+    if (this.appointmentDetail.id === appointmentId
+        && (this.appointmentDetail.communicateStatus === this.contactStatus.DONE
+        || this.appointmentDetail.communicateStatus === this.contactStatus.CLOSE
+        || this.appointmentDetail.communicateStatus === this.contactStatus.CANCEL)
+        ) {
+        this.appointmentCloseInfo = {
+        closedOtherReason     : closedInfo?.closedOtherReason,
+        closedReason          : closedInfo?.closedReason,
+        planCode              : closedInfo?.planCode,
+        policyEntryDate       : closedInfo?.policyEntryDate,
+        policyholderIdentityId: closedInfo?.policyholderIdentityId,
+        remark                : closedInfo?.remark,
+        selectCloseOption     : this.appointmentDetail.communicateStatus === this.contactStatus.DONE
+                                ? this.contactStatus.DONE
+                                : this.contactStatus.CLOSE
+      };
     }
-  ];
+  }
+
+  //////////////////////////////////////////////////////////////////////
+
+  closeAppointment(): void {
+    const appointmentId = +this.$route.params.appointmentId;
+    if (this.appointmentCloseInfo.selectCloseOption === this.contactStatus.DONE) {
+      const toDoneAppointment: ToDoneAppointment = {
+        appointmentId         : appointmentId,
+        contactStatus         : this.contactStatus.DONE,
+        planCode              : this.appointmentCloseInfo.planCode,
+        policyEntryDate       : this.appointmentCloseInfo.policyEntryDate,
+        policyholderIdentityId: this.appointmentCloseInfo.policyholderIdentityId,
+        remark                : this.appointmentCloseInfo.remark,
+      }
+      appointmentService.closeAppointment(toDoneAppointment).then((_) => this.updateAppointmentDetail(appointmentId));
+      this.isShowSuccessAlert = true;
+    } else {
+      const toCloseAppointment: ToCloseAppointment = {
+        appointmentId    : appointmentId,
+        closedOtherReason: this.appointmentCloseInfo.closedOtherReason,
+        closedReason     : this.appointmentCloseInfo.closedReason,
+        contactStatus    : this.contactStatus.CLOSE,
+        remark           : this.appointmentCloseInfo.remark,
+      }
+      appointmentService.closeAppointment(toCloseAppointment).then((_) => this.updateAppointmentDetail(appointmentId));
+      this.isShowSuccessAlert = true;
+    }
+  }
+
+  closeAlert(){
+    this.isShowSuccessAlert = false ;
+    this.$router.push(`/myAppointmentList/contactedList`);
+  }
+
+  get isSubmitBtnDisabled() {
+    const {
+      selectCloseOption,
+      policyholderIdentityId,
+      planCode,
+      closedReason,
+      closedOtherReason,
+      remark
+    } = this.appointmentCloseInfo;
+    // this.appointmentCloseInfo.policyEntryDate 銝行��齒瘜��澆 this.appointmentCloseDate
+    if (selectCloseOption === this.contactStatus.DONE) {
+      return !policyholderIdentityId || !this.identityIdValid || !planCode || !this.appointmentCloseInfo.policyEntryDate || !remark
+    } else if (closedReason === 'other' || closedReason === 'no_suitable_commodity') {
+      return !closedOtherReason
+    }
+    return false
+  }
+
+  get identityIdValid() {
+    const rule = /^[A-Z]\d{9}$/;
+    const identityId = this.appointmentCloseInfo.policyholderIdentityId;
+    return identityId ? rule.test(identityId) : true;
+  }
 
 }
 </script>
@@ -148,8 +251,47 @@
   font-size: 20px;
   padding  : 10px 20px;
   width    : 100%;
+  box-sizing: border-box;
   &::placeholder {
     color: $MID_GREY;
   }
+  &.is-invalid {
+    border-color: $PRIMARY_RED !important;
+  }
 }
+.appointment-client-detail-close__select-box {
+  position: relative;
+
+  & .appointment-client-detail-close__select{
+    appearance: none;
+  }
+  & .down-icon {
+    position: absolute;
+    right: 7px;
+    bottom: 10px;
+  }
+}
+.invite-review{
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+ .error {
+    @extend .smTxt_bold;
+    @extend .text--primary;
+    height: 16px;
+  }
+  .required {
+    position: relative;
+
+    &::before {
+      content: '*';
+      font-size: 20px;
+      font-weight: bold;
+      position: absolute;
+      color: #FF0000;
+      transform: translateX(-5px);
+      z-index: 5;
+    }
+  }
 </style>

--
Gitblit v1.8.0