Skip to content

Commit ab5c280

Browse files
committed
検索時にintervalを操作しないように修正・正規表現match -> testに修正
1 parent 5af51ab commit ab5c280

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

pages/center/_centerId/index.vue

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
})
@@ -192,22 +208,7 @@ export default class CenterId extends Vue {
192208
}
193209
194210
handleSearch(value: string): void {
195-
if (value) {
196-
if (this.timer) {
197-
clearInterval(this.timer)
198-
}
199-
patientsStore.load(this.$route.params.centerId).then((patients) => {
200-
this.patients = patients.filter((item) => {
201-
const pattern = new RegExp(value, 'ig')
202-
return item.phone.match(pattern) || item.memo?.match(pattern)
203-
})
204-
})
205-
} else {
206-
this.fetchPatients()
207-
this.timer = setInterval(() => {
208-
this.checkAndFetchPatients()
209-
}, 30000)
210-
}
211+
this.searchWord = value
211212
}
212213
213214
handleInputTel(): void {

0 commit comments

Comments
 (0)