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

637 lines
21 KiB
Vue
Raw Normal View History

2019-11-16 10:21:14 +03:00
<template>
<base-input :label="title"
:name="name"
:class="formClasses"
:error="formError">
2019-12-20 20:12:43 +03:00
<el-select v-model="real_model" @input="change" disabled filterable v-if="disabled && !multiple && !collapse"
2019-11-16 10:21:14 +03:00
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
2019-11-16 10:21:14 +03:00
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
2020-01-03 14:04:00 +03:00
</li>
</ul>
2020-01-03 14:04:00 +03:00
</div>
2019-11-16 10:21:14 +03:00
<template 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="(label, value) in selectOptions"
:key="value"
:label="label"
:value="value">
</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"
:key="value"
:label="label"
:value="value">
</el-option>
</el-option-group>
2019-12-25 15:02:55 +03:00
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
2019-11-16 10:21:14 +03:00
</el-select>
2019-12-20 20:12:43 +03:00
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && !multiple"
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
2019-12-25 15:02:55 +03:00
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2019-12-25 15:02:55 +03:00
<template 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="(label, value) in selectOptions"
:key="value"
:label="label"
:value="value">
</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"
:key="value"
:label="label"
:value="value">
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
2019-12-25 15:02:55 +03:00
</el-select>
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && !collapse" multiple
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template 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="(label, value) in selectOptions"
:key="value"
:label="label"
:value="value">
</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"
:key="value"
:label="label"
:value="value">
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable disabled v-if="disabled && multiple && !collapse" multiple
2019-12-25 15:02:55 +03:00
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
2019-12-20 20:12:43 +03:00
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2019-12-20 20:12:43 +03:00
<template 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="(label, value) in selectOptions"
:key="value"
:label="label"
:value="value">
</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"
:key="value"
:label="label"
:value="value">
</el-option>
</el-option-group>
2019-12-25 15:02:55 +03:00
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
2019-12-20 20:12:43 +03:00
</el-select>
2019-11-16 10:21:14 +03:00
2019-12-25 15:02:55 +03:00
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && collapse" multiple collapse-tags
2019-11-16 10:21:14 +03:00
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
2019-11-16 10:21:14 +03:00
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2019-11-16 10:21:14 +03:00
<template 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="(label, value) in selectOptions"
:key="value"
:label="label"
:value="value">
</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"
:key="value"
:label="label"
:value="value">
</el-option>
</el-option-group>
2019-12-25 15:02:55 +03:00
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
2019-11-16 10:21:14 +03:00
</el-select>
2020-01-03 14:04:00 +03:00
<component v-bind:is="add_new_html" @submit="onSubmit"></component>
<select :name="name" class="d-none" v-model="real_model">
<option v-for="(label, value) in selectOptions" :value="value">{{ label }}</option>
</select>
2019-11-16 10:21:14 +03:00
</base-input>
</template>
<script>
import { Select, Option, OptionGroup, ColorPicker } from 'element-ui';
2019-11-16 10:21:14 +03:00
import AkauntingModalAddNew from './AkauntingModalAddNew';
2020-01-03 14:04:00 +03:00
import AkauntingModal from './AkauntingModal';
import AkauntingRadioGroup from './forms/AkauntingRadioGroup';
import AkauntingSelect from './AkauntingSelect';
import AkauntingDate from './AkauntingDate';
import AkauntingRecurring from './AkauntingRecurring';
import Form from './../plugins/form';
2019-11-16 10:21:14 +03:00
export default {
name: "akaunting-select",
components: {
[Select.name]: Select,
[Option.name]: Option,
[OptionGroup.name]: OptionGroup,
[ColorPicker.name]: ColorPicker,
AkauntingModalAddNew,
AkauntingRadioGroup,
AkauntingSelect,
AkauntingModal,
AkauntingDate,
AkauntingRecurring,
2019-11-16 10:21:14 +03:00
},
props: {
title: {
type: String,
default: '',
description: "Selectbox label text"
2019-11-16 10:21:14 +03:00
},
placeholder: {
type: String,
default: '',
description: "Selectbox input placeholder text"
2019-11-16 10:21:14 +03:00
},
formClasses: {
2020-01-18 16:36:36 +03:00
type: Array,
default: null,
description: "Selectbox input class name"
},
formError: {
type: String,
default: null,
description: "Selectbox input error message"
},
name: {
type: String,
default: null,
description: "Selectbox attribute name"
},
value: {
type: String,
default: null,
description: "Selectbox selected value"
},
2020-01-18 16:36:36 +03:00
options: null,
2019-11-16 10:21:14 +03:00
model: null,
2019-11-16 10:21:14 +03:00
icon: {
type: String,
description: "Prepend icon (left)"
},
2020-01-03 14:04:00 +03:00
addNew: {
type: Object,
default: function () {
return {
text: 'Add New Item',
status: false,
path: null,
type: 'modal', // modal, inline
field: 'name',
buttons: {}
2020-01-03 14:04:00 +03:00
};
},
description: "Selectbox Add New Item Feature"
},
group: {
type: Boolean,
default: false,
description: "Selectbox option group status"
},
multiple: {
type: Boolean,
default: false,
description: "Multible feature status"
},
disabled: {
type: Boolean,
default: false,
description: "Selectbox disabled status"
},
collapse: {
type: Boolean,
default: false,
description: "Selectbox collapse status"
},
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"
}
2019-11-16 10:21:14 +03:00
},
data() {
return {
add_new: this.addNew,
2020-01-03 14:04:00 +03:00
add_new_text: this.addNew.text,
2019-11-16 10:21:14 +03:00
selectOptions: this.options,
real_model: this.model,
2020-01-03 14:04:00 +03:00
add_new_html: '',
form: {},
2019-11-16 10:21:14 +03:00
}
},
mounted() {
this.real_model = this.value;
this.$emit('interface', this.real_model);
},
methods: {
change() {
this.$emit('change', this.real_model);
this.$emit('interface', this.real_model);
},
onAddItem() {
// Get Select Input value
var value = this.$children[0].$children[0].$children[0].$refs.input.value;
if (this.add_new.type == 'inline') {
2020-01-03 14:04:00 +03:00
this.addInline(value);
} else {
this.onModal(value);
}
},
addInline(value) {
},
onModal(value) {
let add_new = this.add_new;
2020-01-03 14:04:00 +03:00
axios.get(this.add_new.path)
2020-01-03 14:04:00 +03:00
.then(response => {
add_new.status = true;
2020-01-03 14:04:00 +03:00
add_new.html = response.data.html;
this.$children[0].$children[0].visible = false;
2020-01-03 14:04:00 +03:00
this.add_new_html = Vue.component('add-new-component', function (resolve, reject) {
resolve({
template: '<div><akaunting-modal-add-new :show="add_new.status" @submit="onSubmit" @cancel="add_new.status = false" :buttons="add_new.buttons" :title="add_new.text" :is_component=true :message="add_new.html"></akaunting-modal-add-new></div>',
2020-01-03 14:04:00 +03:00
components: {
AkauntingModalAddNew,
2020-01-03 14:04:00 +03:00
AkauntingRadioGroup,
AkauntingSelect,
AkauntingModal,
AkauntingDate,
AkauntingRecurring,
[ColorPicker.name]: ColorPicker,
2020-01-03 14:04:00 +03:00
},
data: function () {
return {
add_new: add_new,
2020-01-03 14:04:00 +03:00
}
},
methods: {
onSubmit(event) {
this.$emit('submit', event);
2020-01-03 14:04:00 +03:00
}
}
})
});
})
.catch(e => {
this.errors.push(e);
})
.finally(function () {
// always executed
});
},
onSubmit(event) {
this.form = event;
2020-01-03 14:04:00 +03:00
axios.post(this.form.action, this.form.data())
2020-01-03 14:04:00 +03:00
.then(response => {
this.form.loading = false;
2020-01-03 14:04:00 +03:00
if (response.data.success) {
this.selectOptions[response.data.data.id] = response.data.data['name'];
this.real_model = response.data.data.id.toString();
this.change();
2020-01-23 10:55:42 +03:00
//this.add_new.status = false;
2020-01-03 14:04:00 +03:00
}
})
.catch(error => {
this.form.loading = false;
this.form.onFail(error);
2020-01-03 14:04:00 +03:00
this.method_show_html = error.message;
});
},
addModal() {
},
2019-11-16 10:21:14 +03:00
},
watch: {
options: function (options) {
// update options
//this.selectOptions = options;
2019-11-16 10:21:14 +03:00
}
},
}
</script>
<style scoped>
.form-group .modal {
z-index: 3050;
}
.el-select-dropdown__empty {
padding: 10px 0 0 !important;
}
.el-select__footer {
text-align: center;
border-top: 1px solid #dee2e6;
padding: 0px;
cursor: pointer;
color: #3c3f72;
font-weight: bold;
height: 38px;
line-height: 38px;
margin-top: 5px;
margin-bottom: -6px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}
.el-select__footer.el-select-dropdown__item.hover {
background-color: inherit !important;
}
.el-select__footer.el-select-dropdown__item:hover, .el-select__footer.el-select-dropdown__item:focus {
background-color: #3c3f72 !important;
color: white !important;
border-top-color: #3c3f72;
}
.el-select__footer div span {
margin-left: 5px;
}
</style>