|
|
@@ -1,36 +1,30 @@
|
|
|
<template>
|
|
|
<main>
|
|
|
<v-autocomplete
|
|
|
- v-model="model"
|
|
|
- :value="data"
|
|
|
- :items="items"
|
|
|
- :loading="isLoading"
|
|
|
- :search-input.sync="search"
|
|
|
- hide-no-data
|
|
|
- hide-selected
|
|
|
+ @change="$emit('update', $event, field)"
|
|
|
+ :items="itemsToDisplayed"
|
|
|
+ :label="$t(label)"
|
|
|
item-text="textDisplay"
|
|
|
:item-value="itemValue"
|
|
|
- :label="$t(label_field)"
|
|
|
- :placeholder="$t('start_your_research')"
|
|
|
- prepend-icon="mdi-magnify"
|
|
|
+ :multiple="multiple"
|
|
|
+ :loading="isLoading"
|
|
|
:return-object="returnObject"
|
|
|
- ></v-autocomplete>
|
|
|
-
|
|
|
+ >
|
|
|
+ </v-autocomplete>
|
|
|
</main>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
- import {defineComponent, computed, watch, ref, useContext, onUnmounted, Ref} from '@nuxtjs/composition-api'
|
|
|
- import {QUERY_TYPE} from "~/types/enums";
|
|
|
- import * as _ from "lodash";
|
|
|
+ import {computed, defineComponent, ComputedRef} from '@nuxtjs/composition-api'
|
|
|
+ import {AnyJson} from "~/types/interfaces";
|
|
|
|
|
|
export default defineComponent({
|
|
|
props: {
|
|
|
- label:{
|
|
|
+ label: {
|
|
|
type: String,
|
|
|
required: false
|
|
|
},
|
|
|
- field:{
|
|
|
+ field: {
|
|
|
type: String,
|
|
|
required: false
|
|
|
},
|
|
|
@@ -38,69 +32,51 @@
|
|
|
type: String,
|
|
|
required: false
|
|
|
},
|
|
|
+ items: {
|
|
|
+ type: Array,
|
|
|
+ required: false,
|
|
|
+ default: []
|
|
|
+ },
|
|
|
readOnly: {
|
|
|
type: Boolean,
|
|
|
required: false
|
|
|
},
|
|
|
- itemValue:{
|
|
|
+ itemValue: {
|
|
|
type: String,
|
|
|
default: 'id'
|
|
|
},
|
|
|
- itemText:{
|
|
|
+ itemText: {
|
|
|
type: Array,
|
|
|
required: true
|
|
|
},
|
|
|
- returnObject:{
|
|
|
+ returnObject: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ multiple: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ isLoading: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
}
|
|
|
},
|
|
|
- setup(props){
|
|
|
- const {$dataProvider} = useContext();
|
|
|
-
|
|
|
- const search:Ref<string|null> = ref(null);
|
|
|
- const model = ref(null);
|
|
|
- const count = ref(0);
|
|
|
- const entries = ref([]);
|
|
|
- const isLoading = ref(false);
|
|
|
-
|
|
|
- const items = computed(() => {
|
|
|
- return entries.value.map(entry => {
|
|
|
- const textDisplay:Array<string> = []
|
|
|
- for (const text of props.itemText){
|
|
|
- textDisplay.push(entry[text as string])
|
|
|
+ setup(props) {
|
|
|
+ //On reconstruit les items à afficher car le text de l'Item doit être construit par rapport au itemText passé en props
|
|
|
+ const itemsToDisplayed: ComputedRef<Array<AnyJson>> = computed(() => {
|
|
|
+ return props.items.map((item: any) => {
|
|
|
+ const textDisplay: Array<string> = []
|
|
|
+ for (const text of props.itemText) {
|
|
|
+ textDisplay.push(item[text as string])
|
|
|
}
|
|
|
- return Object.assign({}, entry, { textDisplay: textDisplay.join(' ') })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- const unwatch = watch(search, _.debounce(async (research) => {
|
|
|
- // Items have already been requested
|
|
|
- if (isLoading.value) return
|
|
|
-
|
|
|
- isLoading.value = true
|
|
|
-
|
|
|
- let response = await $dataProvider.invoke({
|
|
|
- type: QUERY_TYPE.DEFAULT,
|
|
|
- url: `gps-coordinate-searching?city=${research}`
|
|
|
+ return Object.assign({}, item, {textDisplay: textDisplay.join(' ')})
|
|
|
})
|
|
|
-
|
|
|
- count.value = response.length
|
|
|
- entries.value = response
|
|
|
- isLoading.value = false
|
|
|
- }, 500))
|
|
|
-
|
|
|
- onUnmounted(()=>{
|
|
|
- unwatch()
|
|
|
})
|
|
|
|
|
|
return {
|
|
|
- label_field : props.label ?? props.field,
|
|
|
- count,
|
|
|
- isLoading,
|
|
|
- items,
|
|
|
- search,
|
|
|
- model
|
|
|
+ label_field: props.label ?? props.field,
|
|
|
+ itemsToDisplayed
|
|
|
}
|
|
|
|
|
|
}
|