55
55
</template >
56
56
57
57
<script lang="ts">
58
- import { Component , Vue } from ' vue-property-decorator'
58
+ import { Component , Vue , Watch } from ' vue-property-decorator'
59
59
import ActionButton from ' @/components/ActionButton.vue'
60
60
import PlusIcon from ' @/static/icon-plus.svg'
61
61
import ModalBase from ' @/components/ModalBase.vue'
@@ -90,6 +90,7 @@ export default class CenterId extends Vue {
90
90
showModal = false
91
91
registered = false
92
92
inputSearch = ' '
93
+ searchWord = ' '
93
94
sortSelect = ' '
94
95
displaySelect = ' show-only-display-true'
95
96
patients: Patient [] = []
@@ -115,6 +116,13 @@ export default class CenterId extends Vue {
115
116
}
116
117
}
117
118
119
+ @Watch (' searchWord' )
120
+ onSearchWordChanged(newValue : string , oldValue : string ) {
121
+ if (newValue !== oldValue ) {
122
+ this .fetchPatients ()
123
+ }
124
+ }
125
+
118
126
checkAndFetchPatients(): void {
119
127
authStore .checkIsExpired ().then ((expired ) => {
120
128
if (expired ) {
@@ -140,6 +148,14 @@ export default class CenterId extends Vue {
140
148
? item .display
141
149
: ! item .display
142
150
})
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
+ }
143
159
this .sortSelect = utilsStore .getSortItem
144
160
this .sortItems (this .sortSelect )
145
161
})
@@ -192,22 +208,7 @@ export default class CenterId extends Vue {
192
208
}
193
209
194
210
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
211
212
}
212
213
213
214
handleInputTel(): void {
0 commit comments