Files
mixtape/zero.Backoffice.UI/app/modules/countries/ui-countrypicker.vue
T

75 lines
1.5 KiB
Vue
Raw Normal View History

2021-12-07 15:59:29 +01:00
<template>
<div class="ui-countrypicker" :class="{'is-disabled': disabled }">
2022-01-03 01:20:29 +01:00
<ui-pick :config="pickerConfig" :value="value" @input="onChange" :disabled="disabled" />
2021-12-07 15:59:29 +01:00
</div>
</template>
<script>
import api from './api';
2022-01-03 01:20:29 +01:00
import { extendObject } from '../../utils';
2021-12-07 15:59:29 +01:00
export default {
name: 'uiCountrypicker',
props: {
2022-01-03 01:20:29 +01:00
value: {
2021-12-07 15:59:29 +01:00
type: [String, Array],
default: null
},
limit: {
type: Number,
default: 1
},
disabled: {
type: Boolean,
default: false
},
options: {
type: Object,
default: () => {}
}
},
data: () => ({
previews: [],
pickerConfig: {}
}),
2022-01-03 01:20:29 +01:00
created()
{
const mapItem = item => ({
id: item.id,
name: item.name,
icon: 'flag-' + item.code.toLowerCase()
});
this.pickerConfig = extendObject({
scope: 'country',
items: async search =>
{
const res = await api.getByQuery({ search });
return Promise.resolve(res.data.map(mapItem));
},
previews: async ids =>
{
const res = await api.getByQuery({ ids });
return Promise.resolve(res.data.map(mapItem));
},
limit: this.limit,
multiple: this.limit > 1,
preview: {
2021-12-07 15:59:29 +01:00
2022-01-03 01:20:29 +01:00
}
}, this.options);
},
2021-12-07 15:59:29 +01:00
2022-01-03 01:20:29 +01:00
methods: {
onChange(value)
{
this.$emit('input', value);
}
}
2021-12-07 15:59:29 +01:00
}
</script>