| | |
| | | <template> |
| | | <el-row type="flex" justify="center" :class="cusClass"> |
| | | <el-button @click="addConsultant(agentInfo)"> |
| | | <span> + 顧問清單</span> |
| | | <el-button @click="addConsultant(agentInfo)" :disabled="isAdded"> |
| | | <span> {{isAdded ? '已加入顧問清單' : '+ 顧問清單'}}</span> |
| | | </el-button> |
| | | <el-button |
| | | @click="reserveCommunication" |
| | |
| | | </template> |
| | | |
| | | <script lang="ts"> |
| | | import { Vue, Component, Prop, Emit } from 'nuxt-property-decorator'; |
| | | import { addFavoriteConsultant, Consultants } from '~/assets/ts/api/consultant'; |
| | | import { isLogin } from '~/assets/ts/auth'; |
| | | import { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant'; |
| | | import { Vue, Component, Prop, Emit, Action, State, namespace } from 'nuxt-property-decorator'; |
| | | import { Consultant } from '~/shared/models/consultant.model'; |
| | | |
| | | const localStorage = namespace('localStorage'); |
| | | @Component |
| | | export default class AddAndReservedBtns extends Vue { |
| | | @Prop() agentInfo!: Consultants; |
| | | @Action addToMyConsultantList!: (consultantToAdd: Consultant) => Promise<boolean> |
| | | @State('myConsultantList') myConsultantList!: Consultant[]; |
| | | @Prop() agentInfo!: Consultant; |
| | | @Prop() cusClass!: string; |
| | | isVisiblePopUp = false; |
| | | addConsultant(item: Consultants) { |
| | | console.log('click') |
| | | if (isLogin()) { |
| | | addFavoriteConsultant([item.agentNo]).then(res => this.openPopUp()) |
| | | } else { |
| | | this.addConsultantToStorage(item); |
| | | } |
| | | } |
| | | |
| | | addConsultantToStorage(item: Consultants) { |
| | | let agentList = [item]; |
| | | const consultantList = getFavoriteFromStorage(); |
| | | |
| | | if (consultantList) { |
| | | const isRepeat = consultantList.findIndex(i => i.agentNo === item.agentNo) === -1; |
| | | isRepeat |
| | | ? this.storageFavoriteAndPopUp(consultantList.concat(agentList)) |
| | | : this.openPopUp('已經加入顧問清單'); |
| | | |
| | | } else { |
| | | this.storageFavoriteAndPopUp(agentList); |
| | | } |
| | | } |
| | | |
| | | storageFavoriteAndPopUp(item: Consultants[]) { |
| | | setFavoriteToStorage(item); |
| | | this.openPopUp(); |
| | | addConsultant(item: Consultant) { |
| | | this.addToMyConsultantList(item).then(addOk => { |
| | | addOk && this.openPopUp(); |
| | | }); |
| | | } |
| | | |
| | | reserveCommunication() { |
| | | isLogin() ? this.$router.push('/questionnaire') : this.$router.push('/login'); |
| | | this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`); |
| | | } |
| | | |
| | | @Emit('openPopUp') openPopUp(popUpTxt: string = '成功加入顧問清單') { |
| | | return popUpTxt |
| | | } |
| | | |
| | | get isAdded() { |
| | | return this.myConsultantList.find(item => item.agentNo === this.agentInfo.agentNo) |
| | | ? true : false |
| | | } |
| | | } |
| | | </script> |
| | | </script> |