626 lines
20 KiB
JavaScript
626 lines
20 KiB
JavaScript
var export_settings = new Vue({
|
|
el: '#export_settings',
|
|
components: {
|
|
|
|
vuejsDatepicker: window.vuejsDatepicker
|
|
},
|
|
data() {
|
|
|
|
return {
|
|
user_id: $('#session_user_id').val(),
|
|
agency_id: $('#session_agency_id').val() || null,
|
|
isShow: false,
|
|
is_modal_export: false,
|
|
OpenIndicator: {
|
|
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
|
|
},
|
|
|
|
isPreloader: 0,
|
|
tab: 'setting',
|
|
reqFields: [],
|
|
columnsReq: {},
|
|
progress: 0,
|
|
limit: 500,
|
|
rows: 0,
|
|
title_raport: '',
|
|
error_title_raport: false,
|
|
castomAllChange: 0,
|
|
is_write_file: false,
|
|
|
|
columns: {
|
|
id: 1,
|
|
date: 1,
|
|
responsible: 1,
|
|
client: 1,
|
|
phone: 1,
|
|
email: 1,
|
|
name_req: 1,
|
|
type_req: 1,
|
|
contract_type: 1,
|
|
contract_number: 1,
|
|
contract_date: 1,
|
|
nazv_obj: 0,
|
|
address_obj: 0,
|
|
price_obj: 0,
|
|
funnel: 1,
|
|
tag: 1,
|
|
step: 1,
|
|
desc: 1,
|
|
events: 1,
|
|
events_call: 0,
|
|
source: 1,
|
|
partner: 1,
|
|
denial: 1,
|
|
denial_comm: 1,
|
|
summa: 1,
|
|
date_close: 0,
|
|
},
|
|
raport_id: null,
|
|
raports: [],
|
|
raport_list: [],
|
|
funnels: [],
|
|
type: 'req',
|
|
isShowRaport: false,
|
|
}
|
|
},
|
|
methods: {
|
|
|
|
//Открытие
|
|
open() {
|
|
$("body").addClass("lock");
|
|
$('.ui-tooltip').remove();
|
|
$('.jw__add-popup').removeClass('is__show');
|
|
|
|
this.isShow = true;
|
|
|
|
this.getSettingsExport();
|
|
|
|
},
|
|
//Выбор таба
|
|
changeTab(tab) {
|
|
this.tab = tab;
|
|
},
|
|
|
|
//Выбор колонки
|
|
checkColumn(nameColumn) {
|
|
if (this.columns[nameColumn] == 0) {
|
|
this.columns[nameColumn] = 1;
|
|
} else {
|
|
this.columns[nameColumn] = 0;
|
|
}
|
|
},
|
|
|
|
//Выбор колонки
|
|
checkColumnField(idColumn) {
|
|
if (this.columnsReq[idColumn].val == 0) {
|
|
this.columnsReq[idColumn].val = 1;
|
|
} else {
|
|
this.columnsReq[idColumn].val = 0;
|
|
this.castomAllChange = 0;
|
|
}
|
|
},
|
|
checkColumnFieldAll(){
|
|
// this.checkColumnFieldAll
|
|
if (this.castomAllChange == 0) {
|
|
this.castomAllChange = 1;
|
|
} else {
|
|
this.castomAllChange = 0;
|
|
|
|
}
|
|
|
|
for(let idColumn in this.columnsReq){
|
|
this.columnsReq[idColumn].val = this.castomAllChange;
|
|
}
|
|
|
|
},
|
|
|
|
clear() {
|
|
this.getReqFields();
|
|
this.title_raport = '';
|
|
this.error_title_raport = false;
|
|
this.tab = 'setting';
|
|
this.castomAllChange = 0;
|
|
this.is_write_file = false;
|
|
this.columns = {
|
|
id: 1,
|
|
date: 1,
|
|
responsible: 1,
|
|
client: 1,
|
|
phone: 1,
|
|
email: 1,
|
|
name_req: 1,
|
|
type_req: 1,
|
|
contract_type: 1,
|
|
contract_number: 1,
|
|
contract_date: 1,
|
|
nazv_obj: 0,
|
|
address_obj: 0,
|
|
price_obj: 0,
|
|
funnel: 1,
|
|
tag: 1,
|
|
step: 1,
|
|
desc: 1,
|
|
events: 1,
|
|
events_call: 0,
|
|
source: 1,
|
|
partner: 1,
|
|
denial: 1,
|
|
denial_comm: 1,
|
|
summa: 1,
|
|
date_close: 0,
|
|
|
|
}
|
|
this.raport_id = 0;
|
|
this.raports = [];
|
|
this.get_raports();
|
|
this.get_funnels_steps();
|
|
$('#order_export').hide();
|
|
$("#order_export").html('');
|
|
|
|
},
|
|
|
|
//Очистка ошибок
|
|
clearErrors() {
|
|
this.errorText = '';
|
|
this.errors = { 'number': 0, 'type': 0, 'celendar': 0 };
|
|
this.errorMes = false;
|
|
},
|
|
|
|
|
|
//Закрытие
|
|
closes() {
|
|
this.isShow = false;
|
|
this.isPreloader = 0;
|
|
this.clear();
|
|
$("body").removeClass("lock");
|
|
$('.jw__add-popup').removeClass('is__show');
|
|
},
|
|
|
|
close_modal_export() {
|
|
this.is_modal_export = false;
|
|
$("body").removeClass("lock");
|
|
$('.jw__add-popup').removeClass('is__show');
|
|
},
|
|
|
|
//Получение дополнительных полей заявок
|
|
getReqFields() {
|
|
//console.log(this.funnel_id);
|
|
axios.post('/ajax/ajax_vue_requisitions.php', {
|
|
request: 'get_req_fields',
|
|
agency_id: this.agency_id,
|
|
req_id: 0,
|
|
funnel_id: 0,
|
|
}).then((response) => {
|
|
// console.log(response.data);
|
|
|
|
this.reqFields = response.data.fields;
|
|
|
|
|
|
//this.reqFieldsLinking = response.data.linking_fields;
|
|
|
|
|
|
for (var i = 0; i < this.reqFields.length; i++) {
|
|
this.$set(this.columnsReq, 'column' + this.reqFields[i].id, { 'title': this.reqFields[i].title, val: 0 });
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(function(error) {
|
|
//console.log(error);
|
|
});
|
|
},
|
|
|
|
//сохранение
|
|
save() {
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'saveSettingExport',
|
|
user_id: this.user_id,
|
|
field_fixes: this.columns,
|
|
field_castom: this.columnsReq,
|
|
type: 'req',
|
|
is_raport: 0,
|
|
}, )
|
|
.then((response) => {
|
|
//console.log(response.data);
|
|
this.closes();
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
|
|
//Создать отчет
|
|
saveRaport() {
|
|
if (this.isEmpty(this.title_raport)) {
|
|
this.error_title_raport = true;
|
|
} else {
|
|
// console.log(this.columns);
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'saveSettingExport',
|
|
user_id: this.user_id,
|
|
field_fixes: this.columns,
|
|
field_castom: this.columnsReq,
|
|
field_funnels: this.funnels,
|
|
type: 'req',
|
|
is_raport: 1,
|
|
raport_id: this.raport_id,
|
|
title_raport: this.title_raport,
|
|
}, )
|
|
.then((response) => {
|
|
|
|
// console.log(response.data);
|
|
this.closes();
|
|
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
},
|
|
|
|
select_raport(){
|
|
this.isPreloader = 1;
|
|
if(this.raport_id == 0 || this.isEmpty(this.raport_id)){
|
|
this.tab='setting';
|
|
}
|
|
this.getSettingsExport();
|
|
|
|
},
|
|
|
|
editRaport(raport_id){
|
|
this.tab='setting';
|
|
this.raport_id = raport_id;
|
|
this.select_raport();
|
|
},
|
|
|
|
deleteRaport(raport_id = undefined){
|
|
if(raport_id){
|
|
this.raport_id = raport_id;
|
|
}
|
|
$('.jw__add-popup').removeClass('is__show');
|
|
if (confirm('Вы действительно хотите удалить это отчет?')) {
|
|
this.isPreloader = 1;
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'deleteRaport',
|
|
agency_id: this.agency_id,
|
|
raport_id: this.raport_id,
|
|
|
|
|
|
}, )
|
|
.then((response) => {
|
|
// console.log(response.data);
|
|
|
|
if(this.tab != 'order'){
|
|
this.tab='setting';
|
|
}
|
|
this.raport_id = 0;
|
|
this.getSettingsExport();
|
|
this.get_raports();
|
|
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
},
|
|
|
|
//Получение настроек
|
|
getSettingsExport() {
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'getSettingsExport',
|
|
user_id: this.user_id,
|
|
type: 'req',
|
|
raport_id: this.raport_id,
|
|
}, )
|
|
.then((response) => {
|
|
// console.log(response.data);
|
|
res = response.data;
|
|
|
|
this.title_raport = res.title_raport;
|
|
for (var index in res.fields_fixes) {
|
|
if (this.columns[index] !== undefined) {
|
|
|
|
this.columns[index] = res.fields_fixes[index];
|
|
}
|
|
}
|
|
|
|
if(!this.isEmpty(res.fields_fixes)){
|
|
for (var index in this.columns) {
|
|
if(res.fields_fixes[index] === undefined){
|
|
this.columns[index] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (var index in res.fields_castom) {
|
|
if (this.columnsReq[index]) {
|
|
this.columnsReq[index].val = res.fields_castom[index].val;
|
|
}
|
|
}
|
|
if(this.isEmpty(res.fields_funnels)){
|
|
this.get_funnels_steps();
|
|
} else {
|
|
for (var index in res.fields_funnels){
|
|
if(this.funnels[index]){
|
|
this.funnels[index].is_active = res.fields_funnels[index].is_active;
|
|
for(index2 in res.fields_funnels[index].steps){
|
|
if(this.funnels[index].steps[index2]){
|
|
this.funnels[index].steps[index2].is_active = res.fields_funnels[index].steps[index2].is_active;
|
|
for(index3 in res.fields_funnels[index].steps[index2].fields){
|
|
if(this.funnels[index].steps[index2].fields[index3]){
|
|
this.funnels[index].steps[index2].fields[index3].is_active = res.fields_funnels[index].steps[index2].fields[index3].is_active;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.isPreloader = 0;
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
|
|
|
|
|
|
//Получение воронок
|
|
get_funnels_steps(){
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'get_funnels_steps',
|
|
agency_id: this.agency_id,
|
|
type: 'req',
|
|
|
|
}, )
|
|
.then((response) => {
|
|
// console.log(response.data);
|
|
this.funnels = response.data;
|
|
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
|
|
//
|
|
checkFunnelActive(funnelId){
|
|
if(this.funnels[funnelId].is_active == 0){
|
|
this.funnels[funnelId].is_active = 1;
|
|
} else {
|
|
this.funnels[funnelId].is_active = 0;
|
|
}
|
|
|
|
},
|
|
checkFunnelStepActive(funnelId, stepId){
|
|
if(this.funnels[funnelId].steps['step'+stepId].is_active == 0){
|
|
this.funnels[funnelId].steps['step'+stepId].is_active = 1;
|
|
} else {
|
|
this.funnels[funnelId].steps['step'+stepId].is_active = 0;
|
|
}
|
|
|
|
},
|
|
checkFunnelStepFieldActive(funnelId, stepId, fieldIndex){
|
|
if(this.funnels[funnelId].steps['step'+stepId].fields[fieldIndex].is_active == 0){
|
|
this.funnels[funnelId].steps['step'+stepId].fields[fieldIndex].is_active = 1;
|
|
} else {
|
|
this.funnels[funnelId].steps['step'+stepId].fields[fieldIndex].is_active = 0;
|
|
}
|
|
},
|
|
|
|
//Экспорт заявок
|
|
export_req(page = 0) {
|
|
var filter = {'stages': {'work': 0, 'hit':0}};
|
|
if($('#filter_stage_work').hasClass('active')){
|
|
filter.stages.work = 1;
|
|
}
|
|
if($('#filter_stage_hit').hasClass('active')){
|
|
filter.stages.hit = 1;
|
|
}
|
|
|
|
this.closes_raport();
|
|
this.is_modal_export = true;
|
|
if (page == 0) {
|
|
this.progress = 0;
|
|
page = 1;
|
|
}
|
|
var temp_total = 0;
|
|
temp_total = $('#totalCountReq .text').text();
|
|
// console.log(temp_total);
|
|
// if(this.agency_id != 8826){
|
|
if(temp_total > 5000){
|
|
this.limit = 1000;
|
|
}
|
|
if (temp_total > 10000){
|
|
this.limit = 2500;
|
|
}
|
|
/* if (temp_total > 40000){
|
|
this.limit = 5000;
|
|
}*/
|
|
|
|
// console.log(this.limit);
|
|
// if(this.agency_id != 8826){
|
|
axios.post('/ajax/export_req_vue_progress.php', {
|
|
page: page,
|
|
columns: this.columns,
|
|
user_id: this.user_id,
|
|
agency_id: this.agency_id,
|
|
type: 'req',
|
|
limit: this.limit,
|
|
raport_id: this.raport_id,
|
|
filter: filter,
|
|
}, )
|
|
.then((response) => {
|
|
console.log(response.data);
|
|
let res = response.data;
|
|
this.progress = res.procent;
|
|
page++;
|
|
if (res.cont === true) {
|
|
export_settings.export_req(page);
|
|
} else {
|
|
var ref = this;
|
|
setTimeout(function() {
|
|
ref.is_write_file = true;
|
|
|
|
}, 1000);
|
|
// this.is_write_file = true;
|
|
//this.chec_write_file();
|
|
axios.post('/ajax/get_excel_progress.php', {
|
|
|
|
user_id: this.user_id,
|
|
|
|
}).then((response) => {
|
|
// console.log(response.data);
|
|
this.chec_write_file();
|
|
}).catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
|
|
|
|
|
|
}
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
// }
|
|
|
|
},
|
|
|
|
chec_write_file(){
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'get_write_file',
|
|
user_id: this.user_id,
|
|
|
|
}, )
|
|
.then((response) => {
|
|
//console.log(response.data);
|
|
res = response.data;
|
|
let href = res.file;
|
|
let name = res.name;
|
|
var ref = this;
|
|
if (res.done === 'ok') {
|
|
setTimeout(function() {
|
|
ref.is_write_file = false;
|
|
|
|
ref.is_modal_export = false;
|
|
//if (res.done === 'ok') {
|
|
|
|
let $a = $("<a />");
|
|
$a.attr("href", href);
|
|
|
|
$("body").append($a);
|
|
$a.attr("download", name);
|
|
//console.log($a);
|
|
$a[0].click();
|
|
$a.remove();
|
|
// }
|
|
}, 1000);
|
|
}
|
|
/* } else {
|
|
this.chec_write_file();
|
|
}*/
|
|
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
|
|
//Отчеты
|
|
get_raports(){
|
|
axios.post('/ajax/ajax_vue_export.php', {
|
|
request: 'get_raports',
|
|
user_id: this.user_id,
|
|
type: 'req',
|
|
}, )
|
|
.then((response) => {
|
|
//console.log(response.data);
|
|
this.raports = response.data.list_raports;
|
|
this.raport_list = response.data.list;
|
|
let html = '<p id="__TABLE_LIST_CLOSE"></p><div><p data-table-id="0">Стандартная</p></div>';
|
|
$('#__TABLE_LIST').html('');
|
|
|
|
for (let i = 0; i < this.raports.length; i++) {
|
|
html += '<div><p data-table-id="' + this.raports[i].code + '">' + this.raports[i].name + '</p></div>';
|
|
}
|
|
$('#__TABLE_LIST').html(html);
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
|
|
show_table(){
|
|
showRaportExport('req', this.raport_id);
|
|
},
|
|
|
|
closes_raport(){
|
|
$("body").removeClass("lock");
|
|
$('.ui-tooltip').remove();
|
|
$('.jw__add-popup').removeClass('is__show');
|
|
this.isShowRaport = false;
|
|
$('#order_export').hide();
|
|
$("#order_export").html('');
|
|
},
|
|
|
|
open_raport(){
|
|
$("body").addClass("lock");
|
|
$('.ui-tooltip').remove();
|
|
$('.jw__add-popup').removeClass('is__show');
|
|
this.getSettingsExport();
|
|
this.isShowRaport = true;
|
|
showRaportExport('req', this.raport_id);
|
|
},
|
|
|
|
//Удаление
|
|
delete(id, type) {
|
|
|
|
axios.post('/ajax/ajax_vue_contract.php', {
|
|
request: 'delete_contract',
|
|
id: id,
|
|
type: type,
|
|
}, )
|
|
.then((response) => {
|
|
// console.log(response.data);
|
|
})
|
|
.catch(function(error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
|
|
//Проверка на пустоту
|
|
isEmpty(data) {
|
|
if (typeof(data) === 'object') {
|
|
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') {
|
|
return true;
|
|
} else if (!data) {
|
|
return true;
|
|
}
|
|
return false;
|
|
} else if (typeof(data) === 'string') {
|
|
if (!data.trim()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
} else if (typeof(data) === 'undefined') {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
},
|
|
mounted() {
|
|
|
|
},
|
|
created: function() {
|
|
|
|
$("#export_settings").removeClass("hidden");
|
|
this.getReqFields();
|
|
this.get_raports();
|
|
this.get_funnels_steps();
|
|
|
|
}
|
|
}) |