保誠-保戶業務員媒合平台
PAMapp/components/Consultant/ConsultantCard.vue
@@ -1,55 +1,318 @@
<template>
    <div>
        <el-row type="flex" class="rowStyle">
            <el-col :xs="2" :sm="1" :class="{'state': agentInfo.new}"></el-col>
        <el-row type="flex" class="rowStyle" :class="{'new': !agentInfo.customerViewTime }">
            <el-col :xs="2" :sm="1"></el-col>
            <el-col :xs="22" :sm="23">
                <el-row type="flex">
                    <el-col class="flex_column" :xs="5" :sm="3">
                        <img class="avator" :src="agentInfo.img" alt="">
                        <div class="star">{{agentInfo.satisfaction}}</div>
                    </el-col>
                    <el-col class="flex_column" :xs="10" :sm="15">
                        <div class="smTxt_bold name">{{agentInfo.name}}</div>
                        <div class="tagStyle">
                            <span
                                class="tagTxt"
                                v-for="(tag, index) in agentInfo.tags" :key="index">#{{tag}}</span>
                        <UiAvatar
                            :size="50"
                            :fileName="avatarFileName"
                            @click.native="showAgentDetail(agentInfo.agentNo)"
                        ></UiAvatar>
                        <!-- TODO:隱藏滿意度 -->
                        <div v-if="!hideReviews">
                            <i class="icon-star pam-icon icon--yellow satisfaction"  v-if="!(latestContactedAppointment && !latestContactedAppointment.satisfactionScore)"></i>
                            <span v-if="agentInfo.contactStatus === 'contacted' && latestContactedAppointment && latestContactedAppointment.satisfactionScore">
                                {{ latestContactedAppointment && latestContactedAppointment.satisfactionScore}}
                            </span>
                            <div class="unfilled text--center "
                                style="display:flex"
                                v-if="agentInfo.contactStatus === 'contacted' &&
                                latestContactedAppointment && !latestContactedAppointment.satisfactionScore">未填<br />滿意度</div>
                            <span v-if="agentInfo.contactStatus !== 'contacted'">{{ agentInfo.avgScore }}</span>
                        </div>
                        <div class="delete" @click="removeAgent">移除</div>
                    </el-col>
                    <el-col :xs="10" :sm="15">
                        <div class="smTxt_bold name">{{agentInfo.name}}</div>
                        <div class="professionals">
                            <span
                                class="professionalsTxt"
                                v-for="(expertise, index) in agentInfo.expertise"
                                :key="index"
                            >#{{expertise}}</span>
                        </div>
                        <div
                            class="delete"
                            v-if="agentInfo.contactStatus === 'picked'
                                || !agentInfo.contactStatus"
                            @click="removeAgent"
                        >移除</div>
                    </el-col>
                    <el-col class="flex_column" :xs="9" :sm="6">
                        <el-button
                            class="smTxt_bold outline_btn"
                            @click="reserveCommunication"
                            :class="{'reservedBtn': agentInfo.reserve}"
                        >{{ agentInfo.reserve ? '已預約' : '進行預約'}}</el-button>
                        <div class="time">今天 10:00 加入</div>
                            :class="agentInfo.contactStatus + 'Btn'"
                        >{{ contactTxt }}</el-button>
                        <div class="updateTime mt-10">
                            {{ displayTime | formatDate }}
                        </div>
                    </el-col>
                </el-row>
            </el-col>
        </el-row>
        <Ui-Dialog
            :isVisible.sync="isVisibleDialog"
            :width="width"
            class="pam-myDemand-dialog"
        >
            <div v-if="appointmentDetail">
                <h5 class="subTitle text--center mb-30">預約成功</h5>
                <p class="smTxt">{{appointmentDetail.appointmentDate | formatDate}}</p>
                <div class="dialogInfo">
                    <p>姓名:{{appointmentDetail.name}}</p>
                    <p>電話:{{appointmentDetail.phone}}</p>
                    <p>Email:{{appointmentDetail.email}}</p>
                    <p>性別:{{gender}}</p>
                    <p>年齡:{{appointmentDetail.age | toAgeLabel }}</p>
                    <p>職業:{{appointmentDetail.job}}</p>
                    <p>需求:{{appointmentDetail.requirement.split(',').join('、')}}</p>
                    <p
                        v-for="(item, index) in hopeContactTime"
                        :key="index"
                    >連絡時段{{index + 1 | formatNumber}}:{{ item | formatHopeContactTime }}</p>
                    <div v-if="appointmentDetail.satisfactionScore">
                      <div class="mdTxt mt-10 mb-10">滿意度</div>
                      <el-rate
                      :value="appointmentDetail.satisfactionScore"
                      class="pam-myDemand-dialog__rate"
                      disabled>
                      </el-rate>
                    </div>
                  </div>
                <div v-if="agentInfo.contactStatus === 'contacted'
                        && !appointmentDetail.satisfactionScore" class="dialogInfo-btn">
                    <el-button type="primary"
                        @click.native="reviewsBtn = true">給予滿意度評分</el-button>
                </div>
                <div v-if="agentInfo.contactStatus === 'reserved'" class="text--center mt-10">
                    <el-button @click="isCancelPopup = true">取消預約</el-button>
                    <el-button @click="edit" type="primary">編輯</el-button>
                </div>
            </div>
        </Ui-Dialog>
        <PopUpFrame :isOpen.sync="reviewsBtn">
            <div class="mdTxt">
                保險顧問滿意度
                <span class="hint">選取星星</span>
                <div class="dialogInfo-score">
                    <el-rate v-model="inputScore" class="pam-quickFilter-rate"></el-rate>
                </div>
                <div class="dialogInfo-btn">
                    <el-button
                        type="primary"
                        :disabled="!inputScore"
                        @click="userReviewsConsultants">送出</el-button>
                </div>
            </div>
        </PopUpFrame>
        <PopUpFrame :isOpen.sync="isCancelPopup">
            <div class="text--center mdTxt">是否取消此筆預約?</div>
            <div class="text--center mt-30">
                <el-button @click="isCancelPopup = false">取消</el-button>
                <el-button @click="cancel" type="primary">確定</el-button>
            </div>
        </PopUpFrame>
    </div>
</template>
<script lang="ts">
import { Vue, Component, Prop, Emit, Watch } from 'nuxt-property-decorator';
import { Agents } from '~/plugins/api/home';
import { Vue, Component, Prop, Action, namespace } from 'nuxt-property-decorator';
import { getAppointmentDetail, UserReviewsConsultantsParams, userReviewsConsultants, cancelAppointment } from '~/assets/ts/api/consultant';
import { Consultant, Appointment } from '~/assets/ts/models/consultant.model';
import { isMobileDevice } from '~/assets/ts/device';
import { Role } from '~/assets/ts/models/enum/Role';
import { hideReviews } from '~/assets/ts/const/hide-reviews';
@Component
const roleStorage = namespace('localStorage');
@Component({
    filters: {
        formatNumber(index: number) {
            if (index) {
                const upperNumber = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
                return upperNumber[index];
            }
        },
        formatHopeContactTime(item: string): string {
        if (item) {
            const [hopeDay, hopeTime] = item.split('、');
            const day = hopeDay.split(',').length > 6 ? '不限日期' : hopeDay;
            const time = hopeTime.split(',').length > 3 ? '不限時間' : hopeTime;
            return `${day}、${time}`;
            }
            return '';
        }
    }
})
export default class ConsultantCard extends Vue {
    @Prop() agentInfo!: Agents;
    @Action removeFromMyConsultantList!: (agentNo: string) => Promise<boolean>;
    @Action storeConsultantList!: any;
    @Prop() agentInfo!: Consultant;
    @roleStorage.Getter currentRole!:string;
    isVisibleDialog = false;
    reviewsBtn = false;
    status = false;
    width: string = '';
    inputScore = 0;
    isCancelPopup = false;
    hideReviews = hideReviews;
    get latestContactedAppointment(): Appointment | null {
        if (!(this.agentInfo && this.agentInfo.appointments && this.agentInfo.appointments.length)) return null;
        const contactedAppointments: Appointment[] =  this.agentInfo.appointments
                                                        .filter((appointment) => appointment.communicateStatus === 'contacted')
                                                        .sort((preAppointment, nextAppointment) => +nextAppointment.appointmentDate - +preAppointment.appointmentDate);
        return contactedAppointments[0];
    }
    get latestReservedAppointment(): Appointment {
        return this.agentInfo.appointments!
                .filter((appointment) => appointment.communicateStatus !== 'contacted')
                .map((reversedAppointment) => {
                    return {
                    ...reversedAppointment,
                    sortDate: new Date(reversedAppointment.appointmentDate)
                    }
                })
                .sort((preAppointment, nextAppointment) => +nextAppointment.sortDate - +preAppointment.sortDate)[0];
    }
    get displayTime(): string {
        let time: Date | string = '';
        switch(this.agentInfo.contactStatus) {
            case 'reserved':
                time = this.agentInfo.updateTime
                break;
            case 'contacted':
                time = this.agentInfo.updateTime
                break;
            case 'picked':
                time = this.agentInfo.createTime
                break;
        }
        if (typeof time !== 'string') {
          time.toString();
        }
        return time as string;
    }
    appointmentDetail: any = {
        age               : '',
        agentNo           : '',
        appointmentDate   : '',
        communicateStatus : '',
        consultantReadTime: null,
        consultantViewTime: null,
        contactTime       : '',
        contactType       : '',
        customerId        : 0,
        email             : '',
        gender            : '',
        hopeContactTime   : "",
        id                : 0,
        job               : "",
        lastModifiedDate  : '',
        name              : '',
        otherRequirement  : null,
        phone             : "",
        requirement       : '',
        satisfactionScore : 0,
    };
    get avatarFileName() {
        return this.agentInfo.img;
    }
    get gender() {
        if (this.appointmentDetail.gender) {
            return this.appointmentDetail.gender === 'male' ? '男性' : '女性';
        }
        return ''
    }
    get contactTxt() {
        if (this.agentInfo.contactStatus === 'contacted') {
            return '已聯絡';
        }
        if (this.agentInfo.contactStatus === 'reserved') {
            return '已預約';
        }
        return '進行預約';
    }
    get hopeContactTime() {
        const contactList = this.appointmentDetail.hopeContactTime
            .split("'").map(item => item.slice(0, item.length));
        return contactList.filter(item => !!item && item !== ",")
    }
    reserveCommunication() {
        if (!this.agentInfo.reserve) {
            this.$router.push('/communication/myDemand')
        const contactStatus = this.agentInfo.contactStatus;
        if (!contactStatus || contactStatus === 'picked') {
            this.currentRole === Role.USER
                ? this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`)
                : this.$router.push('/login');
        } else {
            this.openPopUp();
        }
    }
    @Emit('removeAgent') removeAgent() {
        return this.agentInfo.id;
    openPopUp() {
      const appointmentId = this.agentInfo.contactStatus === 'contacted'
                          ? this.latestContactedAppointment?.id
                          : this.latestReservedAppointment.id;
        getAppointmentDetail(appointmentId!).then(res => {
            this.appointmentDetail = {
                ...this.appointmentDetail,
                ...res.data
            };
            this.width = isMobileDevice() ? '80%' : '';
            this.isVisibleDialog = true;
        });
    }
    removeAgent() {
        this.removeFromMyConsultantList(this.agentInfo.agentNo).then((removeOk) => {
        });
    }
    showAgentDetail(agentNo: string): void {
        this.$router.push(`/agentInfo/${agentNo}`);
    }
    userReviewsConsultants() {
        const reviewParams: UserReviewsConsultantsParams = {
            appointmentId: this.appointmentDetail.id,
            score: this.inputScore,
        }
        this.appointmentDetail.satisfactionScore = this.inputScore;
        userReviewsConsultants(reviewParams).then((res) => {
            this.reviewsBtn = false;
            this.storeConsultantList();
        });
    }
    cancel() {
        cancelAppointment(this.latestReservedAppointment.id).then(res => {
            this.storeConsultantList();
            this.isVisibleDialog = false;
            this.isCancelPopup = false;
        });
    }
    edit() {
        this.isVisibleDialog = false;
        this.$router.push({path: `/questionnaire/${this.agentInfo.agentNo}`, query: {'edit': 'true'}});
    }
}
</script>
<style lang="scss" scoped>
@@ -59,37 +322,31 @@
        margin-bottom: 10px;
        display: flex;
        justify-content: space-between;
        border-left: 4px solid transparent;
        .state {
            width: 10px;
            height: 10px;
            border-radius: 50px;
            background-color: $YELLOW;
            margin: auto 0;
        &.new {
            border-color: $YELLOW;
        }
        .avator {
            width: 50px;
            height: 50px;
            border-radius: 50px ;
        }
        .star {
        .satisfaction {
            font-size: 12px;
            font-weight: bold;
            &:before {
                content: '\2605';
                color: $PRIMARY_RED;
                margin: 5px;
            }
            margin-top: 5px;
        }
        .unfilled {
                font-size: 12px;
                padding-top: 5px;
                padding-left: 5px;
            }
        .tagStyle {
        .professionals {
            height: 20px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            .tagTxt {
            margin: 5px 0 10px 0;
            .professionalsTxt {
                font-size: 12px;
                font-weight: bold;
                margin-right: 5px;
@@ -105,16 +362,27 @@
        .reservedBtn {
            color: $SKY_BLUE;
            cursor: auto;
            border-color: $SKY_BLUE;
            &:hover {
                color: $SKY_BLUE;
                border-color: $SKY_BLUE;
                background-color: $PRIMARY_WHITE;
            &:focus {
                color: $PRIMARY_WHITE;
                background-color: $SKY_BLUE;
                opacity: 0.5;
            }
        }
        .time {
        .contactedBtn {
            color: $GREEN;
            border-color: $GREEN;
            &:focus {
                color: $PRIMARY_WHITE;
                background-color: $GREEN;
                opacity: 0.5;
            }
        }
        .updateTime {
            font-size: 12px;
            font-weight: bold;
            color: #707070;
@@ -128,4 +396,19 @@
        justify-content: space-between;
    }
    .dialogInfo {
        font-size: 20px;
        overflow-y:scroll;
        height: 400px;
    }
    .dialogInfo-btn{
        display: flex;
        justify-content: center;
    }
    .dialogInfo-score{
        display: flex;
        justify-content: center;
        margin-bottom: 50px;
    }
</style>