2018-04-23 04:27:30 +00:00
|
|
|
<template lang="pug">
|
2018-05-12 20:13:04 +00:00
|
|
|
v-dialog(
|
|
|
|
v-model='dialogOpen'
|
|
|
|
max-width='650'
|
|
|
|
)
|
2019-08-25 02:19:35 +00:00
|
|
|
v-card
|
2018-05-12 20:13:04 +00:00
|
|
|
.dialog-header
|
2019-06-15 21:05:56 +00:00
|
|
|
span {{$t('common:user.search')}}
|
2018-05-12 20:13:04 +00:00
|
|
|
v-spacer
|
|
|
|
v-progress-circular(
|
|
|
|
indeterminate
|
|
|
|
color='white'
|
|
|
|
:size='20'
|
|
|
|
:width='2'
|
|
|
|
v-show='searchLoading'
|
|
|
|
)
|
2019-08-25 02:19:35 +00:00
|
|
|
v-card-text.pt-5
|
2018-06-11 03:23:09 +00:00
|
|
|
v-text-field(
|
2019-08-11 02:14:53 +00:00
|
|
|
outlined
|
2019-06-15 21:05:56 +00:00
|
|
|
:label='$t(`common:user.searchPlaceholder`)'
|
2018-05-12 20:13:04 +00:00
|
|
|
v-model='search'
|
2019-08-11 02:14:53 +00:00
|
|
|
prepend-inner-icon='mdi-account-search-outline'
|
2018-05-12 20:13:04 +00:00
|
|
|
color='primary'
|
|
|
|
ref='searchIpt'
|
2018-08-05 15:27:46 +00:00
|
|
|
hide-details
|
2018-05-12 20:13:04 +00:00
|
|
|
)
|
2018-12-30 02:30:51 +00:00
|
|
|
v-list.grey.mt-3.py-0.radius-7(
|
2019-08-10 16:18:14 +00:00
|
|
|
:class='$vuetify.theme.dark ? `darken-3-d5` : `lighten-3`'
|
2018-12-30 02:30:51 +00:00
|
|
|
two-line
|
|
|
|
dense
|
|
|
|
)
|
2018-05-12 20:13:04 +00:00
|
|
|
template(v-for='(usr, idx) in items')
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item(:key='usr.id', @click='setUser(usr.id)')
|
|
|
|
v-list-item-avatar(size='40', color='primary')
|
2018-05-12 20:13:04 +00:00
|
|
|
span.body-1.white--text {{usr.name | initials}}
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-content
|
|
|
|
v-list-item-title.body-2 {{usr.name}}
|
2019-08-11 02:14:53 +00:00
|
|
|
v-list-item-subtitle {{usr.email}}
|
2019-07-29 04:50:03 +00:00
|
|
|
v-list-item-action
|
2019-08-11 02:14:53 +00:00
|
|
|
v-icon(color='primary') mdi-arrow-right
|
2018-05-12 20:13:04 +00:00
|
|
|
v-divider.my-0(v-if='idx < items.length - 1')
|
2018-06-11 03:23:09 +00:00
|
|
|
v-card-chin
|
2018-04-23 04:27:30 +00:00
|
|
|
v-spacer
|
2018-05-12 20:13:04 +00:00
|
|
|
v-btn(
|
2019-08-11 02:14:53 +00:00
|
|
|
text
|
2018-05-12 20:13:04 +00:00
|
|
|
@click='close'
|
|
|
|
:disabled='loading'
|
2019-06-15 21:05:56 +00:00
|
|
|
) {{$t('common:actions.cancel')}}
|
2018-04-23 04:27:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-05-12 20:13:04 +00:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
2018-06-25 06:44:40 +00:00
|
|
|
import searchUsersQuery from 'gql/common/common-users-query-search.gql'
|
2018-04-23 04:27:30 +00:00
|
|
|
|
|
|
|
export default {
|
2018-05-12 20:13:04 +00:00
|
|
|
filters: {
|
|
|
|
initials(val) {
|
2019-08-25 02:19:35 +00:00
|
|
|
return val.split(' ').map(v => v.substring(0, 1)).join('')
|
2018-05-12 20:13:04 +00:00
|
|
|
}
|
|
|
|
},
|
2018-04-23 04:27:30 +00:00
|
|
|
props: {
|
2018-05-12 20:13:04 +00:00
|
|
|
multiple: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2018-04-23 04:27:30 +00:00
|
|
|
value: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: false,
|
|
|
|
searchLoading: false,
|
|
|
|
search: '',
|
2018-05-12 20:13:04 +00:00
|
|
|
items: []
|
2018-04-23 04:27:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
dialogOpen: {
|
|
|
|
get() { return this.value },
|
|
|
|
set(value) { this.$emit('input', value) }
|
|
|
|
}
|
|
|
|
},
|
2018-05-12 20:13:04 +00:00
|
|
|
watch: {
|
|
|
|
value(newValue, oldValue) {
|
|
|
|
if (newValue && !oldValue) {
|
|
|
|
this.search = ''
|
|
|
|
this.selectedItems = null
|
|
|
|
_.delay(() => { this.$refs.searchIpt.focus() }, 100)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-04-23 04:27:30 +00:00
|
|
|
methods: {
|
|
|
|
close() {
|
|
|
|
this.$emit('input', false)
|
|
|
|
},
|
2018-05-12 20:13:04 +00:00
|
|
|
setUser(id) {
|
|
|
|
this.$emit('select', id)
|
|
|
|
this.close()
|
|
|
|
},
|
|
|
|
searchFilter(item, queryText, itemText) {
|
|
|
|
return _.includes(_.toLower(item.email), _.toLower(queryText)) || _.includes(_.toLower(item.name), _.toLower(queryText))
|
2018-04-23 04:27:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
items: {
|
|
|
|
query: searchUsersQuery,
|
|
|
|
variables() {
|
|
|
|
return {
|
2018-05-12 20:13:04 +00:00
|
|
|
query: this.search
|
2018-04-23 04:27:30 +00:00
|
|
|
}
|
|
|
|
},
|
2019-06-04 15:17:08 +00:00
|
|
|
fetchPolicy: 'cache-and-network',
|
2018-04-23 04:27:30 +00:00
|
|
|
skip() {
|
|
|
|
return !this.search || this.search.length < 2
|
|
|
|
},
|
2018-05-12 20:13:04 +00:00
|
|
|
update: (data) => data.users.search,
|
2018-04-23 04:27:30 +00:00
|
|
|
watchLoading (isLoading) {
|
|
|
|
this.searchLoading = isLoading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|