From 18098111cc905e88524e7d9ce788b742637e0824 Mon Sep 17 00:00:00 2001 From: Mila <Mila@pollex.com.tw> Date: 星期二, 14 十二月 2021 16:02:04 +0800 Subject: [PATCH] refactor: 快速篩選 1. 整理 methods 順序 2. 整理 interface、const --- PAMapp/pages/quickFilter/index.vue | 111 +++++++++++++++++-------------------------------------- 1 files changed, 35 insertions(+), 76 deletions(-) diff --git a/PAMapp/pages/quickFilter/index.vue b/PAMapp/pages/quickFilter/index.vue index c6ef025..7c8764f 100644 --- a/PAMapp/pages/quickFilter/index.vue +++ b/PAMapp/pages/quickFilter/index.vue @@ -17,7 +17,8 @@ @removeTag="removeTag(item.value)" > <span v-if="item.option === 'gender'">{{item.value === 'male' ? '���' : '憟單��'}}</span> - <span v-else-if="item.option === 'avgScore'">{{item.value + '��誑銝遛��漲'}}</span> + <!-- TODO:���遛��漲 --> + <!-- <span v-else-if="item.option === 'avgScore'">{{item.value + '��誑銝遛��漲'}}</span> --> <span v-else>{{item.value}}</span> </UiTags> </template> @@ -49,7 +50,6 @@ <PopUpFrame :isOpen.sync="isOpenQuestionPopUp" - :drawerSize="questionOption.name === 'communicationStyles' ? '55%' : '35%'" :dialogWidth="'400px'" class="pam-myDemand-dialog" > @@ -66,10 +66,10 @@ <script lang="ts"> import { Vue, Component, namespace } from 'nuxt-property-decorator'; -import { FastQueryParams } from '~/assets/ts/api/consultant'; import { Consultant } from '~/assets/ts/models/consultant.model'; -import { Selected } from '~/components/QuickFilter/QuickFilterSelector.vue'; import { fastQuery } from '~/assets/ts/api/consultant'; +import { questionList } from '~/assets/ts/const/quickFilter-questionList'; +import { FastQueryParams, QuestionOption, Selected } from '~/assets/ts/models/quickFilter.model'; const localStorage = namespace('localStorage'); @Component @@ -81,41 +81,9 @@ consultantList: Consultant[] = []; questionOption = {}; confirmItem: Selected[] = []; - questionList: QuestionOption[] = [ - { - name: 'gender', - title: '憿批��批', - detail: [ - { name: '���', value: 'male', className: 'btn_man'}, - { name: '憟單��', value: 'female', className: 'btn_woman'} - ], - type: 'radio' - }, - { - 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' - // } - ]; + questionList = questionList; + //////////////// lifecycle //////////////// mounted() { if (this.quickFilterSelectedData && this.quickFilterSelectedData.length > 0) { this.confirmItem = this.quickFilterSelectedData; @@ -123,26 +91,8 @@ } } - gender(): string { - const filter = this.confirmItem.filter(item => item.option === 'gender').map(i => i.value); - return filter.length === 0 ? '' : filter[0]; - } - avgScore(): number { - const filter = this.confirmItem.filter(item => item.option === 'avgScore').map(i => i.value); - return filter.length === 0 ? '' : filter[0]; - } - - communicationStyles(): string[] { - return this.confirmItem.filter(item => item.option === 'communicationStyles').map(i => i.value); - } - - isActive(name: string) { - return name === 'gender' && !!this.gender() - || name === 'avgScore' && !!this.avgScore() - || name === 'communicationStyles' && !!this.communicationStyles().length - } - + ////////////////////////////////////////// openPopUp(question: QuestionOption) { this.questionOption = question; this.isOpenQuestionPopUp =true; @@ -159,7 +109,29 @@ this.isOpenQuestionPopUp = false; } - setConfirmData(event: Selected) { + isActive(name: string) { + return name === 'gender' && !!this.gender() + || name === 'avgScore' && !!this.avgScore() + || name === 'communicationStyles' && !!this.communicationStyles().length + } + + + //////////////// private //////////////// + private gender(): string { + const filter = this.confirmItem.filter(item => item.option === 'gender').map(i => i.value); + return filter.length === 0 ? '' : filter[0]; + } + + private avgScore(): number { + const filter = this.confirmItem.filter(item => item.option === 'avgScore').map(i => i.value); + return filter.length === 0 ? '' : filter[0]; + } + + private communicationStyles(): string[] { + return this.confirmItem.filter(item => item.option === 'communicationStyles').map(i => i.value); + } + + private setConfirmData(event: Selected) { if (event.option === 'communicationStyles') { this.filterCommunicationStyles(event); } else { @@ -168,7 +140,7 @@ } } - filterCommunicationStyles(event: Selected) { + private filterCommunicationStyles(event: Selected) { const confirmValue = this.confirmItem .filter(item => item.option === 'communicationStyles') .map(i => i.value); @@ -188,7 +160,7 @@ } } - getRecommendList() { + private getRecommendList() { const data: FastQueryParams = { gender: this.gender(), communicationStyles: this.communicationStyles(), @@ -196,25 +168,12 @@ status: '' } - 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> @@ -240,7 +199,7 @@ .quickBtnBlock { display: flex; width: 100%; - height: 132px; + // height: 132px; flex-wrap: wrap; justify-content: space-between; -- Gitblit v1.8.0