MCUT_Supervisor/N4JS/js/RiserDiagram.js
2025-03-26 10:38:33 +08:00

1251 lines
59 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var tablefloorlist = new Array(0);//排程外顯示Table的樓層
var AllDevicebool = false;//全選設備開關
var Allfloors = new Array(0);//全選樓層用 全部樓層
var Allfloorsbool = false;//全選樓層開關
var devicelist;//形成datatable變數
var weekList = new Array(0);//選擇星期
var selectdeviceList = new Array(0);//選擇的設備
var selectfloorguid;//單選樓層(內)
var schedule_guid = '';//選擇的排程guid
var allcheck = false;//設備全選開關
var alarmjson = JSON.parse(localStorage.getItem('specify_device_number'));
var getdeviceresult;
// var global_specify_device_number;
$(function () {
// $('li.site-menu-item').mouseenter(function (e) {
// e.stopImmediatePropagation();
// $(this).addClass('active open');
// $(this).css('z-index', '10000');
// });
// $('li.site-menu-item').mouseleave(function (e) {
// $(this).removeClass('active open');
// });
//alert(123)
// $('#multiselect').multiselect();
var current_devices = [];
// global_specify_device_number = JSON.parse(localStorage.getItem('specify_device_number'));
send_data = {
building_guid: localStorage.getItem('building_guid'),
main_system_guid: localStorage.getItem('main_system_guid'),
sub_system_guid: localStorage.getItem('sub_system_guid')
}
if (send_data.main_system_guid == 'E6891AC5-C825-4436-A91A-75173F03758B') {
$('.panel-heading').empty();
$('.panel-heading').addClass('d-flex');
$('.panel-heading').addClass('justify-content-end');
$('.panel-heading').append(`<button type="button" class="btn btn-success waves-effect waves-themed" id="myBtn" onclick="openlightschedule()"> 燈控排程 </button>`);
}
$.ajax({
url: baseApiUrl + 'api/GetDevice',
data: send_data,
type: 'POST',
dataType: 'json',
success: function (code, statut) {
// console.log("device", code);
// console.log(selected_subsystem);
getdeviceresult = code;
// 設定Bajascript要訂閱的設備
code.data.forEach(function (item, index) {
item.device.forEach(function (device_item, device_index) {
current_devices.push(device_item)
});
});
myBaja.setPrepareSubscribeDevices(current_devices);
myBaja.setCallBack(myFunc)
var light_html = "";
//抓出第一筆設備來帶代表上方狀態
if (code.data != undefined && code.data != null && code.data.length > 0) {
$("#light-description").empty();
if (code.data[0].device[0].device_system_category_layer3 != "L1" && code.data[0].device[0].device_system_category_layer3 != "L2") {
temp_light = code.data[0].device[0];
if (temp_light.device_normal_text != undefined && temp_light.device_normal_text != null) {
light_html += `<a href="javascript:;" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${temp_light.device_normal_color}"> </a> ${temp_light.device_normal_text} `;
}
if (temp_light.device_close_text != undefined && temp_light.device_close_text != null) {
light_html += `<a href="javascript:;" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${temp_light.device_close_color}"> </a> ${temp_light.device_close_text} `;
}
if (temp_light.device_error_color != undefined && temp_light.device_error_color != null) {
light_html += `<a href="javascript:;" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${temp_light.device_error_color}"> </a> ${temp_light.device_error_text} `;
}
$("#light-description").append(light_html);
}
}
makedeviceRiser();
// reloadDeviceStutsLight();
}
});
//bajascript回傳的function
function myFunc(specify_device_number = [], modify_target_device = {}) {
localStorage.setItem('specify_device_number', JSON.stringify(specify_device_number));
// global_specify_device_number = specify_device_number;
// console.log("[昇位圖]這是我的func的specify_device_number", specify_device_number)
// specify_device_number.forEach(function (item, index) {
// });
if (modify_target_device != undefined && modify_target_device != null && modify_target_device != {}) {
var target_device = current_devices.filter(x => x.device_number == modify_target_device.device_number)[0];
//判斷點位是否為燈號控制的點位
if (modify_target_device.point_name != undefined &&
modify_target_device.point_name != null &&
modify_target_device.point_name != "" &&
(modify_target_device.point_name == target_device.device_normal_point_name ||
modify_target_device.point_name == target_device.device_close_point_name ||
modify_target_device.point_name == target_device.device_error_point_name)) {
//找出該點位的資訊
var temp_specify_device_number = specify_device_number.filter(x => x.device_number == modify_target_device.device_number)[0];
//判斷 欲修改的點位是否為設備異常燈號點位
if (modify_target_device.point_name == target_device.device_error_point_name) {
if (target_device.device_error_point_name == "ER") { //為ER點位的判斷
if (temp_specify_device_number.points[modify_target_device.point_name] == "true") { //目標設備點位發生異常
if (target_device.device_error_flashing == 1) {
$(`#${target_device.device_number}`).addClass("bglink");
} else {
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("max-width", "200px");
$(`#${target_device.device_number}`).css("background-color", target_device.device_error_color);
}
} else { //目標設備點位未發生異常
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("max-width", "200px");
$(`#${target_device.device_number}`).css("background-color", "#FFF");
}
} else {
if (temp_specify_device_number.points[modify_target_device.point_name] == target_device.device_error_point_value) { //目標設備點位發生異常
if (target_device.device_error_flashing == 1) {
$(`#${target_device.device_number}`).addClass("bglink");
} else {
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("max-width", "200px");
$(`#${target_device.device_number}`).css("background-color", target_device.device_error_color);
}
} else { //目標設備點位未發生異常
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("max-width", "200px");
$(`#${target_device.device_number}`).css("background-color", "#FFF");
}
}
// $(".bglink").resetKeyframe();
$(".bglink").playKeyframe({
name: 'bglink123',
duration: "1s",
timingFunction: 'ease',
iterationCount: 'infinite',
});
}
//判斷 欲修改的點位是否為設備燈號點位
if (modify_target_device.point_name == target_device.device_normal_point_name ||
modify_target_device.point_name == target_device.device_close_point_name) {
//判斷 設備正常與關閉點設位定是否相同
if (target_device.device_normal_point_name == target_device.device_close_point_name) { //相同
if (temp_specify_device_number.points[modify_target_device.point_name] == target_device.device_normal_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_normal_color);
} else if (temp_specify_device_number.points[modify_target_device.point_name] == target_device.device_close_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_close_color);
}
} else { //不相同
//判斷正常、異常是否有點位為ER
if ((target_device.device_normal_point_name != undefined && target_device.device_normal_point_name == "ER") ||
(target_device.device_close_point_name != undefined && target_device.device_close_point_name == "ER")) {
if (modify_target_device.point_name == target_device.device_normal_point_name &&
target_device.device_normal_point_name == "ER") {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_normal_color);
} else if (modify_target_device.point_name == target_device.device_close_point_name &&
target_device.device_close_point_name == "ER") {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_close_color);
}
} else { //正常、異常不是為ER點位
if (modify_target_device.point_name == target_device.device_normal_point_name) {
if (temp_specify_device_number.points[modify_target_device.point_name] == target_device.device_normal_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_normal_color);
} else {
$(`#${target_device.device_number}_status`).css("background-color", '');
}
} else if (modify_target_device.point_name == target_device.device_close_point_name) {
if (temp_specify_device_number.points[modify_target_device.point_name] == target_device.device_close_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_close_color);
} else {
$(`#${target_device.device_number}_status`).css("background-color", '');
}
}
}
}
}
}
}
}
function ChangeDeviceStatusLight(specify_device_number = {}, modify_target_device = {}) {
}
});
function makedeviceRiser() {
if (selected_subsystem == undefined) {
return;
}
$('#riser-diagram').empty();
var html = "";
// console.log(selected_subsystem.floors);
selected_subsystem.floors.forEach(floors => {
html += `<div class="row align-items-start mx-0 mb-5">`;
html += `<div class="row">`;
html += `<div class="col-auto floor-header-wrap">
<div class="pr-3"><a href="javascript:void(0);" onclick="GetFloortoDrawing(4, '${floors.floor_guid}', '${floors.full_name}')"><span class="badge badge-secondary fs-lg">${floors.full_name}</span></a></div>
</div>`;
var device_master_arr = [];
var a = getdeviceresult.data.filter(function (n, i) {
if (n.floor_guid === floors.floor_guid) {
html += `<div class="row col d-flex justify-content-start floor-body-wrap">`
n.device.forEach(device => {
if (device.device_master_number != undefined && device.device_master_number != null && (device.device_system_category_layer3 == "L1" || device.device_system_category_layer3 == "L2")) {
if (device_master_arr.findIndex(x => x == device.device_master_number) < 0) {
device_master_arr.push(device.device_master_number);
html += `<div class="card m-1 border device-wrap" style="max-width: 200px;" id="${device.device_master_number}">`;
html += `<div class="card-body p-2">`;
html += `<div class="d-flex">`;
html += `<div class="mb-2">`;
if (device.device_master_icon != null) {
html += `<img src="upload/device_icon/${device.device_master_icon}" class="width-2 height-2 mr-2 float-left" width="45px" height="auto">`;
}
var ifhtml = `./_FloorMap.html?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${n.floor_guid}&device_system_category_layer3=${device.device_system_category_layer3}&device_master=${device.device_master_number}`;
var name_html = "";
if (device.device_master_full_name != null) {
name_html = `${device.device_master_full_name}<br>`;
}
html += `<p class="font-weight-bold mb-2 twoclamp">`;
html += `<a href="javascript:;" class="mb-0 " onclick='openiframe("${ifhtml}", ${device.icon_click_url_width}, ${device.icon_click_url_height})'>
${name_html}
${device.device_master_number}
</a>`;
html += `</p>`;
html += `</div>`;
html += `</div>`;
html += `</div>`;
html += `</div>`;
}
} else {
//沒有master的情況
var erbool = '';
$.keyframe.define([{
name: 'bglink123',
'0%': { 'background-color': device.device_error_color },
'80%': { 'background-color': device.device_error_color },
'81%': { 'background-color': "#FFF" },
'100%': { 'background-color': "#FFF" },
}]);
var ercolor = 0;//0:沒有1:有顏色2:會閃鑠
if (alarmjson == undefined || alarmjson == null) {
alarmjson = [];
}
if (device.device_error_point_name != "" && device.device_error_point_name != null && device.device_error_point_name != undefined) {
if (device.device_error_point_name == "ER") // 有ER時
{
alarmjson.filter(function (n, i) {
if (n.device_number == device.device_number) {
erbool = n.points[device.device_error_point_name];
}
})
if (erbool == "true") {
if (device.device_error_flashing == 1) {
ercolor = 2;
}
else {
ercolor = 1;
}
}
else {
ercolor = 0;
}
}
else // 非ER用其他點位時
{
alarmjson.filter(function (n, i) {
if (n.device_number == device.device_number) {
erbool = n.points[device.device_error_point_name];
}
})
if (erbool == device.device_error_point_value) {
if (device.device_error_flashing == 1) {
ercolor = 2;
}
else {
ercolor = 1;
}
}
else {
ercolor = 0;
}
}
}
if (ercolor == 0) {
html += `<div class="card m-1 border device-wrap" style="max-width: 200px;" id="${device.device_number}">`;
}
else if (ercolor == 1) {
html += `<div class="card m-1 border device-wrap " style="max-width: 200px;
background: ${device.device_error_color};" id="${device.device_number}">`;
}
else {
html += `<div class="card m-1 border device-wrap bglink" style="max-width: 200px;" id="${device.device_number}">`;
}
html += `<div class="card-body p-2">`;
html += `<div class="d-flex">`;
html += `<div class="mb-2">`;
if (device.device_image != null) {
html += `<img src="upload/device_icon/${device.device_image}" class="mr-2 float-left" width="45px" height="auto">`;
}
var ifhtml = `./_FloorMap.html?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${n.floor_guid}&device_system_category_layer3=${device.device_system_category_layer3}&device_number=${device.device_number}`;
html += `<p class="col-auto font-weight-bold mb-2 twoclamp">`;
html += `<a href="javascript:;" class="mb-0 " onclick='openiframe("${ifhtml}", ${device.icon_click_url_width}, ${device.icon_click_url_height})'>
${device.full_name}
<br>
${device.device_number}
</a>`;
html += `</p>`
html += `</div>`;
html += `</div>`;
html += `<div class="d-flex">`;
var normalpoint = device.device_normal_point_name;
var closepoint = device.device_close_point_name;
var pointname = '';
var checker = 0;//nor:1 close:2
if (normalpoint == closepoint) {
pointname = normalpoint;
}
else {
if (normalpoint == "ER" || closepoint == "ER") {
if (normalpoint == "ER") {
checker = 1;
}
else {
checker = 2;
}
pointname = "ER";
}
else {
if (normalpoint != null && normalpoint != "ER") {
pointname = normalpoint;
}
if (closepoint != null && closepoint != "ER") {
pointname = closepoint;
}
}
}
var bool = "";
if (pointname != '') {
alarmjson.filter(function (n, i) {
if (n.device_number == device.device_number) {
bool = n.points[pointname];
}
})
}
var color = "";
if (device.device_close_point_value == bool && bool != "") {
color = device.device_close_color;
}
if (device.device_normal_point_value == bool && bool != "") {
color = device.device_normal_color;
}
if (checker == 1) {
color = device.device_normal_color;
}
else if (checker == 2) {
color = device.device_close_color;
}
html += `<p class="mb-0 mt-2" style="clear: both">`;
html += `<a href="javascript:;" id="${device.device_number}_status" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${color}">  </a>`;
if (device.icon_click & 1 > 0) {
// html += `<div class="col d-flex justify-content-end align-items-center custom-control custom-switch">
// <input type="checkbox" class="custom-control-input" id="${device.device_number}_check">
// <label class="custom-control-label" for="${device.device_number}_check"></label>
// </div>`;
if (device.deviceURL != null) {
html += `<a href="javascript:;" class=" ml-2 mb-0 " onclick="openiframe('${device.deviceURL}', ${device.icon_click_url_width}, ${device.icon_click_url_height}, 1)"> 詳細資料</a>`;
}
}
html += `</p>`;
html += `</div>`;
html += `</div>`;
html += `</div>`;
}
})
html += `</div>`;
}
});
html += `</div>`;
html += `</div>`;
});
$('#riser-diagram').append(html);
$(".bglink").playKeyframe({
name: 'bglink123',
duration: "1s",
timingFunction: 'ease',
iterationCount: 'infinite',
});
}
function openiframe(iframeurl, width = 0, height = 0, mode = 0) {
if (mode == 0) {
$('#iframemodal > .modal-content').css("width", "80%");
$('#iframemodal > .modal-content').css("height", "85vh");
}
else {
if (width != undefined && width != null && width > 0) {
$('#iframemodal > .modal-content').css("width", width + "px");
} else {
$('#iframemodal > .modal-content').css("width", "80%");
}
if (height != undefined && height != null && height > 0) {
$('#iframemodal > .modal-content').css("height", height + "px");
} else {
$('#iframemodal > .modal-content').css("height", "85vh");
}
}
$('#iframemodal').find('.modal-body').empty();
var html = `<iframe src="${iframeurl}" width="100%" height="100%"></iframe>`;
$('#iframemodal').find('.modal-body').append(html);
$('#iframemodal').show();
}
function Turndevice() {
$('#device_onclick').modal('show');
}
//燈控排程開啟
function openlightschedule() {
//console.log(selected_subsystem);
$('#lightschedule').show();
$('#floorlist').empty();
$('#addschedulefloorlist').empty();
var floorhtml = '<button type="button" class="btn btn-secondary waves-effect waves-themed mb-2 mr-2" id="allbtn" onclick="SelectAllFloor()">全選</button>';
var addfloorhtml = '';
Allfloors = new Array(0);
$.each(selected_subsystem.floors, function (ind, val) {
floorhtml += `<button type="button" class="btn btn-outline-success waves-effect waves-themed mb-2 mr-2" id="btn_` + val.floor_guid + `" onclick="SelectTablefloor('` + val.floor_guid + `',this)">` + val.full_name + `</button>`;
if (ind == 0) {
addfloorhtml += `<button type="button" class="btn btn-success waves-effect waves-themed mb-2 mr-2" id="bt_` + val.floor_guid + `" onclick="SelectDevicefloor('` + val.floor_guid + `',this)">` + val.full_name + `</button>`
}
else {
addfloorhtml += `<button type="button" class="btn btn-secondary waves-effect waves-themed mb-2 mr-2" id="bt_` + val.floor_guid + `" onclick="SelectDevicefloor('` + val.floor_guid + `',this)">` + val.full_name + `</button>`
}
Allfloors.push(val.floor_guid);
});
$('#floorlist').append(floorhtml);
$('#addschedulefloorlist').append(addfloorhtml);
$('#allbtn').click();
$('#addschedulefloorlist').find('.btn-success').click();
}
//外層選擇樓層
function SelectTablefloor(guid, e) {
if ($(e).hasClass("btn-outline-success")) {
$(e).removeClass("btn-outline-success").addClass("btn-success");
tablefloorlist.push(guid);
} else if ($(e).hasClass("btn-success")) {
$(e).removeClass("btn-success").addClass("btn-outline-success");
var a = tablefloorlist.filter(function (n, i) {
if (n === guid) {
tablefloorlist.splice(i, 1);
}
});
}
MakeScheduleTable()
//console.log(tablefloorlist);
}
function MakeScheduleTable() {
$('#ScheduleTablediv').empty();
var html = `
<table class="table table-bordered m-0 text-center" id="ScheduleTable">
<thead class="thead-themed">
<tr>
<th>序號</th>
<th>排程名稱</th>
<th>設備數量</th>
<th>排程設定</th>
<th>狀態</th>
<th>功能</th>
</tr>
</thead>
<tbody>
</tbody>
</table>`;
$('#ScheduleTablediv').append(html);
var send_data =
{
Floors: tablefloorlist,
};
var url = baseApiUrl + "api/LightSchedule/ScheduleTable";
$.ajax({
method: "post",
url: url,
data: send_data,
async: false,
dataType: 'json',
success: function (rel) {
console.log(rel);
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
html = '';
rel.data.forEach(function (element, i) {
html += '<tr>';
html += '<td>' + Number(i + 1) + '</td>';
html += '<td>' + element.full_name + '</td>';
html += '<td>' + element.devicecount + '</td>';
var talk = '';
switch (element.cycle) {
case 0: { talk += "僅一次</br>"; break; }
case 1: { talk += "每周</br>"; break; }
}
var week = element.week.split(",")
week.sort(function (a, b) {
return Number(a) - Number(b);
});
week.forEach(function (elemente, i) {
switch (elemente) {
case '0': { talk += "日"; break; }
case '1': { talk += "一"; break; }
case '2': { talk += "二"; break; }
case '3': { talk += "三"; break; }
case '4': { talk += "四"; break; }
case '5': { talk += "五"; break; }
case '6': { talk += "六"; break; }
}
if (i != week.length - 1) {
talk += "、";
} else {
talk += "</br>";
}
});
talk += element.start_time + " - ";
talk += element.end_time;
html += '<td>' + talk + '</td>';
if (element.status == 0) {
html += '<td>' + "停用" + '</td>';
}
else {
html += '<td>' + "啟用" + '</td>';
}
html += '<td>' + `<a href="javascript:;" class="btn btn-success" onclick="Callapi('${element.light_schedule_guid}')" >觸發執行</a>
<button type="button" class="btn btn-info waves-effect waves-themed" onclick="GetOneschedule('`+ element.light_schedule_guid + `')">
修改 </button>
<button type="button" class="btn btn-danger waves-effect waves-themed" onclick="DeleteSchedule('`+ element.light_schedule_guid + `')"> 刪除 </button>` + '</td>';
html += '</tr>'
})
$('#ScheduleTable').find('tbody').append(html);
new simpleDatatables.DataTable('#ScheduleTable', {
searchable: false,
perPage: 10,
});
$('#ScheduleTable').parent().parent().find('.dataTable-top').empty();
}
}
})
}
function Callapi(guid) {
var url = baseApiUrl + "api/LightSchedule/SendAPI";
var send_data =
{
guid: guid
};
$.ajax({
method: "post",
url: url,
data: send_data,
async: false,
dataType: 'json',
success: function (rel) {
if (rel.code != "0000") {
toast_error("觸發失敗");
}
else {
toast_ok("已觸發");
}
}
});
}
function GetOneschedule(guid) {
resetSchedule();
var send_data =
{
schedule_guid: guid
};
var url = baseApiUrl + "api/LightSchedule/GetOneschedule";
AllDevicebool = false;
$.ajax({
method: "post",
url: url,
data: send_data,
async: false,
dataType: 'json',
success: function (rel) {
console.log(rel);
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
schedule_guid = rel.data.light_schedule_guid;
$('#bt_' + rel.data.floor_guid).click();
$('#ScheduleFullName').val(rel.data.full_name);
var weekbacklist = rel.data.week.split(',');
weekbacklist.forEach(function (elemente, i) {
switch (elemente) {
case '0': { $('#weekselect').find('.bt0').click(); break; }
case '1': { $('#weekselect').find('.bt1').click(); break; }
case '2': { $('#weekselect').find('.bt2').click(); break; }
case '3': { $('#weekselect').find('.bt3').click(); break; }
case '4': { $('#weekselect').find('.bt4').click(); break; }
case '5': { $('#weekselect').find('.bt5').click(); break; }
case '6': { $('#weekselect').find('.bt6').click(); break; }
}
});
$("input[name*='cycle'][value='" + rel.data.cycle + "']").prop("checked", true);
$("input[name*='status'][value='" + rel.data.status + "']").prop("checked", true);
$('#StartTime').val(rel.data.start_time);
$('#EndTime').val(rel.data.end_time);
$('#ScheduleFullName').val(rel.data.full_name);
$('#addschedulefloorlist').find('.btn').attr('disabled', true);
$('#addlightschedule').show();
}
}
})
}
function DeleteSchedule(guid) {
Swal.fire(
{
title: "刪除",
text: "你確定是否刪除此筆資料?",
type: "warning",
icon: 'warning',
showCancelButton: true,
confirmButtonText: "是",
cancelButtonText: "否"
}).then(function (result) {
if (result.value) {
var send_data =
{
schedule_guid: guid
};
var url = baseApiUrl + "api/LightSchedule/DeleteSchedule";
$.ajax({
method: "post",
url: url,
data: send_data,
async: false,
dataType: 'json',
success: function (rel) {
console.log(rel);
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
toast_ok("刪除成功");
MakeScheduleTable();
}
}
})
}
});
}
function closemodal(modalid) {
//toast_ok("關閉");
Allfloorsbool = false;
$('#' + modalid).hide();
}
//新增排程
function Addschedule() {
resetSchedule();
schedule_guid = '';
$('#addschedulefloorlist').find('.btn').first().click();
$('#addlightschedule').show();
}
//選擇設備樓層
function SelectDevicefloor(floorguid, e) {
selectfloorguid = floorguid;
$(e).parent().find('.btn-success').removeClass('btn-success').addClass('btn-secondary');
$(e).removeClass('btn-secondary').addClass('btn-success');
var send_data =
{
building_guid: localStorage.getItem('building_guid'),
sub_system_guid: localStorage.getItem('sub_system_guid'),
floor_guid: floorguid,
schedule_guid: schedule_guid
};
//$('#devicetable').find('tbody').empty();
var url = baseApiUrl + "api/LightSchedule/GetLightDevice";
$.ajax({
method: "post",
url: url,
data: send_data,
async: false,
dataType: 'json',
success: function (rel) {
console.log(rel);
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
devicelist = rel.data;
AllDevicebool = false;
MakeDeviceTable();
}
}
})
}
//生成設備Table
function MakeDeviceTable() {
$('#devicetablediv').empty();
var html = `<button type="button" class="btn btn-secondary waves-effect waves-themed mb-2" onclick="SelectAllDevice()">全選設備</button>
<table class="table table-bordered m-0 text-center" id="devicetable">
<thead class="thead-themed">
<tr>
<th>選擇</th>
<th>設備編號</th>
<th>設備名稱</th>
</tr>
</thead>
<tbody>
</tbody>
</table>`;
$('#devicetablediv').append(html);
$('#devicetable').find('tbody').empty();
selectdeviceList = [];
var html = '';
devicelist.forEach(function (element, i) {
html += '<tr>';
if (allcheck) {
if (AllDevicebool) {
html += '<td>' + '<input type="checkbox" onclick="SelectDevice(this)" value=\'' + element.device_guid + '\' checked>' + '</td>';
selectdeviceList.push(element.device_guid);
} else {
html += '<td>' + '<input type="checkbox" onclick="SelectDevice(this)" value=\'' + element.device_guid + '\' >' + '</td>';
selectdeviceList = [];
}
}
else {
if (element.check == 0) {
html += '<td>' + '<input type="checkbox" onclick="SelectDevice(this)" value=\'' + element.device_guid + '\'>' + '</td>';
}
else {
html += '<td>' + '<input type="checkbox" onclick="SelectDevice(this)" value=\'' + element.device_guid + '\' checked>' + '</td>';
selectdeviceList.push(element.device_guid);
}
}
html += '<td>' + element.device_number + '</td>';
html += '<td>' + element.full_name + '</td>';
html += '</tr>'
})
allcheck = false;
$('#devicetable').find('tbody').append(html);
new simpleDatatables.DataTable('#devicetable', {
searchable: false,
perPage: 10,
});
$('#devicetable').parent().parent().find('.dataTable-top').empty();
}
//設備全選
function SelectAllDevice() {
allcheck = true;
if (AllDevicebool) {
AllDevicebool = false;
}
else {
AllDevicebool = true;
}
MakeDeviceTable();
}
function SelectAllFloor() {
if (Allfloorsbool) {
$('#floorlist').find('.btn-success').removeClass('btn-success').addClass('btn-outline-success');
tablefloorlist = [];
Allfloorsbool = false;
}
else {
tablefloorlist = Allfloors
$('#floorlist').find('.btn-outline-success').removeClass('btn-outline-success').addClass('btn-success');
Allfloorsbool = true;
}
MakeScheduleTable();
}
//選擇星期
function SelectWeek(week, e) {
if ($(e).hasClass("btn-outline-success")) {
$(e).removeClass("btn-outline-success").addClass("btn-success");
weekList.push(week);
} else if ($(e).hasClass("btn-success")) {
$(e).removeClass("btn-success").addClass("btn-outline-success");
var a = weekList.filter(function (n, i) {
if (n === week) {
weekList.splice(i, 1);
}
});
}
//console.log(weekList);
}
//勾選設備
function SelectDevice(e) {
if ($(e).attr('checked')) {
$(e).removeAttr('checked');
selectdeviceList.filter(function (n, i) {
if (n === $(e).val()) {
selectdeviceList.splice(i, 1);
}
});
}
else {
$(e).attr("checked", true);
selectdeviceList.push($(e).val());
}
//console.log(selectdeviceList);
}
function resetSchedule() {
$('#addschedulefloorlist').find('.btn').attr('disabled', false);
$('#ScheduleFullName').val('');
weekList = new Array(0);
$('#weekselect').find('.btn-success').removeClass('btn-success').addClass('btn-outline-success');
$("input[name*='cycle'][value='0']").prop("checked", true);
$("input[name*='status'][value='0']").prop("checked", true);
$('#StartTime').val('');
$('#EndTime').val('');
}
function SaveSchedule() {
var alerthtml = "";
if ($('#ScheduleFullName').val() == "") {
alerthtml += '沒有填寫名稱<br\>';
}
if (weekList.length == 0) {
alerthtml += '沒選擇週期<br\>';
}
if ($('#StartTime').val() == "") {
alerthtml += '沒選擇開始時間<br\>';
}
if ($('#EndTime').val() == "") {
alerthtml += '沒選擇結束時間<br\>';
}
if (selectdeviceList.length == 0) {
alerthtml += '沒選擇設備<br\>';
}
if (alerthtml != "") {
Swal.fire(
{
title: "儲存失敗",
icon: 'warning',
html: "原因:<br\>" + alerthtml,
});
return;
}
var send_data = {
light_schedule_guid: schedule_guid,
full_name: $('#ScheduleFullName').val(),
week: weekList.join(),
cycle: $('input[name="cycle"]:checked').val(),
floor_guid: selectfloorguid,
start_time: $('#StartTime').val(),
end_time: $('#EndTime').val(),
status: $('input[name="status"]:checked').val(),
devicelist: selectdeviceList
}
var url = baseApiUrl + "api/LightSchedule/SaveSchedule";
$.ajax({
method: "post",
url: url,
data: send_data,
async: false,
dataType: 'json',
success: function (rel) {
console.log(rel);
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
toast_ok("儲存成功");
$('#addlightschedule').hide();
MakeScheduleTable();
}
}
})
}
function initLoad() {
send_data = {
building_guid: localStorage.getItem('building_guid'),
main_system_guid: localStorage.getItem('main_system_guid'),
sub_system_guid: localStorage.getItem('sub_system_guid')
}
console.log("我要來抓設備資料囉");
var init_start = new Date(Date.now());
$.ajax({
url: baseApiUrl + 'api/GetDevice',
data: send_data,
type: 'POST',
dataType: 'json',
success: function (code, statut) {
console.log("取得設備資訊-花費時間", (new Date(Date.now()).getTime() - init_start.getTime()) / 1000 + "sec");
getdeviceresult = code;
code.data.forEach(function (item, index) {
item.device.forEach(function (device_item, device_index) {
current_devices.push(device_item)
});
});
// myBaja.setPrepareSubscribeDevices(current_devices);
// myBaja.setCallBack(myFunc)
var light_html = "";
//抓出第一筆設備來帶代表上方狀態
if (code.data != undefined && code.data != null && code.data.length > 0) {
$("#light-description").empty();
if (code.data[0].device[0].device_system_category_layer3 != "L1" && code.data[0].device[0].device_system_category_layer3 != "L2") {
temp_light = code.data[0].device[0];
if (temp_light.device_normal_text != undefined && temp_light.device_normal_text != null) {
light_html += `<a href="javascript:;" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${temp_light.device_normal_color}"> </a> ${temp_light.device_normal_text} `;
}
if (temp_light.device_close_text != undefined && temp_light.device_close_text != null) {
light_html += `<a href="javascript:;" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${temp_light.device_close_color}"> </a> ${temp_light.device_close_text} `;
}
if (temp_light.device_error_text != undefined && temp_light.device_error_text != null) {
light_html += `<a href="javascript:;" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${temp_light.device_error_color}"> </a> ${temp_light.device_error_text} `;
}
$.keyframe.define([{
name: 'bglinkErrorColor',
'0%': { 'background-color': temp_light.device_error_color },
'80%': { 'background-color': temp_light.device_error_color },
'81%': { 'background-color': "#FFF" },
'100%': { 'background-color': "#FFF" },
}]);
$("#light-description").append(light_html);
}
}
var render_start = new Date(Date.now());
makedeviceRiser();
console.log("Render昇位圖-花費時間", (new Date(Date.now()).getTime() - render_start.getTime()) / 1000 + "sec");
console.log("準備進入執行BQL訂閱Function");
ordPath = {
"building_tag": localStorage.getItem('device_building_tag'),
"system_tag": localStorage.getItem('device_system_tag')
}
myBaja.setSubscribeDevicesByBql(ordPath);
myBaja.setSubscribeDevicesCallBack(subscribeCallBack);
}
});
function subscribeCallBack(change_device) {
if (change_device != undefined && change_device != null) {
var target_device = current_devices.filter(x => x.device_number == change_device.device_number)[0];
//判斷點位是否為燈號控制的點位
if (change_device.point_name != undefined &&
change_device.point_name != null &&
change_device.point_name != "" &&
target_device != undefined &&
(change_device.point_name == target_device.device_normal_point_name ||
change_device.point_name == target_device.device_close_point_name ||
change_device.point_name == target_device.device_error_point_name)) {
//判斷 欲修改的點位是否為設備異常燈號點位
if (change_device.point_name == target_device.device_error_point_name) {
if (target_device.device_error_point_name == "ER") { //為ER點位的判斷
if (change_device.value == "true") { //目標設備點位發生異常
if (target_device.device_error_flashing == 1) {
$(`#${target_device.device_number}`).addClass("bglink");
} else {
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("width", "300px");
$(`#${target_device.device_number}`).css("background-color", target_device.device_error_color);
}
} else { //目標設備點位未發生異常
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("width", "300px");
$(`#${target_device.device_number}`).css("background-color", "#FFF");
}
} else {
if (change_device.value == target_device.device_error_point_value) { //目標設備點位發生異常
if (target_device.device_error_flashing == 1) {
$(`#${target_device.device_number}`).addClass("bglink");
} else {
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("width", "300px");
$(`#${target_device.device_number}`).css("background-color", target_device.device_error_color);
}
} else { //目標設備點位未發生異常
$(`#${target_device.device_number}`).removeClass("bglink").removeAttr("style").css("width", "300px");
$(`#${target_device.device_number}`).css("background-color", "#FFF");
}
}
$(".bglink").playKeyframe({
name: 'bglinkErrorColor',
duration: "1s",
timingFunction: 'ease',
iterationCount: 'infinite',
});
}
//判斷 欲修改的點位是否為設備燈號點位
if (change_device.point_name == target_device.device_normal_point_name ||
change_device.point_name == target_device.device_close_point_name) {
//判斷 設備正常與關閉點位設定是否相同
if (target_device.device_normal_point_name == target_device.device_close_point_name) { //相同
if (change_device.value == target_device.device_normal_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_normal_color);
} else if (change_device.value == target_device.device_close_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_close_color);
}
} else { //不相同
//判斷正常或關閉是否有點位為ER
if ((target_device.device_normal_point_name != undefined && target_device.device_normal_point_name == "ER") ||
(target_device.device_close_point_name != undefined && target_device.device_close_point_name == "ER")) {
if (change_device.point_name == target_device.device_normal_point_name &&
target_device.device_normal_point_name == "ER") {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_normal_color);
} else if (change_device.point_name == target_device.device_close_point_name &&
target_device.device_close_point_name == "ER") {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_close_color);
}
} else { //正常、異常不是為ER點位
if (change_device.point_name == target_device.device_normal_point_name) {
if (change_device.value == target_device.device_normal_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_normal_color);
} else {
$(`#${target_device.device_number}_status`).css("background-color", '');
}
} else if (modify_target_device.point_name == target_device.device_close_point_name) {
if (change_device.value == target_device.device_close_point_value) {
$(`#${target_device.device_number}_status`).css("background-color", target_device.device_close_color);
} else {
$(`#${target_device.device_number}_status`).css("background-color", '');
}
}
}
}
}
}
else if (
target_device != undefined &&
change_device.point_name == target_device.points) {
$(`#${target_device.device_number}_${target_device.points}`).html(change_device.value);
}
}
}
}
//繪製昇位圖內容
function makedeviceRiser() {
if (selected_subsystem == undefined) {
return;
}
$('#riser-diagram').empty();
selected_subsystem.floors.forEach(floor => {
var html = "";
html += `<div class="row align-items-start mx-0 mb-5">`;
html += `<div class="row">`;
//因改為跳出新視窗所以註解
// html += `<div class="col-auto floor-header-wrap">
// <div class="pr-3"><a href="javascript:void(0);" onclick="GetFloortoDrawing(4, '${floor.floor_guid}', '${floor.full_name}')"><span class="badge badge-secondary fs-lg">${floor.full_name}</span></a></div>
// </div>`;
var floorparam = `?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${floor.floor_guid}`;
html += `<div class="col-auto floor-header-wrap">
<div class="pr-3"><a href="javascript:void(0);" onclick="CreateOrUpdateTab('${floorparam}')"><span class="badge badge-secondary fs-lg">${floor.full_name}</span></a></div>
</div>`;
var device_master_arr = [];
var select_floor_device = getdeviceresult.data.find(x => x.floor_guid == floor.floor_guid);
html += `<div class="row col d-flex justify-content-start floor-body-wrap">`;
select_floor_device.device.forEach(device => {
if (device.device_master_number != undefined && device.device_master_number != null && (device.device_system_category_layer3 == "L1" || device.device_system_category_layer3 == "L2")) {
if (device_master_arr.findIndex(x => x == device.device_master_number) < 0) {
device_master_arr.push(device.device_master_number);
html += `<div class="card m-1 border device-wrap" style="width: 300px;" id="${device.device_master_number}">`;
html += `<div class="card-body p-2">`;
html += `<div class="d-flex">`;
html += `<div class="mb-2">`;
if (device.device_master_icon != null) {
html += `<img src="upload/device_icon/${device.device_master_icon}" class="width-2 height-2 mr-2 float-left" width="45px" height="auto">`;
}
var ifhtml = `./_FloorMap.html?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${select_floor_device.floor_guid}&device_system_category_layer3=${device.device_system_category_layer3}&device_master=${device.device_master_number}`;
var name_html = "";
if (device.device_master_full_name != null) {
name_html = `${device.device_master_full_name}<br>`;
}
html += `<p class="font-weight-bold mb-2 twoclamp">`;
// html += `<a href="javascript:void(0);" class="mb-0 " onclick='openiframe("${ifhtml}", ${device.icon_click_url_width}, ${device.icon_click_url_height})'>
// ${name_html}
// ${device.device_master_number}
// </a>`;
var param = `?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${select_floor_device.floor_guid}&device_system_category_layer3=${device.device_system_category_layer3}&device_master=${device.device_master_number}`
html += `<a href="javascript:void(0);" class="mb-0 " onclick='CreateOrUpdateTab("${param}")'>
${name_html}
${device.device_master_number}
</a>`;
html += `</p>`;
if (OpenChange) {
html += `<button type="button" class=" btn btn-success waves-effect waves-themed " onclick="ChangeName('${device.device_master_number}','${device.device_master_full_name}',1)"><i class="fal fa-pencil"></i>更改名稱</button>`;
}
html += `</div>`;
html += `</div>`;
html += `</div>`;
html += `</div>`;
}
} else {
html += `<div class="card m-1 border device-wrap" style="width: 300px;" id="${device.device_number}">`;
html += `<div class="card-body p-2">`;
html += `<div class="d-flex">`;
html += `<div class="mb-2">`;
if (device.device_image != null) {
html += `<img src="upload/device_icon/${device.device_image}" class="mr-2 float-left" width="45px" height="auto">`;
}
var ifhtml = `./_FloorMap.html?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${select_floor_device.floor_guid}&device_system_category_layer3=${device.device_system_category_layer3}&device_number=${device.device_number}`;
if (device.device_system_category_layer3 == 'C') {
ifhtml += "&show_cctv=1"
}
html += `<p class="col-auto font-weight-bold mb-2 twoclamp">`;
// html += `<a href="javascript:;" class="mb-0 " onclick='openiframe("${ifhtml}", ${device.icon_click_url_width}, ${device.icon_click_url_height})'>
// ${device.full_name}
// <br>
// ${device.device_number}
// </a>`;
var param = `?building_guid=${localStorage.getItem('building_guid')}&main_system_guid=${localStorage.getItem('main_system_guid')}&sub_system_guid=${localStorage.getItem('sub_system_guid')}&floor_guid=${select_floor_device.floor_guid}&device_system_category_layer3=${device.device_system_category_layer3}&device_master=${device.device_master_number}`
if (device.device_system_category_layer3 == 'C') {
param += "&show_cctv=1"
}
html += `<a href="javascript:void(0);" class="mb-0 " onclick='CreateOrUpdateTab("${param}")'>
${device.full_name}
<br>
${device.device_number}
</a>`;
html += `</p>`;
html += `</p>`;
html += `</div>`;
html += `</div>`;
html += `<div class="d-flex">`;
html += `<p class="mb-0 mt-2" style="clear: both">`;
html += `<a href="javascript:;" id="${device.device_number}_status" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed">  </a>&nbsp;&nbsp;`;
// html += `<a href="javascript:;" id="${device.device_number}_status" class="btn btn-xs btn-icon rounded-circle waves-effect waves-themed" style="background-color:${color}">  </a>`;
if (device.points != undefined && device.points != null) {
html += `<span>${device.point_name}</span> : <span id="${device.device_number}_${device.points}"></span>`
}
if (device.icon_click & 1 > 0) {
if (device.deviceURL != null) {
html += `<a href="javascript:;" class=" ml-2 mb-0 " onclick="openiframe('${device.deviceURL}', ${device.icon_click_url_width}, ${device.icon_click_url_height}, 1)"> 詳細資料</a>`;
}
}
if (OpenChange) {
html += `<button type="button" class=" btn btn-success waves-effect waves-themed " onclick="ChangeName('${device.device_number}','${device.full_name}',0)"><i class="fal fa-pencil"></i>更改名稱</button>`;
}
html += `</p>`;
html += `</div>`;
html += `</div>`;
html += `</div>`;
}
})
html += `</div>`;
html += `</div>`;
html += `</div>`;
$('#riser-diagram').append(html);
});
}