Files
luos/resources/assets/js/home/ModalNewRequest.vue

182 lines
4.5 KiB
Vue
Raw Normal View History

2020-12-02 19:46:17 +00:00
<template>
<div>
<b-modal
ref="my-modal"
hide-footer
2020-12-04 13:33:23 +00:00
:title="$t('ID_WEVE_MADE_IT_EASY_FOR_YOU')"
2020-12-02 19:46:17 +00:00
size="xl"
>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"
><i class="fas fa-search"></i
></span>
</div>
<input
v-model="filter"
type="text"
class="form-control"
2020-12-04 13:33:23 +00:00
:placeholder="$t('ID_CASES_MENU_SEARCH')"
2020-12-02 19:46:17 +00:00
aria-label="Search"
aria-describedby="basic-addon1"
@input="onChangeFilter"
/>
</div>
2020-12-04 13:33:23 +00:00
<div v-for="item in categoriesFiltered" :key="item.title">
2020-12-16 18:26:40 +00:00
<process-category :data="item" :disable="disable" />
2020-12-02 19:46:17 +00:00
</div>
</b-modal>
</div>
</template>
<script>
import ProcessCategory from "./../components/home/newRequest/ProcessCategory.vue";
import api from "./../api/index";
import _ from "lodash";
export default {
name: "ModalNewRequest",
components: {
ProcessCategory,
},
props: {
data: Object,
},
2020-12-04 13:33:23 +00:00
mounted() {},
2020-12-02 19:46:17 +00:00
data() {
return {
2020-12-16 18:26:40 +00:00
disable: false,
2020-12-02 19:46:17 +00:00
filter: "",
categories: [],
2020-12-04 13:33:23 +00:00
categoriesFiltered: [],
TRANSLATIONS: window.config.TRANSLATIONS,
2020-12-02 19:46:17 +00:00
};
},
methods: {
classBtn(cls) {
return "btn v-btn-request " + cls;
},
show() {
this.filter = "";
2020-12-02 19:46:17 +00:00
this.$refs["my-modal"].show();
this.getProcess();
},
getProcess() {
let that = this;
2020-12-04 13:33:23 +00:00
api.process.list
.start()
2020-12-02 19:46:17 +00:00
.then((response) => {
if (response.data && response.data.success !== "failure") {
that.categories = that.formatCategories(response.data);
that.categoriesFiltered = that.categories;
}
2020-12-02 19:46:17 +00:00
})
.catch((e) => {
console.error(e);
});
},
/**
* Change the property filter
*/
onChangeFilter() {
let that = this,
categories = [],
processes = [];
this.categoriesFiltered = [];
_.each(this.categories, (o) => {
processes = that.filterProcesses(o.items);
if (processes.length != 0) {
that.categoriesFiltered.push({
title: o.title,
items: processes,
});
}
});
},
/**
* Filter the processes in category, serach by title and description
*/
filterProcesses(processes) {
let that = this;
return _.filter(processes, (p) => {
return p.title.toLowerCase().indexOf(that.filter.toLowerCase()) !== -1 ||
p.description.toLowerCase().indexOf(that.filter.toLowerCase()) !== -1;
2020-12-02 19:46:17 +00:00
});
},
formatResponseGetProcess(response) {
let res = [],
items,
that = this,
data = response.data;
_.each(data, (o) => {
items = [];
_.each(o.children, (v) => {
items.push({
title: v.otherAttributes.value,
task_uid: v.tas_uid,
pro_uid: v.pro_uid,
description: v.otherAttributes.catname,
onClick: that.startNewCase,
});
});
res.push({
title: o.text,
items: items,
});
});
return res;
},
2020-12-04 13:33:23 +00:00
formatCategories(data) {
let res = [],
that = this,
index,
categories = [];
_.each(data, (o) => {
index = _.findIndex(categories, (c) => {
return c.id == o.pro_category;
2020-12-04 13:33:23 +00:00
});
if (index == -1) {
categories.push({
id: o.pro_category,
title: o.category_name,
2020-12-04 13:33:23 +00:00
items: [],
});
index = categories.length - 1;
}
categories[index].items.push({
title: o.pro_title,
description: o.pro_description,
task_uid: o.tas_uid,
pro_uid: o.pro_uid,
2020-12-04 13:33:23 +00:00
onClick: that.startNewCase,
});
});
return categories;
},
2020-12-02 19:46:17 +00:00
startNewCase(dt) {
let self = this;
2020-12-16 18:26:40 +00:00
this.disable = true;
2020-12-02 19:46:17 +00:00
api.cases
.start(dt)
.then(function (data) {
2020-12-04 13:33:23 +00:00
self.$refs["my-modal"].hide();
2020-12-07 15:59:15 +00:00
self.$parent.$parent.dataCase = {
APP_UID: data.data.APPLICATION,
DEL_INDEX: 1,
ACTION: "draft",
2021-01-28 19:05:33 +00:00
PRO_UID: data.data.PROCESS
2020-12-07 15:59:15 +00:00
};
2020-12-16 18:26:40 +00:00
self.disable = false;
2020-12-04 13:33:23 +00:00
self.$parent.$parent.page = "XCase";
2020-12-02 19:46:17 +00:00
})
.catch((err) => {
2020-12-16 18:26:40 +00:00
self.disable = false;
2020-12-02 19:46:17 +00:00
throw new Error(err);
});
},
},
};
</script>
<style>
</style>