¤ñ¹ï·sÀÉ®× |
| | |
| | | import { Vue, Component, State, Action, Watch } from 'nuxt-property-decorator'; |
| | | import { addFavoriteConsultant, appointmentDemand, AppointmentParams, AppointmentRequests ,editAppointment,RegisterInfo } from '~/assets/ts/api/consultant'; |
| | | import { getRequestQuestionFromStorage, getRequestsFromStorage, removeRequestQuestionFromStorage, setRequestsToStorage } from '~/assets/ts/storageRequests'; |
| | | import _ from 'lodash'; |
| | | import { isLogin } from '~/assets/ts/auth'; |
| | | import { Consultant } from '~/assets/ts/models/consultant.model'; |
| | | import { ContactType } from '~/assets/ts/models/enum/ContactType'; |
| | | import { Gender } from '~/assets/ts/models/enum/gender.enum'; |
| | | |
| | | @Component |
| | | export default class Questionnaire extends Vue { |
| | | @State('myConsultantList') myConsultantList!: Consultant[]; |
| | | @Action storeConsultantList!: () => Promise<number>; |
| | | |
| | | 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:'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; |
| | | isEditPopup = false; |
| | | isEditBtn = false; |
| | | |
| | | appointmentId = 0; |
| | | |
| | | 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'); |
| | | } |
| | | }) |
| | | } |
| | | |
| | | async fetch() { |
| | | if (isLogin()) { |
| | | await this.storeConsultantList(); |
| | | }; |
| | | } |
| | | |
| | | 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() { |
| | | if (this.isEditBtn) { |
| | | this.sentEditAppointmentDemand(); |
| | | } else { |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | private sentEditAppointmentDemand() { |
| | | const info = { |
| | | ...this.myRequest, |
| | | requirement: _.map(this.myRequest.requirement,o=>o).toString(), |
| | | hopeContactTime: this.myRequest.phone && this.phoneValid ? this.getHopeContactTime() :'', |
| | | id: this.appointmentId, |
| | | otherRequirement: null |
| | | } |
| | | editAppointment(info).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('/') |
| | | } |
| | | |
| | | private getLatestReserved(agentNo) { |
| | | const agentInfo = this.myConsultantList.filter(item => item.agentNo === agentNo); |
| | | |
| | | const appointmentInfo = agentInfo.length > 0 && agentInfo[0].appointments |
| | | ? agentInfo[0].appointments! |
| | | .filter((appointment) => appointment.communicateStatus !== 'contacted') |
| | | .map((reversedAppointment) => { |
| | | return { |
| | | ...reversedAppointment, |
| | | sortDate: new Date(reversedAppointment.appointmentDate) |
| | | } |
| | | }) |
| | | .sort((preAppointment, nextAppointment) => +nextAppointment.sortDate - +preAppointment.sortDate)[0] |
| | | : null; |
| | | return this.getReservedData(appointmentInfo); |
| | | } |
| | | |
| | | private getReservedData(appointmentInfo) { |
| | | if (appointmentInfo) { |
| | | const hopeContactTime = appointmentInfo!.hopeContactTime.split("'") |
| | | .filter(item => item && item !== ','); |
| | | this.appointmentId = appointmentInfo.id; |
| | | return { |
| | | age: appointmentInfo.age, |
| | | agentNo: appointmentInfo.agentNo, |
| | | contactType: appointmentInfo.contactType, |
| | | email: appointmentInfo.email || '', |
| | | gender: appointmentInfo.gender, |
| | | hopeContactTime: hopeContactTime.map(item => { |
| | | const info = item.split('ã'); |
| | | return { |
| | | selectWeekOptions: info[0].split(','), |
| | | selectTimesOptions: info[1].split(',') |
| | | } |
| | | }), |
| | | job: appointmentInfo.job, |
| | | phone: appointmentInfo.phone || '', |
| | | requirement: appointmentInfo.requirement.split(',') |
| | | } |
| | | } else { |
| | | return { |
| | | age: '', |
| | | agentNo: '', |
| | | contactType: '', |
| | | email: '', |
| | | gender: '', |
| | | hopeContactTime: [], |
| | | job: '', |
| | | phone: '', |
| | | requirement: [] |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Watch('myConsultantList') onMyConsultantListChange() { |
| | | if (this.isLogin && this.myConsultantList.length > 0) { |
| | | const editAppointment = this.getLatestReserved(this.$route.params.agentNo); |
| | | |
| | | if (editAppointment.agentNo) { |
| | | this.myRequest = JSON.parse(JSON.stringify(editAppointment)); |
| | | if (!this.$route.query || this.$route.query.edit !== 'true') { |
| | | this.isEditPopup = true; |
| | | } |
| | | this.isEditBtn = true; |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |