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

888 lines
28 KiB
Vue
Raw Normal View History

2019-11-16 10:21:14 +03:00
<template>
2021-06-30 18:22:43 +03:00
<div :id="'search-field-' + _uid" class="searh-field tags-input__wrapper js-search">
2021-01-22 23:16:44 +03:00
<div class="tags-group" v-for="(filter, index) in filtered" :index="index">
<span v-if="filter.option" class="el-tag el-tag--primary el-tag--small el-tag--light el-tag-option">
{{ filter.option }}
<i v-if="!filter.operator && !filter.value" class="el-tag__close el-icon-close" @click="onFilterDelete(index)"></i>
</span>
<span v-if="filter.operator" class="el-tag el-tag--primary el-tag--small el-tag--light el-tag-operator">
2021-01-26 12:21:29 +03:00
<i v-if="filter.operator == '='" class="fas fa-equals"></i>
<i v-else-if="filter.operator == '><'" class="fas fa-arrows-alt-h"></i>
2021-01-26 12:21:29 +03:00
<i v-else class="fas fa-not-equal"></i>
2021-01-22 23:16:44 +03:00
<i v-if="!filter.value" class="el-tag__close el-icon-close" @click="onFilterDelete(index)"></i>
</span>
<span v-if="filter.value" class="el-tag el-tag--primary el-tag--small el-tag--light el-tag-value">
{{ filter.value }}
<i class="el-tag__close el-icon-close" @click="onFilterDelete(index)"></i>
</span>
</div>
<div class="dropdown input-full">
<input
v-if="!show_date"
type="text"
class="form-control"
:placeholder="placeholder"
:ref="'input-search-field-' + _uid"
v-model="search"
@focus="onInputFocus"
@input="onInput"
@keyup.enter="onInputConfirm"
/>
<flat-picker
v-else
@on-open="onInputFocus"
:config="dateConfig"
class="form-control datepicker"
:placeholder="placeholder"
:ref="'input-search-date-field-' + _uid"
value=""
2021-01-22 23:16:44 +03:00
@focus="onInputFocus"
@on-close="onInputDateSelected"
2021-01-22 23:16:44 +03:00
@keyup.enter="onInputConfirm"
>
</flat-picker>
<button type="button" class="btn btn-link clear" @click="onSearchAndFilterClear">
<i class="el-tag__close el-icon-close"></i>
</button>
<div :id="'search-field-option-' + _uid" class="dropdown-menu" :class="[{'show': visible.options}]">
<li ref="" class="dropdown-item" v-for="option in filteredOptions" :data-value="option.key">
<button type="button" class="btn btn-link" @click="onOptionSelected(option.key)">{{ option.value }}</button>
</li>
<li ref="" v-if="search" class="dropdown-item">
<button type="button" class="btn btn-link" @click="onInputConfirm">{{ searchText }}</button>
</li>
</div>
2021-01-26 12:21:29 +03:00
<div :id="'search-field-operator-' + _uid" class="dropdown-menu operator" :class="[{'show': visible.operator}]">
2021-01-22 23:16:44 +03:00
<li ref="" class="dropdown-item">
2021-01-26 12:21:29 +03:00
<button type="button" class="btn btn-link" @click="onOperatorSelected('=')"><i class="fas fa-equals"></i><span class="btn-helptext d-none">{{ operatorIsText }}</span></button>
2021-01-22 23:16:44 +03:00
</li>
<li ref="" class="dropdown-item">
2021-01-26 12:21:29 +03:00
<button type="button" class="btn btn-link" @click="onOperatorSelected('!=')"><i class="fas fa-not-equal"></i><span class="btn-helptext d-none">{{ operatorIsNotText }}</span></button>
2021-01-22 23:16:44 +03:00
</li>
<li v-if="range" ref="" class="dropdown-item">
<button type="button" class="btn btn-link" @click="onOperatorSelected('><')"><i class="fas fa-arrows-alt-h"></i><span class="btn-helptext d-none">{{ operatorIsNotText }}</span></button>
</li>
2021-01-22 23:16:44 +03:00
</div>
<div :id="'search-field-value-' + _uid" class="dropdown-menu" :class="[{'show': visible.values}]">
<li ref="" class="dropdown-item" v-for="(value) in filteredValues" :data-value="value.key">
<button type="button" class="btn btn-link" @click="onValueSelected(value.key)">{{ value.value }}</button>
</li>
<li ref="" class="dropdown-item" v-if="!filteredValues.length">
<button type="button" class="btn btn-link">{{ noMatchingDataText }}</button>
</li>
</div>
</div>
2020-11-06 01:48:49 +03:00
</div>
</template>
2020-01-20 18:16:56 +03:00
2020-02-02 21:08:00 +03:00
<script>
2020-11-11 14:33:49 +03:00
import flatPicker from "vue-flatpickr-component";
import "flatpickr/dist/flatpickr.css";
2020-11-06 01:48:49 +03:00
export default {
2021-01-22 23:16:44 +03:00
name: 'akaunting-search',
2020-01-20 18:16:56 +03:00
2021-01-22 23:16:44 +03:00
components: {
flatPicker
2020-11-06 22:34:53 +03:00
},
2021-01-22 23:16:44 +03:00
props: {
placeholder: {
type: String,
default: 'Search or filter results...',
description: 'Input placeholder'
},
searchText: {
type: String,
default: 'Search for this text',
description: 'Input placeholder'
},
operatorIsText: {
type: String,
default: 'is',
description: 'Operator is "="'
},
operatorIsNotText: {
type: String,
default: 'is not',
description: 'Operator is not "!="'
},
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"
},
value: {
type: String,
default: null,
description: 'Search attribute value'
},
filters: {
type: Array,
default: () => [],
description: 'List of filters'
},
2021-06-01 14:43:27 +03:00
defaultFiltered: {
type: Array,
default: () => [],
description: 'List of filters'
},
2021-01-22 23:16:44 +03:00
2021-06-29 18:13:49 +03:00
dateConfig: null
2020-11-06 01:48:49 +03:00
},
2021-01-22 23:16:44 +03:00
model: {
prop: 'value',
event: 'change'
2020-11-06 01:48:49 +03:00
},
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
data() {
return {
filter_list: this.filters, // set filters prop assing it.
search: '', // search cloumn model
filtered:[], // Show selected filters
filter_index: 0, // added filter count
filter_last_step: 'options', // last fitler step
visible: { // Which visible dropdown
options: false,
operator: false,
values: false,
},
range: false,
2021-01-22 23:16:44 +03:00
option_values: [],
selected_options: [],
selected_operator: [],
selected_values: [],
values: [],
current_value: null,
show_date: false,
};
2020-11-11 14:33:49 +03:00
},
2021-01-22 23:16:44 +03:00
methods: {
onInputFocus() {
if (!this.filter_list.length) {
return;
}
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
if (this.filter_last_step != 'values' || (this.filter_last_step == 'values' && this.selected_options[this.filter_index].type != 'date')) {
this.visible[this.filter_last_step] = true;
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
} else {
this.show_date = true;
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
this.$nextTick(() => {
this.$refs['input-search-date-field-' + this._uid].fp.open();
});
}
2020-02-02 21:08:00 +03:00
2021-06-01 14:43:27 +03:00
//console.log('Focus :' + this.filter_last_step);
2021-01-22 23:16:44 +03:00
},
2020-11-09 20:30:05 +03:00
onInputDateSelected(selectedDates, dateStr, instance) {
this.filtered[this.filter_index].value = dateStr;
let date = instance.formatDate(selectedDates[0], 'Y-m-d');
if (selectedDates.length > 1) {
let dates = [];
2021-01-22 23:16:44 +03:00
selectedDates.forEach(function (item) {
dates.push(instance.formatDate(item, 'Y-m-d'));
}, this);
date = dates.join('-to-');
}
2021-01-22 23:16:44 +03:00
this.selected_values.push({
key: date,
value: dateStr,
2021-01-22 23:16:44 +03:00
});
this.$emit('change', this.filtered);
this.show_date = false;
this.search = '';
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
this.filter_index++;
if (this.filter_list.length) {
this.visible = {
options: true,
operator: false,
values: false,
};
} else {
this.visible = {
options: false,
operator: false,
values: false,
};
}
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
this.filter_last_step = 'options';
},
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
onInput(evt) {
this.search = evt.target.value;
2019-11-16 10:21:14 +03:00
2021-01-22 23:16:44 +03:00
let option_url = this.selected_options[this.filter_index].url;
2021-01-22 23:16:44 +03:00
if (this.search) {
2021-02-23 19:25:51 +03:00
if (option_url.indexOf('?') === -1) {
option_url += '?search="' + this.search + '" limit:10';
} else {
if (option_url.indexOf('search=') === -1) {
option_url += '&search="' + this.search + '" limit:10';
} else {
option_url += ' "' + this.search + '" limit:10';
}
}
2021-01-22 23:16:44 +03:00
}
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
if (option_url) {
2021-02-23 19:46:53 +03:00
if (option_url.indexOf('limit') === -1) {
option_url += ' limit:10';
}
2021-01-22 23:16:44 +03:00
window.axios.get(option_url)
.then(response => {
this.values = [];
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
let data = response.data.data;
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
data.forEach(function (item) {
this.values.push({
key: item.id,
value: item.name
});
}, this);
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
this.option_values[value] = this.values;
})
.catch(error => {
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
});
}
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
this.$emit('input', evt.target.value);
},
2020-02-02 21:08:00 +03:00
2021-01-22 23:16:44 +03:00
onInputConfirm() {
let path = window.location.href.replace(window.location.search, '');
let args = '';
2020-02-02 21:08:00 +03:00
2021-01-22 23:16:44 +03:00
if (this.search) {
args += '?search="' + this.search + '" ';
}
2019-11-16 10:21:14 +03:00
2021-01-22 23:16:44 +03:00
let now = new Date();
now.setTime(now.getTime() + 1 * 3600 * 1000);
let expires = now.toUTCString();
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
let search_string = {};
search_string[path] = {};
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
this.filtered.forEach(function (filter, index) {
if (!args) {
args += '?search=';
}
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
if (this.selected_operator[index].key == '!=') {
args += 'not ';
}
2020-11-06 01:48:49 +03:00
if (this.selected_operator[index].key == '><') {
let dates = this.selected_values[index].key.split('-to-');
args += this.selected_options[index].key + '>=' + dates[0] + ' ';
args += this.selected_options[index].key + '<=' + dates[1] + ' ';
} else {
args += this.selected_options[index].key + ':' + this.selected_values[index].key + ' ';
}
2021-01-22 23:16:44 +03:00
search_string[path][this.selected_options[index].key] = {
'key': this.selected_values[index].key,
'value': this.selected_values[index].value,
'operator': this.selected_operator[index].key,
};
}, this);
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
Cookies.set('search-string', search_string, expires);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
window.location = path + args;
},
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
onOptionSelected(value) {
this.current_value = value;
this.range = false;
2021-01-22 23:16:44 +03:00
let option = false;
let option_url = false;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
for (let i = 0; i < this.filter_list.length; i++) {
if (this.filter_list[i].key == value) {
option = this.filter_list[i].value;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (this.filter_list[i].values !== 'undefined' && Object.keys(this.filter_list[i].values).length) {
this.option_values[value] = this.convertOption(this.filter_list[i].values);
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (typeof this.filter_list[i].url !== 'undefined' && this.filter_list[i].url) {
option_url = this.filter_list[i].url;
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (typeof this.filter_list[i].type !== 'undefined' && this.filter_list[i].type == 'boolean') {
this.option_values[value] = this.filter_list[i].values;
}
2021-01-13 15:25:26 +03:00
if (typeof this.filter_list[i].type !== 'undefined' && this.filter_list[i].type == 'date') {
this.range = true;
}
2021-01-22 23:16:44 +03:00
this.selected_options.push(this.filter_list[i]);
this.filter_list.splice(i, 1);
break;
}
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
// Set filtered select option
this.filtered.push({
option: option,
operator: false,
value: false
});
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
this.$emit('change', this.filtered);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.search = '';
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (option_url) {
if (option_url.indexOf('?') === -1) {
option_url += '?search=limit:10';
} else {
option_url += ' limit:10';
}
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (!this.option_values[value] && option_url) {
2021-02-23 19:46:53 +03:00
if (option_url.indexOf('limit') === -1) {
option_url += ' limit:10';
}
2021-01-22 23:16:44 +03:00
window.axios.get(option_url)
.then(response => {
let data = response.data.data;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.values = [];
2021-01-22 23:16:44 +03:00
data.forEach(function (item) {
this.values.push({
key: (item.code) ? item.code : item.id,
value: (item.title) ? item.title : (item.display_name) ? item.display_name : item.name
});
}, this);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.option_values[value] = this.values;
})
.catch(error => {
2021-01-22 23:16:44 +03:00
});
} else {
this.values = (this.option_values[value]) ? this.option_values[value] : [];
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.visible = {
options: false,
operator: true,
values: false,
};
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.filter_last_step = 'operator';
},
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
onOperatorSelected(value) {
this.filtered[this.filter_index].operator = value;
this.$emit('change', this.filtered);
if (this.selected_options[this.filter_index].type != 'date') {
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
this.visible = {
options: false,
operator: false,
values: true,
};
} else {
this.show_date = true;
this.$nextTick(() => {
let mode = this.selected_operator[this.filter_index].key == '><' ? 'range' : 'single';
this.$refs['input-search-date-field-' + this._uid].fp.set('mode', mode);
2021-01-22 23:16:44 +03:00
this.$refs['input-search-date-field-' + this._uid].fp.open();
});
this.visible = {
options: false,
operator: false,
values: false,
};
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.selected_operator.push({
key: value
});
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.filter_last_step = 'values';
},
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
onValueSelected(value) {
let select_value = false;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
for (let i = 0; i < this.values.length; i++) {
if (this.values[i].key == value) {
select_value = this.values[i].value;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.selected_values.push(this.values[i]);
this.option_values[this.current_value].splice(i, 1);
break;
}
}
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
this.filtered[this.filter_index].value = select_value;
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
this.$emit('change', this.filtered);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
2021-01-22 23:16:44 +03:00
this.filter_index++;
2021-01-22 23:16:44 +03:00
if (this.filter_list.length) {
this.visible = {
options: true,
operator: false,
values: false,
};
} else {
this.visible = {
options: false,
operator: false,
values: false,
};
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.show_date = false;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.filter_last_step = 'options';
this.search = '';
},
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
onFilterDelete(index) {
this.filter_list.push(this.selected_options[index]);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (this.filter_last_step == 'options') {
this.filter_index--;
}
2019-11-16 10:21:14 +03:00
2021-01-22 23:16:44 +03:00
this.filtered.splice(index, 1);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.selected_options.splice(index, 1);
this.selected_operator.splice(index, 1);
this.selected_values.splice(index, 1);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.show_date = false;
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.filter_last_step = 'options';
},
2020-11-11 14:33:49 +03:00
2021-01-22 23:16:44 +03:00
onSearchAndFilterClear() {
this.filtered = [];
this.search = '';
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
Cookies.remove('search-string');
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.onInputConfirm();
},
2020-11-06 01:48:49 +03:00
2021-06-01 14:43:27 +03:00
convertOption(options) {
2021-01-22 23:16:44 +03:00
let values = [];
2021-01-22 23:16:44 +03:00
// Option set sort_option data
if (!Array.isArray(options)) {
for (const [key, value] of Object.entries(options)) {
values.push({
key: (key).toString(),
value: (value).toString()
});
}
} else {
options.forEach(function (option, index) {
values.push({
key: (option.key).toString(),
value: (option.value).toString()
});
}, this);
}
2021-01-22 23:16:44 +03:00
return values;
},
2021-01-12 01:30:14 +03:00
2021-01-22 23:16:44 +03:00
closeIfClickedOutside(event) {
if (!document.getElementById('search-field-' + this._uid).contains(event.target) && event.target.className != 'btn btn-link') {
this.visible.options = false;
this.visible.operator = false;
this.visible.values = false;
document.removeEventListener('click', this.closeIfClickedOutside);
}
},
2020-11-06 01:48:49 +03:00
},
2021-01-22 23:16:44 +03:00
created() {
let path = window.location.href.replace(window.location.search, '');
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
let cookie = Cookies.get('search-string');
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
if (cookie != undefined) {
cookie = JSON.parse(cookie)[path];
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (this.value) {
this.value = this.value.replace(/\s+[a-zA-Z\w]+[<=]+/g, '-to-');
this.value = this.value.replace('>=', ':');
2021-01-22 23:16:44 +03:00
let search_string = this.value.replace('not ', '').replace(' not ', ' ');
2021-01-13 15:25:26 +03:00
2021-01-22 23:16:44 +03:00
console.log(search_string);
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
search_string = search_string.split(' ');
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
search_string.forEach(function (string) {
if (string.search(':') === -1) {
this.search = string.replace(/[\"]+/g, '');
2021-01-22 23:16:44 +03:00
} else {
let filter = string.split(':');
let option = '';
let operator = '=';
let value = '';
let value_assigned = false;
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
this.filter_list.forEach(function (_filter, i) {
let filter_values = this.convertOption(_filter.values);
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
if (_filter.key == filter[0]) {
option = _filter.value;
operator = _filter.operator;
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
filter_values.forEach(function (_value) {
if (_value.key == filter[1]) {
value = _value.value;
}
}, this);
2021-01-22 23:16:44 +03:00
if (!value && (cookie != undefined && cookie[_filter.key])) {
value = cookie[_filter.key].value;
}
2021-01-22 23:16:44 +03:00
if (cookie != undefined && cookie[_filter.key]) {
operator = cookie[_filter.key].operator;
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
this.selected_options.push(this.filter_list[i]);
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
this.selected_operator.push({
key: operator,
});
2021-01-13 15:25:26 +03:00
2021-01-22 23:16:44 +03:00
this.filter_list.splice(i, 1);
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
this.option_values[_filter.key] = filter_values;
2020-11-06 22:34:53 +03:00
filter_values.forEach(function (value, j) {
if (value.key == filter[1]) {
this.selected_values.push(value);
this.option_values[_filter.key].splice(j, 1);
value_assigned = true
2021-01-22 23:16:44 +03:00
}
}, this);
if (!value_assigned && (cookie != undefined && cookie[_filter.key])) {
this.selected_values.push(cookie[_filter.key]);
2021-01-22 23:16:44 +03:00
}
}
}, this);
2021-01-22 23:16:44 +03:00
this.filtered.push({
option: option,
operator: operator,
value: value
});
2021-01-22 23:16:44 +03:00
this.filter_index++;
}
}, this);
2021-06-01 14:47:10 +03:00
} else if (this.defaultFiltered) {
2021-06-01 14:43:27 +03:00
this.defaultFiltered.forEach(function (filter) {
let option = '';
let operator = '=';
let value = '';
this.filter_list.forEach(function (_filter, i) {
let filter_values = this.convertOption(_filter.values);
if (_filter.key == filter.option) {
console.log('Filter YES');
option = _filter.value;
operator = filter.operator;
filter_values.forEach(function (_value) {
if (_value.key == filter.value) {
value = _value.value;
}
}, this);
this.selected_options.push(this.filter_list[i]);
console.log(operator);
this.selected_operator.push({
key: operator,
});
this.filter_list.splice(i, 1);
this.option_values[_filter.key] = filter_values;
filter_values.forEach(function (value, j) {
if (value.key == filter.value) {
this.selected_values.push(value);
this.option_values[_filter.key].splice(j, 1);
}
}, this);
}
}, this);
this.filtered.push({
option: option,
operator: operator,
value: value
});
this.filter_index++;
}, this);
2021-01-22 23:16:44 +03:00
}
},
2020-11-06 22:34:53 +03:00
2021-06-29 18:13:49 +03:00
mounted() {
},
2021-01-22 23:16:44 +03:00
computed: {
filteredOptions() {
this.filter_list.sort(function (a, b) {
var nameA = a.value.toUpperCase(); // ignore upper and lowercase
var nameB = b.value.toUpperCase(); // ignore upper and lowercase
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
if (nameA < nameB) {
return -1;
}
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
if (nameA > nameB) {
return 1;
2020-11-06 22:34:53 +03:00
}
2020-11-09 20:30:05 +03:00
2021-01-22 23:16:44 +03:00
// names must be equal
return 0;
});
return this.filter_list.filter(option => {
return option.value.toLowerCase().includes(this.search.toLowerCase())
});
},
filteredValues() {
this.values.sort(function (a, b) {
var nameA = a.value.toUpperCase(); // ignore upper and lowercase
var nameB = b.value.toUpperCase(); // ignore upper and lowercase
if (nameA < nameB) {
return -1;
}
2020-11-06 01:48:49 +03:00
2021-01-22 23:16:44 +03:00
if (nameA > nameB) {
return 1;
}
// names must be equal
return 0;
});
2020-11-06 22:34:53 +03:00
2021-01-22 23:16:44 +03:00
return this.values.filter(value => {
return value.value.toLowerCase().includes(this.search.toLowerCase())
})
2020-11-06 01:48:49 +03:00
}
},
2021-01-22 23:16:44 +03:00
watch: {
visible: {
handler: function(newValue) {
if (newValue) {
document.addEventListener('click', this.closeIfClickedOutside);
}
},
deep: true
}
2020-11-06 01:48:49 +03:00
},
};
2019-11-16 10:21:14 +03:00
</script>
2020-11-06 01:48:49 +03:00
<style>
2021-06-01 14:43:27 +03:00
.searh-field {
border: 1px solid #dee2e6;
border-radius: 0.25rem;
}
.searh-field .tags-group {
display: contents;
}
.searh-field .el-tag.el-tag--primary {
background: #f6f9fc;
background-color: #f6f9fc;
border-color: #f6f9fc;
color: #8898aa;
margin-top: 7px;
}
.searh-field .tags-group:hover > span {
background:#cbd4de;
background-color: #cbd4de;
border-color: #cbd4de;
}
.searh-field .el-tag.el-tag--primary .el-tag__close.el-icon-close {
color: #8898aa;
}
.searh-field .el-tag-option {
border-radius: 0.25rem 0 0 0.25rem;
margin-left: 10px;
}
.searh-field .el-tag-operator {
border-radius: 0;
margin-left: -1px;
margin-right: -1px;
}
.searh-field .el-tag-value {
border-radius: 0 0.25rem 0.25rem 0;
margin-right: 10px;
}
.searh-field .el-select.input-new-tag {
width: 100%;
}
.searh-field .input-full {
width: 100%;
}
.searh-field .btn.btn-link {
width: inherit;
text-align: left;
display: flex;
margin: 0;
text-overflow: inherit;
text-align: left;
text-overflow: ellipsis;
padding: unset;
color: #212529;
}
.searh-field .btn.btn-link.clear {
position: absolute;
top: 0;
right: 0;
width: 45px;
height: 45px;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
color: #adb5bd;
opacity: 1;
}
.searh-field .btn.btn-link.clear:hover {
color: #8898aa;
}
.searh-field .btn-helptext {
margin-left: auto;
color: var(--gray);
}
.searh-field .btn:not(:disabled):not(.disabled):active:focus,
.searh-field .btn:not(:disabled):not(.disabled).active:focus {
-webkit-box-shadow: none !important;
box-shadow: none !important;
}
.searh-field .form-control.datepicker.flatpickr-input {
padding: inherit !important;
}
.searh-field .dropdown-menu.operator {
min-width: 50px !important;
}
.searh-field .dropdown-menu.operator .btn i:not(:last-child), .btn svg:not(:last-child) {
margin-right: inherit !important;
}
</style>