Skip to content

Commit 9b538f6

Browse files
authored
Merge pull request #414 from kaizumaki/feature/issue-413-add-function-search
患者一覧の検索機能を追加
2 parents a85631a + ab5c280 commit 9b538f6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

components/SearchField.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
type="search"
55
placeholder="検索"
66
:value="value"
7-
@input="$emit('input', $event.target.value)"
7+
@keydown.enter="search"
88
/>
99
</template>
1010

@@ -18,6 +18,12 @@ export default Vue.extend({
1818
default: '',
1919
},
2020
},
21+
methods: {
22+
search($event: { keyCode: number; target: { value: string } }): void {
23+
if ($event.keyCode !== 13) return
24+
this.$emit('input', $event.target.value)
25+
},
26+
},
2127
})
2228
</script>
2329

pages/center/_centerId/index.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PatientRegistered v-else :new-patient="newPatient" :sended="sended" />
2525
</ModalBase>
2626
<div class="searchContainer">
27-
<SearchField v-model="inputSearch" />
27+
<SearchField v-model="inputSearch" @input="handleSearch" />
2828
<SortSelect v-model="sortSelect" @input="handleSortSelect" />
2929
<HiddenSelect v-model="displaySelect" @input="handleDisplaySelect" />
3030
</div>
@@ -55,7 +55,7 @@
5555
</template>
5656

5757
<script lang="ts">
58-
import { Component, Vue } from 'vue-property-decorator'
58+
import { Component, Vue, Watch } from 'vue-property-decorator'
5959
import ActionButton from '@/components/ActionButton.vue'
6060
import PlusIcon from '@/static/icon-plus.svg'
6161
import ModalBase from '@/components/ModalBase.vue'
@@ -90,6 +90,7 @@ export default class CenterId extends Vue {
9090
showModal = false
9191
registered = false
9292
inputSearch = ''
93+
searchWord = ''
9394
sortSelect = ''
9495
displaySelect = 'show-only-display-true'
9596
patients: Patient[] = []
@@ -115,6 +116,13 @@ export default class CenterId extends Vue {
115116
}
116117
}
117118
119+
@Watch('searchWord')
120+
onSearchWordChanged(newValue: string, oldValue: string) {
121+
if (newValue !== oldValue) {
122+
this.fetchPatients()
123+
}
124+
}
125+
118126
checkAndFetchPatients(): void {
119127
authStore.checkIsExpired().then((expired) => {
120128
if (expired) {
@@ -140,6 +148,14 @@ export default class CenterId extends Vue {
140148
? item.display
141149
: !item.display
142150
})
151+
if (this.searchWord) {
152+
this.patients = this.patients.filter((item) => {
153+
const pattern = new RegExp(this.searchWord, 'ig')
154+
return (
155+
pattern.test(item.phone) || (item.memo && pattern.test(item.memo))
156+
)
157+
})
158+
}
143159
this.sortSelect = utilsStore.getSortItem
144160
this.sortItems(this.sortSelect)
145161
})
@@ -191,6 +207,10 @@ export default class CenterId extends Vue {
191207
this.fetchPatients()
192208
}
193209
210+
handleSearch(value: string): void {
211+
this.searchWord = value
212+
}
213+
194214
handleInputTel(): void {
195215
this.errorMessage = ''
196216
}

0 commit comments

Comments
 (0)