355 lines
15 KiB
JavaScript
355 lines
15 KiB
JavaScript
|
|
var contract_form = new Vue({
|
||
|
|
el: '#contract_form',
|
||
|
|
components: {
|
||
|
|
|
||
|
|
vuejsDatepicker: window.vuejsDatepicker
|
||
|
|
},
|
||
|
|
data() {
|
||
|
|
|
||
|
|
return {
|
||
|
|
ru: vdp_translation_ru.js,
|
||
|
|
agency_id: $('#session_agency_id').val() || null,
|
||
|
|
isShow: false,
|
||
|
|
errorText: '',
|
||
|
|
errorMes: false,
|
||
|
|
errors: { 'number': 0, 'type': 0, 'celendar': 0 },
|
||
|
|
isPreloader: 1,
|
||
|
|
types_contract: [{ 'code': 0, 'type': '' }],
|
||
|
|
type_contract: null,
|
||
|
|
id: 0,
|
||
|
|
number: null,
|
||
|
|
date_start: new Date(),
|
||
|
|
date_end: new Date(),
|
||
|
|
format: "dd.MM.yyyy",
|
||
|
|
mondayfirst: true,
|
||
|
|
OpenIndicator: {
|
||
|
|
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
|
||
|
|
},
|
||
|
|
days_mes_end: 10,
|
||
|
|
no_mes_end: 0,
|
||
|
|
parent_id: 0,
|
||
|
|
parent_type: null,
|
||
|
|
parent_index: -1,
|
||
|
|
}
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
|
||
|
|
//Открытие
|
||
|
|
open() {
|
||
|
|
$("body").addClass("lock");
|
||
|
|
this.clear();
|
||
|
|
this.isShow = true;
|
||
|
|
this.isPreloader = 0;
|
||
|
|
|
||
|
|
if (this.id > 0) {
|
||
|
|
|
||
|
|
axios.post('/ajax/ajax_vue_contract.php', {
|
||
|
|
request: 'get_contract',
|
||
|
|
parent_id: this.parent_id,
|
||
|
|
parent_type: this.parent_type,
|
||
|
|
id: this.id,
|
||
|
|
}, )
|
||
|
|
.then((response) => {
|
||
|
|
|
||
|
|
var res = response.data;
|
||
|
|
this.number = res.number;
|
||
|
|
this.type_contract = res.type;
|
||
|
|
this.date_start = this.get_date(res.date_start);
|
||
|
|
this.date_end = this.get_date(res.date_end);
|
||
|
|
this.days_mes_end = res.days;
|
||
|
|
this.no_mes_end = res.send;
|
||
|
|
|
||
|
|
|
||
|
|
})
|
||
|
|
.catch(function(error) {
|
||
|
|
console.log(error);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
clear() {
|
||
|
|
this.number = null;
|
||
|
|
this.date_start = new Date();
|
||
|
|
this.date_end = new Date();
|
||
|
|
this.days_mes_end = 10;
|
||
|
|
this.no_mes_end = 0;
|
||
|
|
this.type_contract = null;
|
||
|
|
this.clearErrors();
|
||
|
|
},
|
||
|
|
|
||
|
|
//Очистка ошибок
|
||
|
|
clearErrors() {
|
||
|
|
this.errorText = '';
|
||
|
|
this.errors = { 'number': 0, 'type': 0, 'celendar': 0 };
|
||
|
|
this.errorMes = false;
|
||
|
|
},
|
||
|
|
|
||
|
|
//Типы договоров
|
||
|
|
getTypesContract() {
|
||
|
|
axios.post('/ajax/ajax_vue_contract.php', {
|
||
|
|
request: 'get_types_contract',
|
||
|
|
agency_id: this.agency_id,
|
||
|
|
}, )
|
||
|
|
.then((response) => {
|
||
|
|
this.types_contract = response.data;
|
||
|
|
})
|
||
|
|
.catch(function(error) {
|
||
|
|
console.log(error);
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
//Закрытие
|
||
|
|
closes() {
|
||
|
|
this.isShow = false;
|
||
|
|
this.isPreloader = 1;
|
||
|
|
this.parent_id = 0;
|
||
|
|
this.parent_type = null;
|
||
|
|
this.id = 0;
|
||
|
|
this.parent_index = -1;
|
||
|
|
$("body").removeClass("lock");
|
||
|
|
$('.jw__add-popup').removeClass('is__show');
|
||
|
|
},
|
||
|
|
|
||
|
|
//сохранение
|
||
|
|
save() {
|
||
|
|
this.clearErrors();
|
||
|
|
if (this.isEmpty(this.number)) {
|
||
|
|
this.errorText += '<p>Введите номер договора</p>';
|
||
|
|
this.errorMes = true;
|
||
|
|
this.errors.number = 1;
|
||
|
|
}
|
||
|
|
if (this.type_contract == 0 || this.isEmpty(this.type_contract)) {
|
||
|
|
this.errorText += '<p>Выбирете тип договора</p>';
|
||
|
|
this.errorMes = true;
|
||
|
|
this.errors.type = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (this.date_start > this.date_end) {
|
||
|
|
this.errorText += '<p>Дата начала не может быть больше даты окончания</p>';
|
||
|
|
this.errorMes = true;
|
||
|
|
this.errors.calendar = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
var send = 0;
|
||
|
|
if (this.no_mes_end) {
|
||
|
|
send = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!this.errorMes) {
|
||
|
|
var name_type = this.types_contract.find((el, idx) => el.code == this.type_contract);
|
||
|
|
if (this.parent_id == 'req0') {
|
||
|
|
var contract = {
|
||
|
|
number: this.number,
|
||
|
|
type: this.type_contract,
|
||
|
|
date_start: this.date_start,
|
||
|
|
date_end: this.date_end,
|
||
|
|
days_mes_end: this.days_mes_end,
|
||
|
|
no_mes_end: send,
|
||
|
|
parent_type: this.parent_type,
|
||
|
|
parent_id: this.parent_id,
|
||
|
|
id: this.id,
|
||
|
|
agency_id: this.agency_id,
|
||
|
|
name: name_type.type + ' №' + this.number,
|
||
|
|
}
|
||
|
|
if (this.parent_index == -1) {
|
||
|
|
req_form.contracts.push(contract)
|
||
|
|
} else {
|
||
|
|
req_form.contracts[this.parent_index] = contract;
|
||
|
|
}
|
||
|
|
this.closes();
|
||
|
|
} else if (this.parent_id == 0 && this.parent_type == 'client') {
|
||
|
|
var contract = JSON.stringify({
|
||
|
|
number: this.number,
|
||
|
|
type: this.type_contract,
|
||
|
|
date_start: this.date_start,
|
||
|
|
date_end: this.date_end,
|
||
|
|
days_mes_end: this.days_mes_end,
|
||
|
|
no_mes_end: send,
|
||
|
|
parent_type: this.parent_type,
|
||
|
|
parent_id: this.parent_id,
|
||
|
|
id: this.id,
|
||
|
|
agency_id: this.agency_id,
|
||
|
|
name: name_type.type + ' №' + this.number,
|
||
|
|
});
|
||
|
|
var index = this.parent_index;
|
||
|
|
if (index == -1) {
|
||
|
|
var index = 0;
|
||
|
|
$('#list_contracts_client_form div label').each(function() {
|
||
|
|
index++;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
var html = '';
|
||
|
|
var edit = false;
|
||
|
|
console.log($('#contract_elem_client' + index).length);
|
||
|
|
if ($('#contract_elem_client' + index).length > 0) {
|
||
|
|
edit = true;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!edit) {
|
||
|
|
html += '<div data-client="0" data-contract="0" data-data=\'' + contract + '\' id="contract_elem_client' + index + '">';
|
||
|
|
}
|
||
|
|
html += '<label style="display: inline-block;">' +
|
||
|
|
'<a href="javascript:{};" onclick="open_form_contract(0, 0,\'client\', this)">' + name_type.type + ' №' + this.number + '</a>' +
|
||
|
|
'</label>' +
|
||
|
|
'<a href="javascript:{};" onclick="deleteContract(' + index + ')" title="Удалить" style="padding: 6px 8px; border: none; line-height: 34px;"><i class="ti-trash"></i></a>';
|
||
|
|
if (!edit) {
|
||
|
|
html += '</div>';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (edit) {
|
||
|
|
$('#contract_elem_client' + index).html(html);
|
||
|
|
} else {
|
||
|
|
$("#list_contracts_client_form").append(html);
|
||
|
|
}
|
||
|
|
this.closes();
|
||
|
|
} else {
|
||
|
|
console.log(this.agency_id);
|
||
|
|
axios.post('/ajax/ajax_vue_contract.php', {
|
||
|
|
request: 'save_contract',
|
||
|
|
number: this.number,
|
||
|
|
type: this.type_contract,
|
||
|
|
date_start: this.date_start,
|
||
|
|
date_end: this.date_end,
|
||
|
|
days_mes_end: this.days_mes_end,
|
||
|
|
no_mes_end: send,
|
||
|
|
parent_type: this.parent_type,
|
||
|
|
parent_id: this.parent_id,
|
||
|
|
id: this.id,
|
||
|
|
agency_id: this.agency_id,
|
||
|
|
}, )
|
||
|
|
.then((response) => {
|
||
|
|
|
||
|
|
var parent_id = this.parent_id;
|
||
|
|
var parent_type = this.parent_type;
|
||
|
|
|
||
|
|
if (typeof requisitions != "undefined") {
|
||
|
|
requisitions.return_contract_form(this.parent_id, response.data);
|
||
|
|
}
|
||
|
|
if ($('#send_bg_new').css('display') == 'block' && parent_type == 'client') {
|
||
|
|
get_contracts_client(parent_id);
|
||
|
|
}
|
||
|
|
if ($('#client__' + parent_id + ' .contracts').length > 0 ||
|
||
|
|
$('#item' + parent_id + ' .contracts').length > 0) {
|
||
|
|
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||
|
|
request: 'get_contracts',
|
||
|
|
parent_id: this.parent_id,
|
||
|
|
type: this.parent_type,
|
||
|
|
}, )
|
||
|
|
.then((response) => {
|
||
|
|
|
||
|
|
var res = response.data;
|
||
|
|
if (res.contracts.length > 0) {
|
||
|
|
$('#client__' + parent_id + ' .contracts').show().attr('title', res.contracts_name);
|
||
|
|
$('#item' + parent_id + ' .contracts').show();
|
||
|
|
var html = '';
|
||
|
|
if(parent_type == 'object'){
|
||
|
|
var index = (res.contracts.length-1);
|
||
|
|
html = '<div class="contract_div" id="contract_elem_object'+res.contracts[index].id+'" style="padding: 4px 18px 6px; overflow: hidden; width: 300px; text-overflow: ellipsis; white-space: nowrap;">';
|
||
|
|
html += '<div title="'+res.contracts[index].name+'" style="width: 250px; overflow: hidden; text-overflow: ellipsis; float: left; white-space: nowrap;" class="contract_href';
|
||
|
|
if (res.contracts[index].expired) {
|
||
|
|
html += ' expired';
|
||
|
|
}
|
||
|
|
html += '" onclick="open_form_contract(\'' + parent_id + '\', \'' + res.contracts[index].id + '\', \'' + parent_type + '\')">'+res.contracts[index].name+'</div>';
|
||
|
|
html += '<a href="javascript:{};" onclick="deleteContractObject(\'' + parent_id + '\', \'' + res.contracts[index].id + '\', \'' + parent_type + '\')" title="Удалить" style="padding: 0 5px;border: none;float: left;margin-top: -2px;"><i class="ti-trash"></i></a>';
|
||
|
|
|
||
|
|
html += '</div>';
|
||
|
|
$('#popup__actions_contract_' + parent_id + ' .actions-menu__inner').append(html);
|
||
|
|
} else {
|
||
|
|
html = '<i class="ti-file"></i><span> ';
|
||
|
|
for (var i = 0; i < res.contracts.length; i++) {
|
||
|
|
if (html != '<i class="ti-file"></i><span> ') {
|
||
|
|
html += '<span>, </span>';
|
||
|
|
}
|
||
|
|
html += '<span class="contract_href';
|
||
|
|
if (res.contracts[i].expired) {
|
||
|
|
html += ' expired"';
|
||
|
|
}
|
||
|
|
html += '" onclick="open_form_contract(\'' + parent_id + '\', \'' + res.contracts[i].id + '\', \'' + parent_type + '\')">';
|
||
|
|
html += res.contracts[i].name + '</span>';
|
||
|
|
html += '</span>';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$('#client__' + parent_id + ' .contracts').html(html);
|
||
|
|
|
||
|
|
//$('#item' + parent_id + ' .contracts').html(html);
|
||
|
|
} else {
|
||
|
|
$('#client__' + parent_id + ' .contracts').hide();
|
||
|
|
$('#item' + parent_id + ' .contracts').hide();
|
||
|
|
}
|
||
|
|
|
||
|
|
})
|
||
|
|
.catch(function(error) {
|
||
|
|
console.log(error);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
this.closes();
|
||
|
|
})
|
||
|
|
.catch(function(error) {
|
||
|
|
console.log(error);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$('.full_modal-bg').stop().animate({ scrollTop: 0 }, '500');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
//Установка даты
|
||
|
|
get_date(date) {
|
||
|
|
var arrDate = date.split('.');
|
||
|
|
var year = parseInt(arrDate[2]);
|
||
|
|
var mes = parseInt(arrDate[1]) - 1;
|
||
|
|
var day = parseInt(arrDate[0]);
|
||
|
|
return new Date(year, mes, day);
|
||
|
|
},
|
||
|
|
|
||
|
|
//Удаление
|
||
|
|
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() {
|
||
|
|
|
||
|
|
$("#contract_form").removeClass("hidden");
|
||
|
|
this.getTypesContract();
|
||
|
|
|
||
|
|
}
|
||
|
|
})
|