akaunting/resources/assets/js/components/AkauntingSearch.vue

176 lines
4.6 KiB
Vue
Raw Normal View History

2019-11-16 10:21:14 +03:00
<template>
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
<el-select
:class="'pl-20 mr-40'"
v-model="real_model"
@input="change"
filterable
remote
reserve-keyword
:placeholder="placeholder"
:remote-method="remoteMethod"
:loading="loading">
<div v-if="loading" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty loading">
{{ loadingText }}
</p>
</div>
<div v-else-if="options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
</div>
<div v-else-if="options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
</div>
<template v-if="icon" slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="option in selectOptions"
:key="option.id"
:label="option.name"
:value="option.id">
</el-option>
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
2020-01-20 18:16:56 +03:00
:key="value"
:label="label"
:value="value">
</el-option>
2020-02-02 21:08:00 +03:00
</el-option-group>
</el-select>
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
</template>
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
<style>
.el-select {
display: inline;
}
</style>
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
<script>
import { Select, Option, OptionGroup } from 'element-ui';
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
export default {
name: 'akaunting-select',
2019-11-16 10:21:14 +03:00
2020-02-02 21:08:00 +03:00
components: {
[Select.name]: Select,
[Option.name]: Option,
[OptionGroup.name]: OptionGroup,
2019-11-16 10:21:14 +03:00
},
2020-02-02 21:08:00 +03:00
props: {
name: {
type: String,
default: null,
description: "Selectbox attribute name"
},
placeholder: {
type: String,
default: '',
description: "Selectbox input placeholder text"
},
options: null,
value: {
type: String,
default: null,
description: "Selectbox selected value"
},
icon: {
type: String,
description: "Prepend icon (left)"
},
group: {
type: Boolean,
default: false,
description: "Selectbox option group status"
},
loadingText: {
type: String,
default: 'Loading...',
description: "Selectbox loading message"
},
noDataText: {
type: String,
default: 'No Data',
description: "Selectbox empty options message"
},
noMatchingDataText: {
type: String,
default: 'No Matchign Data',
description: "Selectbox search option not found item message"
},
remoteAction: {
type: String,
default: null,
description: "Selectbox remote action path"
},
remoteType: {
type: String,
default: 'invoice',
description: "Ger remote item type."
},
2019-11-16 10:21:14 +03:00
},
2020-02-02 21:08:00 +03:00
data() {
return {
list: [],
selectOptions: this.options,
real_model: this.model,
loading: false,
}
2019-11-16 10:21:14 +03:00
},
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
mounted() {
this.real_model = this.value;
this.$emit('interface', this.real_model);
2019-11-16 10:21:14 +03:00
},
2020-02-02 21:08:00 +03:00
methods: {
change() {
this.$emit('change', this.real_model);
this.$emit('interface', this.real_model);
this.selectOptions.forEach(item => {
if (item.id == this.real_model) {
this.$emit('label', item.name);
this.$emit('option', item);
return;
}
});
2019-11-16 10:21:14 +03:00
},
2020-02-02 21:08:00 +03:00
remoteMethod() {
2019-11-16 10:21:14 +03:00
2020-02-02 21:08:00 +03:00
},
},
2019-11-16 10:21:14 +03:00
2020-02-02 21:08:00 +03:00
watch: {
options: function (options) {
// update options
//this.selectOptions = options;
2019-11-16 10:21:14 +03:00
}
2020-02-02 21:08:00 +03:00
},
2019-11-16 10:21:14 +03:00
}
</script>