ASCU_ALL/Site/js/tech_cycle.js
2024-09-22 04:27:05 +05:00

112 lines
3.1 KiB
JavaScript

var tech_cycle_table = $('#tech_cycle_table');
var data_tech_cycle = null;
var params_tech_cycle_name = null;
var params_tech_cycle_color = null;
//Первая загрузка страницы
$(document).ready(
async function () {
var flag_pasport_load = await get_url_params();
pasport_fill_label();
pasport_show_lable();
if (!flag_pasport_load)
return;
show_menu();
if (!pasport_fill_date())
return;
pasport_show_date();
var tc_data = load_data_tech_cycle();
var tc_name = load_params_tech_cycle_name();
var tc_color = load_params_tech_cycle_color();
await Promise.all([tc_data, tc_name, tc_color]);
if (tc_data)
fill_table_tech_cycle();
}
);
async function load_data_tech_cycle() {
try {
var res = await $.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/date/gettechcycle',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"vdp": pasport_data.numVDP,
"start": pasport_data.dStart,
"end": pasport_data.dEnd
})
});
data_tech_cycle = res.techCycle;
return true;
}
catch (err) {
data_tech_cycle = null;
alert("Ошибка загрузки тех. цикла");
return false;
}
}
async function load_params_tech_cycle_name() {
try {
var res = await $.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/params/gettechcyclename',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({})
});
params_tech_cycle_name = res.name;
return true;
}
catch (err) {
params_tech_cycle_name = null;
alert("Ошибка загрузки имен тех. цикла");
return false;
}
}
async function load_params_tech_cycle_color() {
try {
var res = await $.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/params/gettechcyclecolor',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({})
});
params_tech_cycle_color = res.color;
return true;
}
catch (err) {
params_tech_cycle_color = null;
alert("Ошибка загрузки цветов тех. цикла");
return false;
}
}
function fill_table_tech_cycle() {
for (var i = 0; i < data_tech_cycle.length; i++) {
var color = params_tech_cycle_color != null ?
params_tech_cycle_color.find(item => item.index == data_tech_cycle[i].index) :
'#ffffff';
color = color != undefined ? color.color : '#ffffff';
var name = params_tech_cycle_name != null ?
params_tech_cycle_name.find(item => item.index == data_tech_cycle[i].index) :
'Технологический цикл №' + data_tech_cycle[i].index;
name = name != undefined ?
name = name.name :
'Технологический цикл №' + data_tech_cycle[i].index;
tech_cycle_table.find('tbody').append(
'<tr style="background-color : ' + color + '20;">' +
'<td>' + (i + 1) +
'</td>' +
'<td>' + data_tech_cycle[i].start +
'</td>' +
'<td>' + name +
'</td>' +
'</tr>');
}
}