FIC_Solar/SolarPower/Views/AnalysisStationInfo/Index.cshtml
2021-07-27 20:11:56 +08:00

515 lines
27 KiB
Plaintext

@{
ViewData["MainNum"] = "3";
ViewData["SubNum"] = "2";
ViewData["Title"] = "電站交叉分析";
}
<div class="container-fluid">
<div class="row flex-nowrap wrapper">
<div class="col-md-2 col-1 pl-0 pr-0 collapse width border-right sidebar vh-100">
<div class="list-group border-0 card text-center text-md-left" id="sidebar">
<div class="border bg-light rounded-top">
<div class="form-group p-2 m-0 rounded-top">
<input type="text" class="form-control form-control-lg shadow-inset-2 m-0" id="js_list_accordion_filter" placeholder="">
</div>
<div id="js_list_accordion" class="accordion accordion-hover accordion-clean js-list-filter">
</div>
<span class="filter-message js-filter-message"></span>
</div>
</div>
</div>
<div class="col-auto px-0">
<a href="javascript:;" data-target=".sidebar" data-toggle="collapse" class="btn btn-default btn-xs btn-icon waves-effect waves-themed" style="border-radius: 0;"><i onclick="myfunc(this)" class="fal fa-angle-right fa-lg py-3"></i></a>
</div>
<main class="col px-5 pl-md-2 main">
<ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">交叉分析</a></li>
<li class="breadcrumb-item active">@ViewData["Title"]</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>
<div class="subheader">
<h1 class="subheader-title">
<i class="subheader-icon fal fa-crosshairs"></i> @ViewData["Title"]
</h1>
</div>
<div class="row">
<div class="col-xl-12">
<div id="panel-5" class="panel">
<div class="panel-container show">
<div class="panel-content">
<div class="mb-5 d-flex justify-content-start">
<div class="pr-3">
<div class="btn-group btn-group-md">
<button type="button" class="btn btn-success waves-effect waves-themed btn-change-searchType" id="Group0" onclick="changeType(0,this)">日</button>
<button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-searchType" id="Group1" onclick="changeType(1,this)">日區間</button>
<button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-searchType" id="Group2" onclick="changeType(2,this)">月</button>
<button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-searchType" id="Group3" onclick="changeType(3,this)">年</button>
</div>
</div>
<div class="pr-3" id="quickSearchOption">
<button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-quickSearch1" onclick="quickSearch(0)">今天</button>
<button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-quickSearch2" onclick="quickSearch(1)">昨天</button>
</div>
<div class="pr-3">
<div class="btn-group" id="js-demo-nesting" role="group" aria-label="Button group with nested dropdown">
<input type="date" class="form-control" id="DateGet" />
</div>
<div class="btn-group" id="DateGettextdiv" role="group" aria-label="Button group with nested dropdown">
<input type="text" class="form-control" id="DateGettext" />
</div>
</div>
<div class="pr-3">
<button type="button" class="btn btn-secondary waves-effect waves-themed">查詢</button>
</div>
</div>
<div class="mb-5">
<div class="card p-3 w-100">
<div class="row mb-5 d-flex justify-content-end">
<div class="pr-3">
<div class="btn-group" id="js-demo-nesting" role="group" aria-label="Button group with nested dropdown">
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">選擇比較欄位 </button>
<div class="dropdown-menu">
<a class="dropdown-item" href="javascript:void(0)">2021 四月</a>
<a class="dropdown-item" href="javascript:void(0)">2021 三月</a>
</div>
</div>
</div>
</div>
<div class="pr-3">
<div class="btn-group" id="js-demo-nesting" role="group" aria-label="Button group with nested dropdown">
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">下載 </button>
<div class="dropdown-menu">
<a class="dropdown-item" href="javascript:void(0)">2021 四月</a>
<a class="dropdown-item" href="javascript:void(0)">2021 三月</a>
</div>
</div>
</div>
</div>
<div class="pr-3">
<button type="button" class="btn btn-secondary waves-effect waves-themed"><i class="fal fa-expand fs-md"></i></button>
</div>
</div>
<p>放圖表</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
@section Scripts{
<script>
var searchType = 0;//搜尋條件(日,日區間,月,年)
var datepicker;
var timerange;//選取時間
var selected_device = [];
var PYR_select_col = [{ name: "日照度", type: "PYR", value: "Irradiance" }];
var ETR_select_col = [{ name: "環境溫度計", type: "ETR", value: "Temperature" }];
var EMM_select_col = [{ name: "濕度", type: "EMM", value: "Humidity" }];
var VAN_select_col = [{ name: "風速", type: "VAN", value: "Vane" }];
var FOM_select_col = [{ name: "落塵%", type: "FOM", value: "Dust" }];
var all_selected_compare_col = [];
var checked_compare_col = [];
$(function () {
//#region 預設初始值
$('#DateGet').val(new Date().toISOString().substring(0, 10));
document.getElementById("DateGettextdiv").style.display = "none";//隱藏
$('#DateGet').attr('style', 'width:205px');
$('#DateGettext').attr('style', 'width:205px');
timerange = $('#DateGet').val();
//#endregion
//#region 載入左邊選單列表
GetPowerStationCollapse("");
//#endregion
})
function myfunc(div) {
var className = div.getAttribute("class");
if (className == "fal fa-angle-left fa-lg py-3") {
div.className = "fal fa-angle-right fa-lg py-3";
}
else {
div.className = "fal fa-angle-left fa-lg py-3";
}
}
//#region 更換搜尋條件(日,日區間,月,年)
function changeType(type, e) {
searchType = type;
if ($(".btn-change-searchType").hasClass("btn-success")) {
$(".btn-change-searchType").removeClass("btn-success").addClass("btn-secondary");
}
document.getElementById("DateGettextdiv").style.display = "none";//隱藏
document.getElementById("DateGet").style.display = "";//隱藏
$(e).removeClass("btn-secondary").addClass("btn-success");
switch (type) {
case 0: $('#DateGet').prop({ 'type': 'date' });
$(".btn-change-quickSearch1").html("今天");
$(".btn-change-quickSearch2").html("昨天");
var today = new Date().toISOString().substring(0, 10);
$('#DateGet').val(today);
break;
case 1:
//#region Date-Picker
datepicker = $('#DateGettext').daterangepicker({
autoUpdateInput: false,
locale: { format: 'YYYY/MM/DD' },
opens: 'left'
});
$('#DateGettext').on('apply.daterangepicker', function (ev, picker) {
$(this).val(picker.startDate.format('YYYY/MM/DD') + ' - ' + picker.endDate.format('YYYY/MM/DD'));
$(this).trigger('change');
});
$('#DateGettext').on('cancel.daterangepicker', function (ev, picker) {
$(this).val('');
$(this).trigger('change');
});
//#endregion
$(".btn-change-quickSearch1").html("近7天");
$(".btn-change-quickSearch2").html("近30天");
//#region 預設近7天
var today = new Date();
var dateLimit = new Date(new Date().setDate(today.getDate() - 7));
var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/");
var dateLimit_format = dateLimit.toISOString().slice(0, 10).replace(/-/g, "/");
datepicker.data('daterangepicker').setStartDate(dateLimit_format);
datepicker.data('daterangepicker').setEndDate(today_format);
document.getElementById("DateGettextdiv").style.display = "";//隱藏
document.getElementById("DateGet").style.display = "none";//隱藏
//#endregion
$('#DateGettext').val(dateLimit_format + ' - ' + today_format);
break;
case 2: $('#DateGet').prop({ 'type': 'month' });
$(".btn-change-quickSearch1").html("本月");
$(".btn-change-quickSearch2").html("上個月");
var now_month = new Date().toISOString().substring(0, 7);
$('#DateGet').val(now_month);
break;
case 3:
$(".btn-change-quickSearch1").html("今年");
$(".btn-change-quickSearch2").html("去年");
var now_year = new Date().toISOString().substring(0, 4);
$('#DateGet').prop({ 'type': 'number', 'min': 1900, 'max': now_year, 'step': 1 });
$('#DateGet').val(now_year);
break;
}
if (type == 1) {
timerange = $('#DateGettext').val();
}
else {
timerange = $('#DateGet').val();
}
}
//#endregion
//#region 快速填入條件(EX.今昨天)
function quickSearch(day) {
switch (searchType) {
case 0:
if (day == 0) {
var today = new Date().toISOString().substring(0, 10);
$('#DateGet').val(today).trigger('change');
} else {
var dateLimit = new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().substring(0, 10);
$('#DateGet').val(dateLimit).trigger('change');
}
break;
case 1:
if (day == 0) {
//#region 預設近7天
var today = new Date();
var dateLimit = new Date(new Date().setDate(today.getDate() - 7));
var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/");
var dateLimit_format = dateLimit.toISOString().slice(0, 10).replace(/-/g, "/");
datepicker.data('daterangepicker').setStartDate(dateLimit_format);
datepicker.data('daterangepicker').setEndDate(today_format);
//#endregion
$('#DateGettext').val(dateLimit_format + ' - ' + today_format).trigger('change');
} else {
//#region 預設近30天
var today = new Date();
var dateLimit = new Date(new Date().setDate(today.getDate() - 30));
var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/");
var dateLimit_format = dateLimit.toISOString().slice(0, 10).replace(/-/g, "/");
datepicker.data('daterangepicker').setStartDate(dateLimit_format);
datepicker.data('daterangepicker').setEndDate(today_format);
//#endregion
$('#DateGettext').val(dateLimit_format + ' - ' + today_format).trigger('change');
}
break;
case 2:
if (day == 0) {
var now_month = new Date().toISOString().substring(0, 7);
$('#DateGet').val(now_month).trigger('change');
} else {
var dateLimit = new Date(new Date().setMonth(new Date().getMonth() - 1)).toISOString().substring(0, 7);
$('#DateGet').val(dateLimit).trigger('change');
}
break;
case 3:
if (day == 0) {
var now_year = new Date().toISOString().substring(0, 4);
$('#DateGet').val(now_year).trigger('change');
} else {
var dateLimit = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString().substring(0, 4);
$('#DateGet').val(dateLimit).trigger('change');
}
break;
}
}
//#endregion
//#region 更換input
$('#DateGet').on('change', function () {
timerange = $('#DateGet').val();
});
//#endregion
//#region 更換inputtext
$('#DateGettext').on('change', function () {
timerange = $('#DateGettext').val();
});
//#endregion
$("#js_list_accordion_filter").change(function (e) {
GetPowerStationCollapse($(this).val());
});
$('#js_list_accordion').on("change", 'input[name="selectedDeviceId[]"]', function (event) {
if (this.checked) {
if ($.inArray(this.value, selected_device) < 0) {
selected_device.push(this.value);
var type = $(this).attr("data-type");
switch (type) {
case 'PWR': //電錶
break;
case 'PYR': //日照計
$.each(PYR_select_col, function (index, item) {
if (!all_selected_compare_col.includes(item)) {
all_selected_compare_col.push(item);
}
});
break;
case 'ETR': //環境溫度計
$.each(ETR_select_col, function (index, item) {
if (!all_selected_compare_col.includes(item)) {
all_selected_compare_col.push(item);
}
});
break;
case 'VAN': //風速計
$.each(VAN_select_col, function (index, item) {
if (!all_selected_compare_col.includes(item)) {
all_selected_compare_col.push(item);
}
});
break;
case 'FOM': //落塵計
$.each(FOM_select_col, function (index, item) {
if (!all_selected_compare_col.includes(item)) {
all_selected_compare_col.push(item);
}
});
break;
case 'EMM': //環境濕度計
$.each(EMM_select_col, function (index, item) {
if (!all_selected_compare_col.includes(item)) {
all_selected_compare_col.push(item);
}
});
break;
}
console.log(all_selected_compare_col);
}
} else {
if ($.inArray(this.value, selected_device) > -1) {
selected_device.splice($.inArray(this.value, selected_device), 1);
switch (type) {
case 'PWR': //電錶
break;
case 'PYR': //日照計
$.each(PYR_select_col, function (index, item) {
if (all_selected_compare_col.includes(item)) {
all_selected_compare_col($.inArray(item, all_selected_compare_col), 1);
}
});
break;
case 'ETR': //環境溫度計
$.each(ETR_select_col, function (index, item) {
if (all_selected_compare_col.includes(item)) {
all_selected_compare_col($.inArray(item, all_selected_compare_col), 1);
}
});
break;
case 'VAN': //風速計
$.each(VAN_select_col, function (index, item) {
if (all_selected_compare_col.includes(item)) {
all_selected_compare_col($.inArray(item, all_selected_compare_col), 1);
}
});
break;
case 'FOM': //落塵計
$.each(FOM_select_col, function (index, item) {
if (all_selected_compare_col.includes(item)) {
all_selected_compare_col($.inArray(item, all_selected_compare_col), 1);
}
});
break;
case 'EMM': //環境濕度計
$.each(EMM_select_col, function (index, item) {
if (all_selected_compare_col.includes(item)) {
all_selected_compare_col($.inArray(item, all_selected_compare_col), 1);
}
});
break;
}
}
}
console.log(selected_device);
});
$('#js_list_accordion').on("change", 'input[name="selectedDeviceLayer2[]"]', function (event) {
if (this.checked) {
$(this).parents(".list-group-item").find('input[name="selectedDeviceId[]"]').prop("checked", true).trigger("change");
} else {
$(this).parents(".list-group-item").find('input[name="selectedDeviceId[]"]').prop("checked", false).trigger("change");
}
});
function GetPowerStationCollapse(filter) {
var url = "/AnalysisStationInfo/GetDeviceCollapse"
var send_data = {
Filter: filter
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.data.msg);
return;
}
var deviceCollapse = rel.data;
$('#js_list_accordion').empty();
if (deviceCollapse.length <= 0) {
$('#js_list_accordion').append("<div>查無結果</div>");
}
var str = "";
Object.keys(deviceCollapse).map(function (key, index) {
str += '<div class="card border-top-left-radius-0 border-top-right-radius-0" id="templateCard">' +
'<div class="card-header">' +
'<a href="javascript:void(0);" class="card-title collapsed" data-toggle="collapse" data-target="#js_list_accordion-' + index + '" aria-expanded="false" data-filter-tags="settings">' +
'<i class="fal fa-globe width-2 fs-xl"></i>' +
'<span class="city-name">' + key + '</span>' +
'<span class="ml-auto">' +
'<span class="collapsed-reveal"><i class="fal fa-chevron-up fs-xl"></i></span>' +
'<span class="collapsed-hidden"><i class="fal fa-chevron-down fs-xl"></i></span>' +
'</span>' +
'</a>' +
'</div>' +
'<div id="js_list_accordion-' + index + '" class="collapse" data-parent="#js_list_accordion" style="">' +
'<div class="card-body">' +
'<ul class="list-group list-group-flush">';
Object.keys(deviceCollapse[key]).map(function (powerStationkey, index) {
str += '<li class="list-group-item">' +
'<div class="d-flex justify-content-between">' +
'<h4 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + powerStationkey + '</h4>' +
'<div class="">' +
'<input type="checkbox" class="" name="selectedDeviceLayer2[]" >' +
'</div>' +
'</div>' +
'<ul class="list-group list-group-flush">';
$.each(deviceCollapse[key][powerStationkey], function (index, device) {
var device_icon = "";
switch (device.deviceType) {
case 'PWR': //電錶
device_icon = '<i class="fal fa-tachometer-alt-slow"></i>';
break;
case 'PYR': //日照計
device_icon = '<i class="fal fa-sun"></i>';
break;
case 'ETR': //環境溫度計
device_icon = '<i class="fal fa-thermometer-half"></i>';
break;
case 'VAN': //風速計
device_icon = '<i class="fal fa-wind"></i>';
break;
case 'FOM': //落塵計
device_icon = '<i class="fal fa-sun-dust"></i>';
break;
case 'EMM': //環境濕度計
device_icon = '<i class="fal fa-tint"></i>';
break;
}
str += '<li class="list-group-item pr-0 d-flex justify-content-between">' +
'<a href="#">' + device_icon + '&nbsp;' + device.deviceName + '</a>' +
'<div class=""><input type="checkbox" class="" name="selectedDeviceId[]" data-type="' + device.deviceType + '" value="' + device.deviceId + '">' + '</div>'
'</li>';
});
str += '</ul>' +
'</li>';
});
str += '</ul>';
str += '</div>';
str += '</div>';
});
$('#js_list_accordion').append(str);
$('#js_list_accordion').find('.card').first().addClass(" border-top-left-radius-0 border-top-right-radius-0");
if (selected_device.length <= 0) {
selected_device.push(Object.values(Object.values(deviceCollapse)[0])[0][0].deviceId)
}
$('input[name="selectedDeviceId[]"]').each(function () {
if ($.inArray(this.value, selected_device) > -1) {
$(this).prop('checked', true);
}
});
$("#js_list_accordion .collapse").collapse('show');
}, 'json');
}
function ChangeColSelectOption() {
}
</script>
}