-
Notifications
You must be signed in to change notification settings - Fork 25
/
geographicArea.vue
83 lines (79 loc) · 1.98 KB
/
geographicArea.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<div>
<fieldset>
<legend>Geographic area</legend>
<switch-component
:options="Object.keys(smartGeographics)"
v-model="view"
:add-option="['search']"
name="switch-geographic"/>
<template v-if="smartGeographics[view]">
<tag-item
v-for="item in smartGeographics[view]"
:item="item"
display="name"
@select="sendGeographic"
:key="item.id"/>
</template>
<autocomplete
v-else
url="/geographic_areas/autocomplete"
label="label_html"
min="2"
:clear-after="true"
:autofocus="true"
@getItem="sendGeographic"
placeholder="Select a geographic area"
param="term"/>
</fieldset>
</div>
</template>
<script>
import TagItem from '../shared/item_tag.vue'
import SwitchComponent from '../shared/switch.vue'
import Autocomplete from 'components/autocomplete.vue'
import CRUD from '../../request/crud'
export default {
mixins: [CRUD],
components: {
TagItem,
SwitchComponent,
Autocomplete
},
props: {
createdList: {
type: Array,
required: true
}
},
data() {
return {
view: undefined,
smartGeographics: [],
selected: undefined
}
},
mounted() {
this.getList(`/geographic_areas/select_options?target=AssertedDistribution`).then(response => {
let result = response.body
Object.keys(result).forEach(key => (!result[key].length) && delete result[key])
this.smartGeographics = result
this.view = this.firstTabWithData(result);
})
},
methods: {
sendGeographic(item) {
this.selected = ''
this.$emit('select', item.id)
},
firstTabWithData(smartObject) {
if(Object.keys(smartObject).length) {
return Object.keys(smartObject)[0]
}
else {
return 'search'
}
}
}
}
</script>