2020-10-26 16:42:42 -07:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<draggable tag="ul" v-model="iVal" ghostClass="ghost" @end="$emit('input', iVal)" :group="ulid"
|
|
|
|
class="list-inline border rounded drop-empty px-3 py-2">
|
2021-02-08 12:07:29 -08:00
|
|
|
<li v-for="val in iVal" :key="val" v-if="options[val]" class="list-inline-item py-1">
|
2021-01-22 14:54:24 -08:00
|
|
|
<a href="#" class="badge bg-light text-dark border p-2" @click.prevent="$emit('input', iVal.filter(v => v !== val))">
|
2020-10-26 16:42:42 -07:00
|
|
|
<slot v-bind:v="val" v-bind:desc="options[val]">
|
|
|
|
{{ val }}
|
|
|
|
</slot>
|
2020-11-10 06:09:30 -08:00
|
|
|
<span class="text-danger">
|
2020-11-09 13:13:18 -08:00
|
|
|
<Icon v="times"/>
|
2020-11-10 06:09:30 -08:00
|
|
|
</span>
|
2020-10-26 16:42:42 -07:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</draggable>
|
2020-11-10 06:09:30 -08:00
|
|
|
<div class="input-group py-1">
|
|
|
|
<input v-model="search" class="form-control form-control-sm" :placeholder="$t('crud.search')"/>
|
2021-01-22 14:54:24 -08:00
|
|
|
<button v-if="search" type="button" class="btn btn-light btn-sm border text-danger" @click.prevent="search = ''">
|
|
|
|
<Icon v="times"/>
|
|
|
|
</button>
|
2020-11-10 06:09:30 -08:00
|
|
|
|
2021-01-22 14:54:24 -08:00
|
|
|
<button v-if="all" type="button" class="btn btn-light btn-sm border" @click.prevent="all = false">
|
|
|
|
<Icon v="caret-up"/>
|
|
|
|
</button>
|
|
|
|
<button v-else type="button" class="btn btn-light btn-sm border" @click.prevent="all = true">
|
|
|
|
<Icon v="caret-down"/>
|
|
|
|
</button>
|
2020-11-10 06:09:30 -08:00
|
|
|
</div>
|
2020-10-26 16:42:42 -07:00
|
|
|
|
|
|
|
<draggable tag="ul" v-model="remainingOptions" ghostClass="ghost" @end="$emit('input', iVal)" class="list-inline" :group="ulid">
|
2021-03-01 13:01:15 -08:00
|
|
|
<li v-for="val in remainingOptions" :key="val" v-if="(all && !search) || (search && options[val].toLowerCase().includes(search))" class="list-inline-item py-1">
|
2021-01-22 14:54:24 -08:00
|
|
|
<a href="#" class="badge bg-light text-dark p-2" @click.prevent="$emit('input', [...iVal, val])">
|
2020-10-26 16:42:42 -07:00
|
|
|
<slot v-bind:v="val" v-bind:desc="options[val]">
|
|
|
|
{{ val }}
|
|
|
|
</slot>
|
2020-11-10 06:09:30 -08:00
|
|
|
<span class="text-success">
|
|
|
|
<Icon v="plus"/>
|
|
|
|
</span>
|
2020-10-26 16:42:42 -07:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</draggable>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import draggable from 'vuedraggable';
|
|
|
|
import { ulid } from 'ulid';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
draggable,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {},
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
iVal: this.value,
|
|
|
|
remainingOptions: this.buildRemainingOptions(),
|
|
|
|
ulid: ulid(),
|
2020-11-09 13:13:18 -08:00
|
|
|
search: '',
|
|
|
|
all: false,
|
2020-10-26 16:42:42 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value() {
|
|
|
|
this.iVal = this.value;
|
|
|
|
this.remainingOptions = this.buildRemainingOptions();
|
2020-11-09 13:13:18 -08:00
|
|
|
this.search = '';
|
2020-10-26 16:42:42 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
buildRemainingOptions() {
|
|
|
|
return Object.keys(this.options).filter(o => !this.value.includes(o));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ghost {
|
|
|
|
opacity: 0.5;
|
|
|
|
background: #c8ebfb;
|
|
|
|
}
|
|
|
|
|
|
|
|
.drop-empty:empty {
|
|
|
|
min-height: 3em;
|
|
|
|
}
|
|
|
|
</style>
|