| | |
| | | async storeConsultantList() { |
| | | const localData = getFavoriteFromStorage(); |
| | | |
| | | // 使用 Optional Chaining (安全的選擇性屬性存取) 來處理可能為 null 或 undefined 的情況 |
| | | if (!this.isUserLogin) { |
| | | this.context.commit('updateConsultantList', localData) |
| | | this.context.commit('updateConsultantList', localData); |
| | | return; |
| | | }; |
| | | |
| | | } |
| | | |
| | | if (localData?.length) { |
| | | const addFavoriteAgentList: AddFavoriteConsultantItem[] = localData.map(i => ({ agentNo: i.agentNo, createdTime: i.updateTime})); |
| | | await queryConsultantService.addFavoriteConsultant(addFavoriteAgentList).then(res => { |
| | | localStorage.removeItem('favoriteConsultant') |
| | | }) |
| | | |
| | | // 確保異步操作的回傳結果不為 null 或 undefined |
| | | const response = await queryConsultantService.addFavoriteConsultant(addFavoriteAgentList); |
| | | if (response !== null) { |
| | | localStorage.removeItem('favoriteConsultant'); |
| | | } else { |
| | | throw new Error('queryConsultantService.addFavoriteConsultant returned null-like value.'); |
| | | } |
| | | } |
| | | |
| | | myConsultantService.getFavoriteConsultantList().then(data => { |
| | | this.context.commit('updateConsultantList', data); |
| | | }) |
| | | |
| | | myConsultantService.getAllGroupByConsultant().then((data) => { |
| | | this.context.commit('updateAppointmentGroupByConsultantList', data); |
| | | }) |
| | | // 確保異步操作的回傳結果不為 null 或 undefined |
| | | const favoriteConsultantList = await myConsultantService.getFavoriteConsultantList(); |
| | | if (favoriteConsultantList !== null) { |
| | | this.context.commit('updateConsultantList', favoriteConsultantList); |
| | | } else { |
| | | throw new Error('myConsultantService.getFavoriteConsultantList returned null-like value.'); |
| | | } |
| | | |
| | | // 確保異步操作的回傳結果不為 null 或 undefined |
| | | const groupByConsultantData = await myConsultantService.getAllGroupByConsultant(); |
| | | if (groupByConsultantData !== null) { |
| | | this.context.commit('updateAppointmentGroupByConsultantList', groupByConsultantData); |
| | | } else { |
| | | throw new Error('myConsultantService.getAllGroupByConsultant returned null-like value.'); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Action |
| | | async removeFromMyConsultantList(agentNo: string) { |
| | | const left = this.myConsultantList.filter(item => item.agentNo !== agentNo); |