保誠-保戶業務員媒合平台
Tomas
2021-12-08 b6661a090e8bcf8f45be24a01b6a7bb08e3aaff1
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
import { Vue, Component } from 'nuxt-property-decorator';
import { addFavoriteConsultant, appointmentDemand, AppointmentParams, AppointmentRequests ,RegisterInfo } from '~/assets/ts/api/consultant';
import { getRequestsFromStorage, setRequestsToStorage, getRequestQuestionFromStorage, removeRequestQuestionFromStorage  } from '~/assets/ts/storageRequests';
import { Gender } from '~/assets/ts/models/enum/gender.enum';
import { ContactType } from '~/assets/ts/models/enum/ContactType';
import _ from 'lodash';
import { isLogin } from '~/assets/ts/auth';
 
@Component
export default class Questionnaire extends Vue {
  genderOptions=[
    {
      title:'男性',
      label:Gender.MALE,
    },
    {
      title:'女性',
      label:Gender.FEMALE,
    }
  ];
 
  requirementOptions=[
    {
      title:'健康與保障',
      label:'健康與保障',
    },
    {
      title:'子女教育',
      label:'子女教育',
    },
    {
      title:'資產規劃',
      label:'資產規劃',
    },
    {
      title:'樂活退休',
      label:'樂活退休',
    },
    {
      title:'保單健檢/規劃',
      label:'保單健檢/規劃',
    },
    {
      title:'分紅保單',
      label:'分紅保單',
    },
  ];
 
  ageRangeOptions=[
    {
      title:'20歲以下',
      label:'under_20',
    },
    {
      title:'21-30 歲',
      label:'21-30'
    },
    {
      title:'31-40 歲',
      label:'31-40'
    },
    {
      title:'41-50 歲',
      label:'41-50'
    },
    {
      title:'46-55 歲',
      label:'46-55',
    },
    {
      title:'51-60 歲',
      label:'51-60',
    },
    {
      title:'61-70 歲',
      label:'61-70',
    },
    {
      title:'71 歲以上',
      label:'over_71',
    }
  ];
 
  quesAboutList = [
                {
                    title:'健康與保障',
                    content:'唯有把身體照顧好,才是保障幸福之本,不做盲目燃燒的蠟燭,只做綻開的陽光,陪孩子多走一哩路,人生的美正要開展。'
                },
                {
                    title:'子女教育',
                    content:'孩子,我們是雙方的導師也是學生,面對未來要並肩作戰,學會勇敢無畏、克服挫折、善於理財,這條路上我們一起學。'
                },
                {
                    title:'資產規劃',
                    content:'真正的財富來自嚴謹規劃資產傳承,為人生蓋一堵抵禦財務風險的牆,確保資產穩健成長,替全家族的未來做好萬全準備。'
                },
                {
                    title:'樂活退休',
                    content:'拼一輩子,退休後的日子要輕鬆快活,就得提早透過保險商品規劃退休財務,替自己創造穩定收入,為精彩的熟年人生揭開序幕。'
                },
                {
                    title:'保單健檢/規劃',
                    content:'全面檢視自己的保障結構是否符合現在或未來的風險移轉需求。'
                },
                {
                    title:'分紅保單',
                    content:'分紅保單 分紅保單是兼具「分攤風險」與「紅利共享」特色的保單,具有一定穩定度,讓你可以同時享有壽險保障及紅利!'
                }
  ];
 
  myRequest: AppointmentRequests = {
    phone          : this.userInfo?.phone ? this.userInfo.phone                               : '',
    email          : this.userInfo?.email ? this.userInfo.email                               : '',
    contactType    : _.isEqual(this.userInfo?.contactType,ContactType.SMS) ? ContactType.PHONE: ContactType.EMAIL,
    gender         : '',
    age            : '',
    job            : '',
    requirement    : [],
    hopeContactTime: [{
      selectWeekOptions : [],
      selectTimesOptions: [],
    }],
    agentNo: '',
  };
 
  showDrawer= false;
  sendReserve = false;
 
  beforeRouteEnter(to: any, from: any, next: any) {
    next(vm => {
      if (from.name === 'login' && !isLogin()) {
        vm.$router.go(-1);
        return;
      }
 
      if (!isLogin()) {
        vm.$router.push('/login');
      }
    })
  }
 
  mounted(): void {
    this.setMyRequest();
  }
 
  private setMyRequest(): void {
    const storageMyRequest = getRequestsFromStorage();
    const storageMyQuestion = getRequestQuestionFromStorage();
 
    if (storageMyRequest) {
      this.myRequest = {
        ...storageMyRequest,
        hopeContactTime: storageMyRequest.hopeContactTime?.length
                          ? storageMyRequest.hopeContactTime
                          : [{
                              selectWeekOptions: [],
                              selectTimesOptions: [],
                            }],
      };
    }
 
    if (storageMyQuestion) {
      this.myRequest = {
        ...this.myRequest,
        requirement: storageMyQuestion
      }
      removeRequestQuestionFromStorage();
    }
  }
 
  get phoneValid(): boolean {
    const rule = /^09[0-9]{8}$/;
    return this.myRequest.phone
          ? rule.test(this.myRequest.phone) && _.isEqual(this.myRequest.phone.length,10)
          : true;
  }
 
  get userInfo(): RegisterInfo {
    const initUserInfo = JSON.parse(localStorage.getItem('userInfo')!);
    return initUserInfo;
  }
 
  get isDisabledSubmitBtn(): boolean {
         return _.includes(this.myRequest.contactType,ContactType.PHONE)
    ? !this.isHopeContactTimeDone()
    : !this.phoneValid;
  }
 
  get isLogin() {
    return isLogin();
  }
 
  private isHopeContactTimeDone():boolean{
    return this.myRequest.hopeContactTime[0]?.selectWeekOptions.length >0 && this.myRequest.hopeContactTime[0]?.selectTimesOptions.length >0;
  }
 
  sentDemand() {
    addFavoriteConsultant([this.$route.params.agentNo]).then(res => this.sentAppointmentDemand());
  }
 
  private sentAppointmentDemand() {
      const data: AppointmentParams = {
        ...this.myRequest,
        requirement: _.map(this.myRequest.requirement,o=>o).toString(),
        hopeContactTime: this.myRequest.phone && this.phoneValid ? this.getHopeContactTime() :'',
        agentNo: this.$route.params.agentNo
      };
 
      appointmentDemand(data).then(res => {
          this.sendReserve = true;
          this.myRequest.hopeContactTime = [];
          setRequestsToStorage(this.myRequest);
      });
  }
 
  getHopeContactTime() {
      const selectedHopeContactTime = this.myRequest.hopeContactTime.filter((i) => i.selectWeekOptions?.length && i.selectTimesOptions?.length);
      return selectedHopeContactTime.map(i => {
          return `'${i.selectWeekOptions}、${i.selectTimesOptions}'`}
      ).toString();
  }
 
  closeReservePopUp() {
      this.sendReserve = false;
      this.$router.push('/')
  }
 
}