保誠-保戶業務員媒合平台
Mila
2021-12-22 6a4966b8898509299cd4d43cc31e2ae2985d0cfe
PAMapp/pages/quickFilter/index.vue
@@ -5,37 +5,31 @@
                v-for="(question, index) in questionList"
                :key="index"
                class="subTitle quickBtn"
                :disabled="question.name === 'status'"
                :class="{'isActive': isActive(question.name)}"
                @click="openPopUp(question)"
            >{{question.title}}</el-button>
        </div>
        <h5 class="mdTxt mb-10 mt-30">篩選條件</h5>
        <div>
            <Ui-Tags
                v-if="selectedItem.gender"
                @removeTag="removeTag('gender')"
            >
                {{selectedItem.gender === 'male' ? '男性' : '女性'}}
            </Ui-Tags>
            <Ui-Tags
                v-if="selectedItem.avgScore"
                @removeTag="removeTag('avgScore')"
            >
                {{selectedItem.avgScore + '星以上滿意度'}}
            </Ui-Tags>
            <template v-if="selectedItem.communicationStyles">
                <Ui-Tags
                    v-for="(item, index) in selectedItem.communicationStyles"
                    :key="index"
                    @removeTag="removeTag('communicationStyles', index)"
            <template v-if="confirmItem.length > 0">
                <UiTags
                    v-for="(item, index) in confirmItem" :key="index"
                    @removeTag="removeTag(item.value)"
                >
                    {{item}}
                </Ui-Tags>
                    <span v-if="item.option === 'gender'">{{item.value === 'male' ? '男性' : '女性'}}</span>
                    <span v-else-if="item.option === 'seniority'" class="mdTxt lighter">
                        {{item.value | formatSeniorityTitle}}
                        <span class="smTxt">{{item.value | formatSenioritySubTitle}}</span>
                    </span>
                    <!-- TODO:隱藏滿意度 -->
                    <!-- <span v-else-if="item.option === 'avgScore'">{{item.value + '星以上滿意度'}}</span> -->
                    <span v-else>{{item.value}}</span>
                </UiTags>
            </template>
            <div class="mb-10" v-if="selectedItem.onlineState"></div>
            <div class="emptyBox text--mid_grey"
                v-if="isEmpty">
            <div
                v-else
                class="emptyBox text--mid_grey"
            >
                <p class="smTxt">尚無篩選</p>
            </div>
        </div>
@@ -59,131 +53,155 @@
        </div>
        <PopUpFrame
            :isOpen.sync="questionPopUp"
            :drawerSize="questionOption.name === 'communicationStyles' ? '50%' : '30%'"
            @update:isOpen="closePopUp"
            :isOpen.sync="isOpenQuestionPopUp"
            :dialogWidth="'400px'"
            class="pam-myDemand-dialog"
        >
            <QuickFilterSelector
                ref="quickFilterRef"
                :drawerVisible.sync="questionPopUp"
                :isOpenQuestionPopUp="isOpenQuestionPopUp"
                :questionOption="questionOption"
                :selectedItem="selectedItem"
                @confirm="confirm"
                :confirmItem="confirmItem"
            ></QuickFilterSelector>
        </PopUpFrame>
    </div>
</template>
<script lang="ts">
import { Vue, Component } from 'nuxt-property-decorator';
import { Consultants, FastQueryParams } from '~/assets/ts/api/consultant';
import QuickFilterDrawer from '~/components/QuickFilter/QuickFilterSelector.vue';
import { Vue, Component, namespace } from 'nuxt-property-decorator';
import { Consultant } from '~/assets/ts/models/consultant.model';
import { questionList } from '~/assets/ts/const/quickFilter-questionList';
import { FastQueryParams, QuestionOption, Selected } from '~/assets/ts/models/quickFilter.model';
import { fastQuery } from '~/assets/ts/api/consultant';
@Component
export default class QuickFilter extends Vue {
    questionPopUp = false;
    consultantList: Consultants[] = [];
    questionOption = {};
    selectedItem: FastQueryParams = {
        gender: '',
        avgScore: 0,
        communicationStyles: [],
        status: ''
    };
    questionList: QuestionOption[] = [
        {
            name: 'gender',
            title: '顧問性別',
            detail: [
                { name: '男性', value: 'male', className: 'btn_man'},
                { name: '女性', value: 'female', className: 'btn_woman'}
            ],
            type: 'radio',
const localStorage = namespace('localStorage');
@Component({
    filters: {
        formatSeniorityTitle(value) {
            if (value === 'SENIOR') return '資深';
            if (value === 'YOUNG') return '年輕';
            return '不限';
        },
        {
            name: 'avgScore',
            title: '顧問滿意度',
            detail: [],
            type: ''
        },
        {
            name: 'communicationStyles',
            title: '溝通風格',
            detail: [
                { value: '謹慎務實', className: 'btn_owl'},
                { value: '明快主動', className: 'btn_tiger'},
                { value: '耐心傾聽', className: 'btn_koala'},
                { value: '健談風趣', className: 'btn_peacock'}
            ],
            type: 'checkbox'
        },
        {
            name: 'status',
            title: '上線狀態',
            detail: [],
            type: 'radio'
        formatSenioritySubTitle(value) {
            if (value === 'SENIOR') return '薑是老的辣';
            if (value === 'YOUNG') return '給年輕人一個機會';
            return '年齡不是問題';
        }
    ];
    }
})
export default class QuickFilter extends Vue {
    @localStorage.Mutation storageQuickFilter!: (token: string) => void;
    @localStorage.Getter quickFilterSelectedData!: Selected[];
    get isEmpty() {
        return !this.selectedItem.gender
            && !this.selectedItem.avgScore
            && this.selectedItem.communicationStyles.length === 0
            && !this.selectedItem.status
    isOpenQuestionPopUp = false;
    consultantList: Consultant[] = [];
    questionOption = {};
    confirmItem: Selected[] = [];
    questionList = questionList;
    //////////////// lifecycle ////////////////
    mounted() {
        if (this.quickFilterSelectedData && this.quickFilterSelectedData.length > 0) {
            this.confirmItem = this.quickFilterSelectedData;
            this.getRecommendList();
        }
    }
    //////////////////////////////////////////
    openPopUp(question: QuestionOption) {
        this.questionOption = question;
        this.questionPopUp =true;
        this.isOpenQuestionPopUp =true;
    }
    removeTag(type: string, index: number = 0) {
        if (type === 'gender') {
            this.selectedItem.gender = ''
        }
        if (type === 'avgScore') {
             this.selectedItem.avgScore = 0
        }
        if (type === 'communicationStyles') {
            this.selectedItem.communicationStyles.splice(index, 1)
        }
        this.isEmpty ? this.consultantList = [] : this.getRecommendList();
    removeTag(value: string) {
        this.confirmItem = this.confirmItem.filter(item => item.value !== value);
        this.confirmItem.length > 0 ? this.getRecommendList() : this.consultantList = [];
    }
    closePopUp() {
        this.selectedItem = JSON.parse(JSON.stringify((this.$refs.quickFilterRef as QuickFilterDrawer).pickedItem));
        this.getRecommendList();
    confirm(event: Selected) {
        this.setConfirmData(event);
        this.confirmItem.length > 0 ? this.getRecommendList() : this.consultantList = [];
        this.isOpenQuestionPopUp = false;
    }
    getRecommendList() {
        const data = {
            gender: this.selectedItem.gender,
            communicationStyles: this.selectedItem.communicationStyles,
            avgScore: this.selectedItem.avgScore,
            status: this.selectedItem.status
    isActive(name: string) {
        return name === 'gender' && !!this.getGender()
            || name === 'avgScore' && !!this.getAvgScore()
            || name === 'communicationStyles' && !!this.getCommunicationStyles().length
            || name === 'seniority' && !!this.getSeniority()
    }
    //////////////// private ////////////////
    private getGender(): string {
        return this.filterSingleSelected('gender');
    }
    private getAvgScore(): number {
        return this.filterSingleSelected('avgScore');
    }
    private getSeniority(): string {
        return this.filterSingleSelected('seniority');
    }
    private getCommunicationStyles(): string[] {
        return this.confirmItem.filter(item => item.option === 'communicationStyles').map(i => i.value);
    }
    private filterSingleSelected(name: string) {
        const filter = this.confirmItem.filter(item => item.option === name);
        return filter.length > 0
            ? filter[0].value
            : (name === 'avgScore' ? 0 : '');
    }
    private setConfirmData(event: Selected) {
        if (event.option === 'communicationStyles') {
            this.filterCommunicationStyles(event);
        } else {
            const findIndex = this.confirmItem.findIndex(item => item.option === event.option);
            findIndex === -1 ? this.confirmItem.push(event) : this.confirmItem[findIndex] = event;
        }
    }
    private filterCommunicationStyles(event: Selected) {
        const confirmValue = this.confirmItem
            .filter(item => item.option === 'communicationStyles')
            .map(i => i.value);
        const pickerValue = event.value;
        this.confirmItem = this.confirmItem
            .filter(item => pickerValue.includes(item.value) || item.option !== 'communicationStyles');
        const addValue = pickerValue.filter(item => !confirmValue.includes(item)).map(i => {
            return {
                option: 'communicationStyles',
                value: i
            }
        })
        if (addValue.length > 0) {
            this.confirmItem.push(...addValue);
        }
    }
    private getRecommendList() {
        const data: FastQueryParams = {
            gender: this.getGender(),
            communicationStyles: this.getCommunicationStyles(),
            avgScore: this.getAvgScore(),
            status: '',
            seniority: this.getSeniority()
        }
        fastQuery(data).then((res) => this.consultantList = res.data)
        fastQuery(data).then((consultantList) => {
            this.consultantList = consultantList;
            this.storageQuickFilter(JSON.stringify(this.confirmItem))
        })
    }
}
export interface QuestionOption {
    title: string;
    detail: Detail[];
    type: string;
    name: string;
}
interface Detail {
    value: string;
    name?: string;
    className: string;
}
</script>
@@ -219,17 +237,11 @@
            text-align: center;
            box-shadow: 0 0 6px #22222229;
            border-radius: 10px;
            color: $PRIMARY_WHITE;
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            background-image: url('~/assets/images/quickFilter/btn_bg.svg');
            border-color: $CORAL;
            &:disabled {
            &.isActive {
                background-color: $CORAL;
                color: $PRIMARY_WHITE;
                border-color: $LIGHT_GREY;
                background-color: $LIGHT_GREY;
                background-image: none;
            }
        }
        .quickBtn+.quickBtn {