保誠-保戶業務員媒合平台
HelenHuang
2021-12-06 20b87b7eab9c600e2445548c4306ea1b8b37b275
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<template>
    <div>
        <el-row type="flex" class="rowStyle">
 
            <el-col :xs="2" :sm="1" :class="{'state': agentInfo.new}"></el-col>
            <el-col :xs="22" :sm="23">
                <el-row type="flex">
                    <el-col class="flex_column" :xs="5" :sm="3">
                        <UiAvatar
                            :size="50"
                            :fileName="avatarFileName"
                            @click.native="showAgentDetail(agentInfo.agentNo)"
                        ></UiAvatar>
                        <div>
                            <i class="icon-star pam-icon icon--yellow satisfaction"  v-if="!(latestContactedAppointment && !latestContactedAppointment.satisfactionScore)"></i>
                            <span v-if="agentInfo.contactStatus !== 'contacted'">{{ agentInfo.avgScore }}</span>
                            <span v-if="agentInfo.contactStatus === 'contacted'">
                                {{ latestContactedAppointment && latestContactedAppointment.satisfactionScore || '未填滿意度' }}
                            </span>
                        </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 expertises"
                                :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="agentInfo.contactStatus + 'Btn'"
                        >{{ contactTxt }}</el-button>
                        <div class="updateTime" v-if="updateTime">{{updateTime | 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>
        </Ui-Dialog>
        <PopUpFrame :isOpen.sync="reviewsBtn" drawerSize='30%'>
            <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>
    </div>
</template>
 
<script lang="ts">
import { Vue, Component, Prop, Emit, Action, State } from 'nuxt-property-decorator';
import { getAppointmentDetail, UserReviewsConsultantsParams, userReviewsConsultants  } from '~/assets/ts/api/consultant';
import { Consultants, Appointment } from '~/assets/ts/models/consultant.model';
import { isLogin } from '~/assets/ts/auth';
import { isMobileDevice } from '~/assets/ts/device';
 
 
@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 {
    @Action removeFromMyConsultantList!: (agentNo: string) => Promise<boolean>;
    @Action storeConsultantList!: any;
    @Prop() agentInfo!: Consultants;
    isVisibleDialog = false;
    reviewsBtn = false;
    status = false;
    width: string = '';
    inputScore = 0;
    
    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];
    }
    
    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 expertises() {
        return this.agentInfo.expertise ? this.agentInfo.expertise : this.agentInfo.expertise;
    }
    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 updateTime() {
        return isLogin() ? this.agentInfo.updateTime : '';
    }
 
    get hopeContactTime() {
        const contactList = this.appointmentDetail.hopeContactTime
            .split("'").map(item => item.slice(0, item.length));
        return contactList.filter(item => !!item && item !== ",")
    }
 
    reserveCommunication() {
        const contactStatus = this.agentInfo.contactStatus;
        if (!contactStatus || contactStatus === 'picked') {
            isLogin()
                ? this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`)
                : this.$router.push('/login');
        } else {
            this.openPopUp();
        }
    }
 
    openPopUp() {
    const latestReservedAppointment = this.agentInfo.appointments!
                                        .filter((appointment) => appointment.communicateStatus !== 'contacted')
                                        .sort((preAppointment, nextAppointment) => +nextAppointment.appointmentDate - +preAppointment.appointmentDate)[0];
        getAppointmentDetail(this.latestContactedAppointment 
                            ? this.latestContactedAppointment.id 
                            : latestReservedAppointment.id).then(res => {
            this.appointmentDetail = {
                ...this.appointmentDetail,
                ...res.data
            };
            this.width = isMobileDevice() ? '80%' : '';
            this.isVisibleDialog = true;
        });
    }
 
    removeAgent() {
        this.removeFromMyConsultantList(this.agentInfo.agentNo).then((removeOk) => {
            console.log('removeOk?', 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();
        });
    }
}
 
</script>
 
<style lang="scss" scoped>
    .rowStyle {
        padding: 10px;
        background-color: $PRIMARY_WHITE;
        margin-bottom: 10px;
        display: flex;
        justify-content: space-between;
 
        .state {
            width: 10px;
            height: 10px;
            border-radius: 50px;
            background-color: $YELLOW;
            margin: auto 0;
        }
 
        .satisfaction {
            font-size: 12px;
            font-weight: bold;
            margin-top: 5px;
        }
 
        .professionals {
            height: 20px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            margin: 5px 0 10px 0;
 
            .professionalsTxt {
                font-size: 12px;
                font-weight: bold;
                margin-right: 5px;
            }
        }
 
        .delete {
            color: $PRIMARY_RED;
            font-size: 14px;
            font-weight: bold;
            cursor: pointer;
        }
 
        .reservedBtn {
            color: $SKY_BLUE;
            border-color: $SKY_BLUE;
 
            &:focus {
                color: $PRIMARY_WHITE;
                background-color: $SKY_BLUE;
                opacity: 0.5;
            }
        }
 
        .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;
            text-align: right;
        }
    }
 
    .flex_column {
        display: flex;
        flex-direction: column;
        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>