保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
    <el-row type="flex" justify="center" :class="cusClass">
        <el-button @click="addConsultant(agentInfo)" :disabled="isAdded">
            <span> {{ isAdded ? '已加入顧問清單' : '+ 顧問清單' }}</span>
        </el-button>
        <el-button
            :disabled="isDisableReserve"
            @click="navigateToReservationForm"
            type="primary"
        >{{ isDisableReserve ? '已聯絡' : '進行預約'}}</el-button>
    </el-row>
</template>
 
<script lang="ts">
import { Vue, Component, Prop, Emit, Action, State, namespace } from 'nuxt-property-decorator';
import { Consultant } from '~/shared/models/consultant.model';
 
const roleStorage = namespace('localStorage');
 
@Component
export default class AddAndReservedBtns extends Vue {
 
    @Action
    addToMyConsultantList!: (consultantToAdd: Consultant) => Promise<boolean>
 
    @State('myConsultantList')
    myConsultantList!: Consultant[];
 
    @Prop()
    agentInfo!: Consultant;
 
    @Prop()
    cusClass!: string;
 
    @roleStorage.Getter
    isUserLogin!: boolean;
 
    isVisiblePopUp = false;
 
    //////////////////////////////////////////////////////////////////////
 
    @Emit('openPopUp')
    openPopUp(popUpTxt: string = '成功加入顧問清單'): string {
        return popUpTxt;
    }
 
    //////////////////////////////////////////////////////////////////////
 
    addConsultant(item: Consultant): void {
        if (!this.isUserLogin) {
          item = {
            ...item,
            updateTime: new Date().toISOString()
          };
        }
        this.addToMyConsultantList(item).then(addOk => {
            addOk && this.openPopUp();
        });
    }
 
    navigateToReservationForm(): void {
        this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`);
    }
 
    get isAdded() {
        return this.myConsultantList.find(item => item.agentNo === this.agentInfo.agentNo)
                ? true : false
    }
 
    get isDisableReserve(): boolean {
      return this.myConsultantList.some((agent) => {
        return agent.agentNo === this.agentInfo.agentNo
            && agent.contactStatus === 'contacted';
        });
    }
}
</script>