ASCU_ALL/Site/js/index.js

221 lines
5.9 KiB
JavaScript
Raw Normal View History

2024-09-22 04:27:05 +05:00
var pasport_date_list = $('#pasport_date_list');
var search_button = $('#search_button');
var pasport_list = $('#pasport_list');
var pasport_select_button = $('#pasport_select_button');
var vdp_select = $('#vdp_select');
var vdp_date_start = $('#vdp_date_start');
var vdp_date_end = $('#vdp_date_end');
var vdp_time_start = $('#vdp_time_start');
var vdp_time_end = $('#vdp_time_end');
var vdp_select_button = $('#vdp_select_button');
//Первая загрузка страницы
$(document).ready(
async function () {
//fill elements
for (var i = 1; i < 51; i++)
vdp_select.append('<option value="' + i + '">' + i + '</option>');
for (var i = 91; i < 95; i++)
vdp_select.append('<option value="' + i + '">' + i + '</option>');
var d = new Date();
pasport_date_list.val(getDate(d));
vdp_date_end.val(getDate(d));
d.setDate(d.getDate() - 3);
vdp_date_start.val(getDate(d));
vdp_time_start.val('00:00:00');
vdp_time_end.val('23:59:59');
await get_url_params();
if (
pasport_data == undefined ||
pasport_data == null
)
return;
if (pasport_data.search_date != null) {
pasport_date_list.val(pasport_data.search_date);
if (pasport_data.search_name != null) {
func_search_button(
pasport_data.search_date,
pasport_data.search_name
);
func_pasport_select_button(
pasport_data.search_date,
pasport_data.search_name
);
}
else
search_button.click();
}
if (pasport_data.numVDP != null)
$('#vdp_select option[value=' + pasport_data.numVDP + ']').prop('selected', true);
if (pasport_data.dStart != null && pasport_data.dEnd != null) {
var st = pasport_data.dStart.split(' ');
var std = st[0].split('.');
var ed = pasport_data.dEnd.split(' ');
var edd = ed[0].split('.');
if (std.length == 1)
vdp_date_start.val(std[0]);
else
vdp_date_start.val(std[0] + '-' + std[1] + '-' + std[2]);
if (edd.length == 1)
vdp_date_end.val(edd[0]);
else
vdp_date_end.val(edd[0] + '-' + edd[1] + '-' + edd[2]);
vdp_time_start.val(st[1]);
vdp_time_end.val(ed[1]);
vdp_select_button.click();
}
else {
var d = new Date();
vdp_date_end.val(
getDate(d)
);
d.setDate(d.getDate() - 3);
vdp_date_start.val(
getDate(d)
);
vdp_time_start.val('00:00:00');
vdp_time_end.val('23:59:59');
}
pasport_fill_label()
pasport_show_lable();
if (pasport_fill_date())
pasport_show_date();
if (pasport_fill_info())
pasport_fill_info();
show_menu();
}
);
//Конвертация даты в строку
function getDate(date) {
var d = (date === undefined) ? new Date() : date;
t =
d.getFullYear() + "-" +
("0" + (d.getMonth() + 1)).slice(-2) + "-" +
("0" + d.getDate()).slice(-2);
return t;
}
//Изменение даты для поиска
pasport_date_list.change(
function () {
pasport_list.empty();
pasport_select_button.attr('hidden', true);
}
);
//Кнопка поиска списка по дате
search_button.click(
function () {
func_search_button(
pasport_date_list.val()
);
}
);
function func_search_button(data, name) {
$.ajax({
type: "POST",
url: 'https://vsmpo.mbucb.ru/api/pasport/getlist',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"date": data
}),
failure:
function (errMsg) {
pasport_select_button.attr('hidden', true);
alert("Не смог зугрузить список плавок. \n" + errMsg.name + ":" + errMsg.message + "\n" + errMsg.stack);
},
beforeSend:
function (jqXHR, settings) {
pasport_select_button.attr('hidden', true);
pasport_list.empty();
},
success: function (date) {
if (date === undefined || date.name === undefined || date.time === undefined) {
pasport_list.append('<option>Ошибка</option>');
return;
}
if (date.name === null || date.name.length === 0) {
pasport_list.append('<option>Плавок нет</option>');
return;
}
for (var i = 0; i < date.name.length; i++)
pasport_list.append('<option value="' + date.time[i] + '-' + date.name[i] + '">' + date.name[i] + '</option>');
if (name != undefined)
$('#pasport_list option[value=' + name + ']').prop('selected', true);
pasport_select_button.removeAttr('hidden');
}
});
}
pasport_select_button.click(
function () {
func_pasport_select_button(
pasport_date_list.val(),
pasport_list.find(':selected').val()
);
}
)
async function func_pasport_select_button(data, name) {
var res_load = await pasport_load(data, name);
pasport_fill_label();
pasport_show_lable();
if (!res_load)
return;
pasport_fill_date();
pasport_fill_info();
pasport_show_date();
pasport_show_info();
show_menu();
}
vdp_select_button.click(
function () {
func_vdp_select_button(
vdp_select.find(':selected').val(),
vdp_date_start.val(),
vdp_time_start.val(),
vdp_date_end.val(),
vdp_time_end.val()
);
}
)
function func_vdp_select_button(vdp, ds, ts, de, te) {
pasport_hide_all();
hide_menu();
var d_s = ds.split('-');
var t_s = ts.split(':');
var d_e = de.split('-');
var t_e = te.split(':');
var s_d_s = new Date(d_s[0], d_s[1], d_s[2], t_s[0], t_s[1], t_s[2]);
var s_d_e = new Date(d_e[0], d_e[1], d_e[2], t_e[0], t_e[1], t_e[2]);
if (s_d_s >= s_d_e) {
alert('Неверно указаны даты.');
return;
}
pasport_custom_set(
vdp,
d_s[0] + '.' + d_s[1] + '.' + d_s[2] + ' ' + ts,
d_e[0] + '.' + d_e[1] + '.' + d_e[2] + ' ' + te
);
pasport_fill_label();
pasport_fill_date();
pasport_show_lable();
pasport_show_date();
show_menu();
}