保誠-保戶業務員媒合平台
Tomas
2024-01-11 756f8a63347119f511fc964bf1e2ff2417339c56
PAMapp/pages/agentInfo/edit/_agentNo.vue
@@ -1,33 +1,100 @@
<template>
    <div>
    <div class="edit-agent-info-page" v-if="!!agentInfo">
      <el-row
        type="flex"
        justify="center">
        <UiAvatar :size="150" :fileName="agentInfo.img"></UiAvatar>
        <EditConsultantAvatar
          :agentNo="agentInfo.agentNo"
          :photoBase64.sync="editInfoValue.photoBase64"/>
      </el-row>
      <el-row
      <!-- NOTE: 我認為編輯頁面不需要顯示 avgScore,先隱藏 [Tomas, 2022/2/10 13:55] -->
      <!-- <el-row
        type="flex"
        class="pt-10"
        justify="center"
        align="middle" v-if="!hideReviews">
        <!-- TODO:隱藏滿意度 -->
          <i class="pam-icon icon--primary icon-star"></i>
          <h3 class="mdTxt">{{ agentInfo.avgScore }}</h3>
      </el-row>
      </el-row> -->
      <el-row
      <!-- <el-row
        type="flex"
        class="pt-10"
        class="pam-paragraph"
        justify="center">
        <el-input class="mdTxt" v-model="editInfoValue.name"></el-input>
      </el-row> -->
       <el-row
        type="flex"
        class="pam-paragraph">
        <el-col :span="24" class="pam-field">
          <div class="pam-field__label pam-progress__label">
            <div>
              <div class="pam-field__title mb-10">
                <i class="pam-icon icon-avatar"
                  ></i>顯示名稱
                  <span class="hint text--bold" v-show="!editInfoValue.name">顯示名稱為必填</span>
              </div>
            </div>
            <el-input
              v-model="editInfoValue.name"
              :class="{'is-invalid': !nameValid}"
              maxlength="10"
              minlength="10"></el-input>
          </div>
        </el-col>
      </el-row>
      <el-row
        type="flex"
        class="pam-paragraph">
        <UiField :span="12" icon="agent" label="頭銜">
          <el-input  v-model="editInfoValue.title"></el-input>
        <el-col :span="24" class="pam-field">
          <div class="pam-field__label pam-progress__label">
            <div>
              <div class="pam-field__title mb-10">
                <i class="pam-icon icon-phone"
                  ></i>手機號碼
                  <span class="hint text--bold" v-show="!phoneValid">手機號碼格式有誤</span>
                  <span class="hint text--bold" v-show="editInfoValue.phoneNumber.length === 0">手機號碼為必填</span>
              </div>
            </div>
            <el-input
            v-model="editInfoValue.phoneNumber"
            :class="{'is-invalid': !phoneValid}"
            maxlength="10"
            minlength="10"></el-input>
          </div>
        </el-col>
      </el-row>
      <el-row
        type="flex"
        class="pam-paragraph">
        <el-col :span="24" class="pam-field">
          <div class="pam-field__label pam-progress__label">
            <div>
              <div class="pam-field__title mb-10">
                <i class="pam-icon icon-comment"
                  ></i>信箱
                  <span class="hint text--bold" v-show="!emailValid">信箱格式有誤</span>
                  <span class="hint text--bold" v-show="editInfoValue.email.length === 0">信箱為必填</span>
              </div>
            </div>
            <el-input
            v-model="editInfoValue.email"
            :class="{'is-invalid': !emailValid}"
            ></el-input>
          </div>
        </el-col>
      </el-row>
      <el-row
        type="flex"
        class="pam-paragraph">
        <UiField :span="24" icon="agent" label="頭銜">
          <el-input  v-model="editInfoValue.title" class="mt-10"></el-input>
        </UiField>
      </el-row>
@@ -35,7 +102,12 @@
        type="flex"
        class="pam-paragraph">
        <UiField icon="company" label="服務地區">
          <el-input  v-model="editInfoValue.serveArea"></el-input>
          <MultiSelectBtn class="mt-30"
            :mutiSelect.sync="editInfoValue.serveArea"
            :nameOfSelectAll="'全台'"
            :options="serveAreaOptions"
            >
          </MultiSelectBtn>
        </UiField>
      </el-row>
@@ -43,7 +115,7 @@
        type="flex"
        class="pam-paragraph">
        <UiField icon="address" label="公司地址">
          <el-input  v-model="editInfoValue.companyAddress"></el-input>
          <el-input  v-model="editInfoValue.companyAddress" class="mt-10"></el-input>
        </UiField>
      </el-row>
@@ -53,20 +125,18 @@
        <UiField :span="12" icon="time" label="最後上線時間">
          {{ agentInfo.latestLoginTime | formatDate }}
        </UiField>
        <UiField :span="12" icon="calender" label="服務資歷" style="display:flex">
          <el-input  v-model="editInfoValue.seniorityYear" class="seniority-input"></el-input>年
          <el-select  style="width:60px" v-model="editInfoValue.seniorityMonth" class="seniority-input">
            <el-option
              v-for="(month) in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]"
              :value="month"
              :key="month">
              {{ month }}
            </el-option>
          </el-select>月
        <UiField :span="12" icon="calender" label="到職日期" class="pam-editInfo-date-picker">
          <UiDatePicker
              :isFutureDateDisabled = true
              id="el-date-picker"
              class="mt-10"
              :defaultValue ="agentInfo.entryDate"
              @changeDate="onChangeDate($event)"
          ></UiDatePicker>
        </UiField>
      </el-row>
      <el-row
      <!-- <el-row
        type="flex"
        class="pam-paragraph">
        <el-col :span="24" class="pam-field">
@@ -85,35 +155,54 @@
            <el-progress :show-text="false" :stroke-width="15" :percentage="agentInfo.evaluation * 2"></el-progress>
          </div>
        </el-col>
      </el-row>
      </el-row> -->
      <el-row
        type="flex"
        class="pam-paragraph">
        <el-checkbox
            v-model="editInfoValue.communicationStyle"
            :label="communicateStyle"
            :key="index"
            v-for="(communicateStyle, index) in communicationStyleList">
          </el-checkbox>
        <el-col :span="24" class="pam-field">
          <div class="pam-field__label pam-progress__label">
            <div>
              <div class="pam-field__title">
                <i class="pam-icon icon-flag"
                  ></i>溝通風格  <span class="hint text--bold">(可複選,最多2項)</span>
              </div>
            </div>
            <MultiSelectBtn class="mt-30"
              :mutiSelect.sync="editInfoValue.communicationStyle"
              :options="agentCommunicationStyleList"
              :maxLength="2"
            >
            </MultiSelectBtn>
          </div>
        </el-col>
      </el-row>
      <el-row
        type="flex"
        class="pam-paragraph">
        <UiField icon="flag" label="專長領域">
          <el-checkbox
            v-model="editInfoValue.expert"
            :label="item.name"
            :key="item.id"
            v-for="item in expertList">
          </el-checkbox>
        </UiField>
        <el-col :span="24" class="pam-field">
          <div class="pam-field__label pam-progress__label">
            <div>
              <div class="pam-field__title">
                <i class="pam-icon icon-flag"
                  ></i>專長領域  <span class="hint text--bold">(可複選)</span>
              </div>
            </div>
            <MultiSelectBtn class="mt-30"
              :mutiSelect.sync="editInfoValue.expertise"
              :options="agentExpertList"
            >
            </MultiSelectBtn>
          </div>
        </el-col>
      </el-row>
      <el-row
        type="flex"
        class="pam-paragraph">
        <UiField icon="comment" label="個人理念">
          <el-input type="textarea" autosize v-model="editInfoValue.concept"></el-input>
          <el-input type="textarea" autosize v-model="editInfoValue.concept" class="mt-10"></el-input>
        </UiField>
      </el-row>
@@ -121,7 +210,12 @@
        type="flex"
        class="pam-paragraph">
        <UiField icon="school" label="個人背景">
            <el-input type="textarea" autosize v-model="editInfoValue.experience"></el-input>
            <el-input
              autosize
              type="textarea"
              class="mt-10"
              v-model="editInfoValue.experiences">
            </el-input>
        </UiField>
      </el-row>
@@ -129,7 +223,7 @@
        type="flex"
        class="pam-paragraph">
        <UiField icon="trophy" label="得獎經歷">
          <el-input type="textarea" autosize style="height:70%" v-model="editInfoValue.awards"></el-input>
          <el-input type="textarea" autosize style="height:70%" v-model="editInfoValue.awards" class="mt-10"></el-input>
        </UiField>
      </el-row>
@@ -147,7 +241,16 @@
            </div>
        </div>
    </PopUpFrame>
    <PopUpFrame :isOpen.sync="isInfoUpdate">
      <div class="text--center mdTxt fs-18">
        <p class="mt-20 text--center ">帳號資訊更新成功</p>
        <el-button
                type="primary"
                @click="backToInfo"
                class="mt-20"
              >我知道了</el-button>
      </div>
    </PopUpFrame>
    <div class="pam-paragraph account-confirm">
      <el-button :disabled="isSubmitBtnDisabled"
        @click.native="editAgentInfoSetting">
@@ -160,82 +263,103 @@
<script lang="ts">
import { Context } from '@nuxt/types';
import { namespace } from 'nuxt-property-decorator';
import { Vue, Component } from 'vue-property-decorator';
import * as _ from "lodash";
import { Vue, Component, Prop } from 'vue-property-decorator';
import myConsultantService from '~/shared/services/my-consultant.service';
import accountSettingService from '~/shared/services/account-setting.service';
import { AgentInfo } from '~/shared/models/agent-info.model';
import { hideReviews } from '~/shared/const/hide-reviews';
import { Role } from '~/shared/models/enum/Role';
import { AgentInfoSetting } from '~/shared/models/account.model';
import { Role } from '~/shared/models/enum/Role';
import { agentCommunicationStyleList } from '~/shared/const/agent-communication-style-list';
import { taiwanCities } from '~/shared/const/taiwan-cities';
const localStorage = namespace('localStorage');
const localStorageTest = namespace('localStorage');
const loginStore = namespace('login.store');
@Component
export default class AgentInfoComponent extends Vue {
export default class AgentInfoEditComponent extends Vue {
  @localStorage.State('current_role')
  currentRole!:string | null;
  @localStorageTest.State
  current_role: any;
  _agentInfoSetting!: AgentInfoSetting;
  agentInfo!:AgentInfo
  role = Role;
  isAlertFieldInfo         = false;
  fieldInfoTitle           = '';
  fieldInfoDesc            = '';
  hideReviews              = hideReviews ;
  @loginStore.Action
  updateConsultantDetail!: (agentNo: string) => Promise<AgentInfo>;
  defaultAgentInfoSetting!: AgentInfoSetting;
  agentInfo!      : AgentInfo
  fieldInfoDesc   : string = '';
  fieldInfoTitle  : string = '';
  hideReviews     : boolean = hideReviews ;
  isAlertFieldInfo: boolean = false;
  isInfoUpdate    : boolean = false;
  serveAreaOptions: any[] = taiwanCities.map((city) => ({ title: city, label: city }));
  editInfoValue = {
    agentNo           : '',
    name              : '',
    expert            : [] as string[],
    expertise         : [] as string[],
    title             : '',
    serveArea         : '',
    serveArea         : [] as string[],
    companyAddress    : '',
    seniorityYear     : 1,
    seniorityMonth    : 0,
    concept           : '',
    experience        : '',
    experiences       : '',
    awards            : '',
    communicationStyle: [] as string[],
  }
  formValidStatus = {
    name          : true,
    title         : true,
    companyAddress: true,
    serveArea     : true,
    seniorityYear : true,
    seniorityMonth: true,
    expert        : true,
    concept       : true,
    experience    : true,
    awards        : true,
    communicationStyle:true
    photoBase64       : '',
    phoneNumber       : '',
    email             : '',
    entryDate         : '',
  };
  expertList=[
  communicationStyleList: string[] = agentCommunicationStyleList;
  role           = Role;
  agentExpertList = [
    {
      name:'健康與保障'
      },
    {
      name:'子女教育'
      },
    {
      name:'資產規劃'
      },
    {
      name:'樂活退休'
      },
    {
      name:'保單健檢/規劃'
        title:'健康與保障',
        label:'健康與保障'
    },
    {
      name:'分紅保單'}
    ];
        title:'子女教育',
        label:'子女教育'
    },
    {
        title:'資產規劃',
        label:'資產規劃'
    },
    {
        title:'樂活退休',
        label:'樂活退休'
    },
    {
        title:'保單健檢/規劃',
        label:'保單健檢/規劃'
    },
    {
        title:'分紅保單',
        label:'分紅保單'
    }];
  communicationStyleList: string[] = ['謹慎務實', '明快主動', '耐心傾聽', '健談風趣'];
  agentCommunicationStyleList = [
    {
        title:'謹慎務實',
        label:'謹慎務實'
    },
    {
        title:'明快主動',
        label:'明快主動'
    },
    {
        title:'耐心傾聽',
        label:'耐心傾聽'
    },
    {
        title:'健談風趣',
        label:'健談風趣'
    }];
  //////////////////////////////////////////////////////////////////////
@@ -247,10 +371,80 @@
  }
  mounted(){
    this.setAgentInfo(this.agentInfo);
    this.setAgentInfo(this.agentInfo);
    const bodyEl = document.querySelector('body');
    bodyEl?.addEventListener('scroll', function() {
      const elDatePickerEl = document.querySelector('#el-date-picker');
      const elDatePickerPanelEl = document.querySelector('.el-picker-panel');
      if (elDatePickerPanelEl) {
        elDatePickerPanelEl['style']['z-index'] = 5;
        const elDatePickerOffsetTop = elDatePickerEl!.getBoundingClientRect().top;
        elDatePickerPanelEl!['style'].top = elDatePickerOffsetTop + 30 + 'px';
      }
    });
  }
  private setAgentInfo(agentInfo: AgentInfo): void {
    this.defaultAgentInfoSetting = {
      agentNo: agentInfo?.agentNo || '',
      name: agentInfo?.name || '',
      expertise: agentInfo?.expertise || [],
      title: agentInfo?.title || '',
      role: agentInfo?.role || '',
      serveArea: agentInfo?.serveArea?.split('、') || [],
      gender: agentInfo?.gender || '',
      phoneNumber: agentInfo?.phoneNumber || '',
      companyAddress: agentInfo?.companyAddress || '',
      concept: agentInfo?.concept || '',
      experiences: agentInfo?.experiences || '',
      awards: agentInfo?.awards || '',
      communicationStyle: agentInfo?.communicationStyle || '',
      photoBase64: '',
      email: agentInfo?.email || '',
      entryDate: agentInfo?.entryDate || '',
    };
    this.editInfoValue = {
      ...this.defaultAgentInfoSetting,
      expertise: JSON.parse(JSON.stringify(this.defaultAgentInfoSetting.expertise)),
      communicationStyle: this.defaultAgentInfoSetting.communicationStyle?.split('、') || [],
    };
  }
  //////////////////////////////////////////////////////////////////////
  editAgentInfoSetting(): void {
    const editSettingInfo: any = {
      ...this.editInfoValue,
      communicationStyle: this.editInfoValue.communicationStyle.join('、'),
      serveArea: this.editInfoValue.serveArea.join('、'),
    };
    accountSettingService.editAgentInfoSetting(editSettingInfo).then((res: AgentInfoSetting) => {
      this.isInfoUpdate = true;
      this.updateConsultantDetail(editSettingInfo.agentNo);
    });
  }
  onChangeDate(date: any): void {
    this.editInfoValue.entryDate = date;
  }
  backToInfo() {
    this.isInfoUpdate = false
    this.$router.push(`/agentInfo/${this.agentInfo.agentNo}`);
  }
  selectCommunicationStyles(): void {
    if (this.editInfoValue.communicationStyle.length > 2) {
            this.editInfoValue.communicationStyle.shift();
        }
  }
  alertFieldInfo(field: string): void {
    this.isAlertFieldInfo = true;
@@ -259,156 +453,54 @@
        this.fieldInfoTitle = '匹配度';
        this.fieldInfoDesc = '匹配度是透過嚴選配對或快速篩選後,將每一位保險顧問資料進行比對後排序推薦給您的媒合數值,您可以作為選擇適合顧問的參考值。';
        break;
      case 'evaluation':
        this.fieldInfoTitle = '諮詢度表現';
        this.fieldInfoDesc = '諮詢度表現是將每一位保險顧問近一個月回覆諮詢數量進行比對後排序推薦給您的媒合數值。';
        break;
      // case 'evaluation':
      //   this.fieldInfoTitle = '諮詢度表現';
      //   this.fieldInfoDesc = '諮詢度表現是將每一位保險顧問近一個月回覆諮詢數量進行比對後排序推薦給您的媒合數值。';
      //   break;
    }
  }
  ////////////////////////////////////////////////////////////
  private setAgentInfo(agentInfo: AgentInfo): void {
      const [agentYear, _yearUnit , agentMonth, _monthUnit] =  agentInfo.seniority.split(" ");
      this._agentInfoSetting = {
                  agentNo           : agentInfo.agentNo||'',
                  name              : agentInfo.name || '',
                  expertise         : agentInfo.expertise || [],
                  title             : agentInfo.title || '',
                  role              : agentInfo.role||'',
                  serveArea         : agentInfo.serveArea || '',
                  gender            : agentInfo.gender||'',
                  phoneNumber       : agentInfo.phoneNumber||'',
                  companyAddress    : agentInfo.companyAddress || '',
                  seniorityYear     : agentYear? +agentYear : 0,
                  seniorityMonth    : agentMonth ? +agentMonth: 0,
                  concept           : agentInfo.concept || '',
                  experience        : agentInfo.experiences  || '',
                  award             : agentInfo.awards || '',
                  communicationStyle: agentInfo.communicationStyle || '',
                  photoBase64       : '123',
              };
                this.editInfoValue.name           = this._agentInfoSetting.name!;
                this.editInfoValue.title          = this._agentInfoSetting.title!;
                this.editInfoValue.serveArea      = this._agentInfoSetting.serveArea
                this.editInfoValue.companyAddress = this._agentInfoSetting.companyAddress;
                this.editInfoValue.seniorityYear = this._agentInfoSetting.seniorityYear;
                this.editInfoValue.seniorityMonth = this._agentInfoSetting.seniorityMonth;
                this.editInfoValue.expert        = _.cloneDeep(this._agentInfoSetting.expertise);
                this.editInfoValue.concept        = this._agentInfoSetting.concept;
                this.editInfoValue.experience     = this._agentInfoSetting.experience;
                this.editInfoValue.awards         = this._agentInfoSetting.award;
                this.editInfoValue.communicationStyle = this._agentInfoSetting.communicationStyle.split(',');
  get nameValid(): boolean {
    return !!this.defaultAgentInfoSetting?.name;
  }
  get nameValid():boolean {
      this.formValidStatus.name = this.editInfoValue.name ? true : false;
      return this.formValidStatus.name;
  get phoneValid(): boolean {
    const rule = /^09[0-9]{8}$/;
    return this.editInfoValue.phoneNumber
      ? rule.test(this.editInfoValue.phoneNumber) && this.editInfoValue.phoneNumber.length === 10
      : true;
  }
  get titleValid():boolean{
      this.formValidStatus.title = this.editInfoValue.title ? true : false ;
      return this.formValidStatus.title;
  }
  get companyAddressValid() : boolean{
      this.formValidStatus.companyAddress = this.editInfoValue.companyAddress ? true : false;
      return this.formValidStatus.companyAddress;
  }
  get serveAreaValid():boolean{
      this.formValidStatus.serveArea = this.editInfoValue.serveArea ? true : false;
      return this.formValidStatus.serveArea;
  }
  get conceptValid():boolean{
      this.formValidStatus.concept = this.editInfoValue.concept ? true : false;
      return this.formValidStatus.concept;
  }
  get experienceValid():boolean{
      this.formValidStatus.experience = this.editInfoValue.experience ? true : false;
      return this.formValidStatus.experience;
  }
  get awardsValid():boolean{
      this.formValidStatus.awards = this.editInfoValue.awards ? true : false ;
      return this.formValidStatus.awards;
  }
  get seniorityYearValid():boolean{
    this.formValidStatus.seniorityYear = this.editInfoValue.seniorityYear ? true  : false;
    return this.formValidStatus.seniorityYear;
  }
  get seniorityMonthValid():boolean{
    this.formValidStatus.seniorityMonth = this.editInfoValue.seniorityMonth ? true : false;
    return this.formValidStatus.seniorityYear;
  }
  get communicationStyleValid():boolean{
    this.formValidStatus.communicationStyle = this.editInfoValue.communicationStyle ? true : false;
    return this.formValidStatus.seniorityMonth;
  }
  get expertValid():boolean{
    this.formValidStatus.expert = this.editInfoValue.expert ? true : false;
    return this.formValidStatus.expert;
  }
  get emailValid() {
      const rule = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
      return this.editInfoValue.email ? rule.test(this.editInfoValue.email) : true;
    }
  get isSubmitBtnDisabled(): boolean {
            const isFormValid =  this.formValidStatus.name
                              && this.formValidStatus.title
                              && this.formValidStatus.companyAddress
                              && this.formValidStatus.serveArea
                              && this.formValidStatus.concept
                              && this.formValidStatus.experience
                              && this.formValidStatus.awards
                              && this.formValidStatus.seniorityYear
                              && this.formValidStatus.seniorityMonth
                              && this.formValidStatus.expert
                              && this.formValidStatus.communicationStyle;
            return !isFormValid
        }
  editAgentInfoSetting(): void {
            const editSettingInfo: any = {
                name              : this.editInfoValue.name,
                expertise         : this.editInfoValue.expert,
                title             : this.editInfoValue.title,
                role              : this.agentInfo.role,
                serveArea         : this.editInfoValue.serveArea,
                gender            : 'male',
                phoneNumber       : this.agentInfo.phoneNumber,
                companyAddress    : this.editInfoValue.companyAddress,
                seniorityYear     : this.editInfoValue.seniorityYear,
                seniorityMonth    : this.editInfoValue.seniorityMonth,
                concept           : this.editInfoValue.concept,
                experience        : this.editInfoValue.experience,
                award             : this.editInfoValue.awards,
                communicationStyle: this.editInfoValue.communicationStyle.join(','),
                photoBase64       : '123'
            }
            accountSettingService.editAgentInfoSetting(editSettingInfo).then((res: AgentInfoSetting) => {
              console.log(editSettingInfo)
            });
        }
      const isFormValid =  this.editInfoValue.name
                        && this.editInfoValue.title
                        && this.editInfoValue.companyAddress
                        && this.editInfoValue.serveArea
                        && this.editInfoValue.concept
                        && this.editInfoValue.experiences
                        && this.editInfoValue.phoneNumber.length
                        && this.editInfoValue.entryDate
                        && this.editInfoValue.expertise.length
                        && this.editInfoValue.communicationStyle.length
                        && this.editInfoValue.email.length;
      return !isFormValid
  }
}
</script>
<style lang="scss">
.pam-icon {
  font-size: 15px;
  font-size    : 15px;
  padding-right: 8px;
  color: $PRUDENTIAL_GREY;
  color        : $PRUDENTIAL_GREY;
  &.icon--primary {
    color: $PRIMARY_RED;
  }
@@ -423,9 +515,9 @@
      font-size: 12px;
    }
    .pam-field__title {
      font-size: 16px;
      font-size  : 16px;
      font-weight: bold;
      display: flex;
      display    : flex;
      align-items: center;
    }
  }
@@ -444,13 +536,13 @@
}
.pam-field-experts {
  display: flex;
  display  : flex;
  flex-wrap: wrap;
}
.pam-progress__label {
  justify-content: space-between;
  flex-wrap: wrap;
  flex-wrap  : wrap;
  line-height: 24px;
}
.account-confirm{
@@ -459,8 +551,17 @@
}
.seniority-input{
  width:50px;
  width       : 60px;
  margin-right: 5px;
}
.el-input--suffix .el-input__inner {
  padding-right: 20px;
}
</style>
.pam-editInfo-date-picker{
  .pam-date.el-input {
      width: 100%;
  }
}
</style>