From 472fd20c108714b28be49d4fedee5bbabe1b2358 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期五, 04 三月 2022 17:40:47 +0800 Subject: [PATCH] Merge branch 'Phase3' into pollex-dev --- PAMapp/components/AddAndReservedBtns.vue | 88 ++++++++++++++++++++++++-------------------- 1 files changed, 48 insertions(+), 40 deletions(-) diff --git a/PAMapp/components/AddAndReservedBtns.vue b/PAMapp/components/AddAndReservedBtns.vue index 41c3e04..14d3cfb 100644 --- a/PAMapp/components/AddAndReservedBtns.vue +++ b/PAMapp/components/AddAndReservedBtns.vue @@ -1,61 +1,69 @@ <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" + @click="navigateToReservationForm" type="primary" >�脰����</el-button> </el-row> </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 roleStorage = namespace('localStorage'); @Component export default class AddAndReservedBtns extends Vue { - @Prop() agentInfo!: Consultants; - @Prop() cusClass!: string; + + @Action + addToMyConsultantList!: (consultantToAdd: Consultant) => Promise<boolean> + + @State('myConsultantList') + myConsultantList!: Consultant[]; + + @Prop() + agentInfo!: Consultant; + + @Prop() + cusClass!: string; + + @roleStorage.Getter + isUserLogin!: boolean; + isVisiblePopUp = false; - addConsultant(item: Consultants) { - console.log('click') - if (isLogin()) { - addFavoriteConsultant([item.agentNo]).then(res => this.openPopUp()) - } else { - this.addConsultantToStorage(item); + + ////////////////////////////////////////////////////////////////////// + + @Emit('openPopUp') + openPopUp(popUpTxt: string = '����憿批��'): string { + return popUpTxt; + } + + ////////////////////////////////////////////////////////////////////// + + addConsultant(item: Consultant): void { + if (!this.isUserLogin) { + item = { + ...item, + updateTime: new Date().toISOString() + }; } + this.addToMyConsultantList(item).then(addOk => { + addOk && this.openPopUp(); + }); } - 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); - } + navigateToReservationForm(): void { + this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`); } - storageFavoriteAndPopUp(item: Consultants[]) { - setFavoriteToStorage(item); - this.openPopUp(); - } - - reserveCommunication() { - isLogin() ? this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`) : this.$router.push('/login'); - } - - @Emit('openPopUp') openPopUp(popUpTxt: string = '����憿批��') { - return popUpTxt + get isAdded() { + return this.myConsultantList.find(item => item.agentNo === this.agentInfo.agentNo) + ? true : false } } -</script> \ No newline at end of file +</script> -- Gitblit v1.8.0