FIC_Solar/SolarPower/Views/PowerStation/PowerStationEdit.cshtml
2021-06-18 12:25:45 +08:00

1597 lines
70 KiB
Plaintext

@{
ViewData["MainNum"] = "6";
ViewData["SubNum"] = "1";
ViewData["Title"] = "電站資料管理";
}
<ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">總覽</a></li>
<li class="breadcrumb-item">@ViewData["Title"]</li>
<li class="breadcrumb-item">新竹市</li>
<li class="breadcrumb-item active">新竹巨城站</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>
<!-- Your main content goes below here: -->
<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="subheader">
<h1 class="subheader-title">
<span class="icon-stack fa-1x">
<i class="base-7 icon-stack-3x color-info-500"></i>
<i class="base-7 icon-stack-2x color-info-700"></i>
<i class="ni ni-graph icon-stack-1x text-white"></i>
</span>
<span id="power-station-title">
新增電站
</span>
</h1>
</div>
<ul class="nav nav-tabs mb-5" role="tablist" id="tablist">
<li class="nav-item">
<a class="nav-link fs-lg px-4 active" data-toggle="tab" href="#tab-station-info" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">電站資料</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-device-setting" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">裝置列表</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-operation-firm" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">維運廠商</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-upload-image" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">資料上傳</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link fs-lg px-4" data-toggle="tab" href="#tab-exception" role="tab">
<i class="fal fa-home text-success"></i> <span class="hidden-sm-down ml-1">異常設定</span>
</a>
</li>
</ul>
<div class="tab-content p-3">
<div class="tab-pane fade show active" id="tab-station-info" role="tabpanel" aria-labelledby="tab-station-info">
@Html.Partial("_StationInfo")
</div>
<div class="tab-pane fade" id="tab-device-setting" role="tabpanel" aria-labelledby="tab-device-setting">
@Html.Partial("_DeviceSetting")
</div>
<div class="tab-pane fade" id="tab-operation-firm" role="tabpanel" aria-labelledby="tab-operation-firm">
@Html.Partial("_Operation")
</div>
<div class="tab-pane fade" id="tab-upload-image" role="tabpanel" aria-labelledby="tab-upload-image">
@Html.Partial("_UploadImage")
</div>
<div class="tab-pane fade" id="tab-exception" role="tabpanel" aria-labelledby="tab-exception">
@Html.Partial("_Exception")
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts{
<script>
var stationId;
var powerStationData;
var selectedLandBuildingId;
var isLandBuildingLock = false;
var selected_id = 0;
$(function () {
var url = new URL(location.href);
stationId = url.searchParams.get('stationId');
//#region 運維列表 DataTable
OperationTable = $("#Operation_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
"order": [[7, "desc"]],
"columns": [{
"data": "typeName"
}, {
"data": "name"
}, {
"data": "contactPerson"
}, {
"data": "phone"
}, {
"data": "email"
}, {
"data": "createdAt"
}, {
"data": "createdName"
}, {
"data": "function"
}],
"columnDefs": [{
'targets': 1,
'searchable': false,
'orderable': false,
'className': 'dt-body-center'
}],
"language": {
"emptyTable": "無資料...",
"processing": "處理中...",
"loadingRecords": "載入中...",
"lengthMenu": "顯示 _MENU_ 項結果",
"zeroRecords": "沒有符合的結果",
"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
"infoFiltered": "(從 _MAX_ 項結果中過濾)",
"infoPostFix": "",
"search": "搜尋:",
"paginate": {
"first": "第一頁",
"previous": "上一頁",
"next": "下一頁",
"last": "最後一頁"
},
"aria": {
"sortAscending": ": 升冪排列",
"sortDescending": ": 降冪排列"
}
},
'createdRow': function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
},
"ajax": {
"url": "/PowerStation/OperationTable",
"type": "POST",
"data": function (d) {
d.stationId = stationId;
},
"dataSrc": function (rel) {
if (rel.data.code == "9999") {
toast_error(rel.data.msg);
return;
}
data = rel.data.data;
if (data == null || data.length == 0) {
this.data = [];
}
return data;
}
}
});
//#endregion
//#region 設備列表 DataTable
DeviceTable = $("#Device_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
"order": [[9, "desc"]],
"columns": [{
"data": "uid"
}, {
"data": "name"
}, {
"data": "typeName"
}, {
"data": "brand"
}, {
"data": "productModel"
}, {
"data": "dbName"
}, {
"data": "tableName"
}, {
"data": "colName"
}, {
"data": "remark"
},{
"data": "function"
}],
"columnDefs": [{
'targets': 1,
'searchable': false,
'orderable': false,
'className': 'dt-body-center'
}],
"language": {
"emptyTable": "無資料...",
"processing": "處理中...",
"loadingRecords": "載入中...",
"lengthMenu": "顯示 _MENU_ 項結果",
"zeroRecords": "沒有符合的結果",
"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
"infoFiltered": "(從 _MAX_ 項結果中過濾)",
"infoPostFix": "",
"search": "搜尋:",
"paginate": {
"first": "第一頁",
"previous": "上一頁",
"next": "下一頁",
"last": "最後一頁"
},
"aria": {
"sortAscending": ": 升冪排列",
"sortDescending": ": 降冪排列"
}
},
'createdRow': function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
},
"ajax": {
"url": "/PowerStation/DeviceTable",
"type": "POST",
"data": function (d) {
d.stationId = stationId;
},
"dataSrc": function (rel) {
if (rel.data.code == "9999") {
toast_error(rel.data.msg);
return;
}
data = rel.data.data;
if (data == null || data.length == 0) {
this.data = [];
}
return data;
}
}
});
//#endregion
//#region 異常設定列表 DataTable
ExceptionTable = $("#Exception_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
"order": [[7, "desc"]],
"columns": [{
"data": "powerStationCode"
}, {
"data": "powerStationName"
}, {
"data": "typeName"
}, {
"data": "upperLimit"
}, {
"data": "lowerLimit"
}, {
"data": "alarmName"
}, {
"data": "createdAt"
}, {
"data": "function"
}],
"columnDefs": [{
'targets': 1,
'searchable': false,
'orderable': false,
'className': 'dt-body-center'
}],
"language": {
"emptyTable": "無資料...",
"processing": "處理中...",
"loadingRecords": "載入中...",
"lengthMenu": "顯示 _MENU_ 項結果",
"zeroRecords": "沒有符合的結果",
"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
"infoFiltered": "(從 _MAX_ 項結果中過濾)",
"infoPostFix": "",
"search": "搜尋:",
"paginate": {
"first": "第一頁",
"previous": "上一頁",
"next": "下一頁",
"last": "最後一頁"
},
"aria": {
"sortAscending": ": 升冪排列",
"sortDescending": ": 降冪排列"
}
},
'createdRow': function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
},
"ajax": {
"url": "/PowerStation/ExceptionTable",
"type": "POST",
"data": function (d) {
d.stationId = stationId;
},
"dataSrc": function (rel) {
if (rel.data.code == "9999") {
toast_error(rel.data.msg);
return;
}
data = rel.data.data;
if (data == null || data.length == 0) {
this.data = [];
}
return data;
}
}
});
//#endregion
//#region 電站資料 view 控制
if (stationId == 'new') {
//#region 電站基本資料
$("#address_detail_text").hide();
$("#power_station_code_text").hide();
$("#power_station_name_text").hide();
$("#electricity_meter_at_text").hide();
$("#estimated_recovery_time_text").hide();
$("#created_by_text").hide();
$("#generating_capacity_text").hide();
$("#escrow_name_text").hide();
$("#power_rate_text").hide();
$("#coordinate_text").hide();
$("#created_at_text").hide();
//逆變器
$("#inverter_brand_text").hide();
$("#inverter_product_model_text").hide();
$("#inverter_amount_text").hide();
//光電板
$("#photovoltaic_panel_brand_text").hide();
$("#photovoltaic_panel_specification_text").hide();
$("#photovoltaic_panel_amount_text").hide();
$("#photovoltaic_panel_product_model_text").hide();
//#endregion
$("#edit-station-info-btn").hide();
$("#canecl-station-info-btn").hide();
$("#check_escrow").attr('disabled', false);
$("#BoEPart").hide();
$("#land_buildingPart").hide();
$("#tablist").hide();
$("#tablist").find(".nav-item > a").first().click();
} else {
var url = "/PowerStation/GetOnePowerStation"
var send_data = {
id: stationId
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
powerStationData = rel.data;
//#region 電站基本資料
ChangeMode("station_info", "view");
SetStationInfo();
//#endregion
//#region 能源局與台電資料
ChangeMode("BOE_TPC", "view");
SetBoETPCInfo();
//#endregion
//#region 土地與房屋資料
ChangeMode("land_building_info", "view");
SetLandBuildingInfo();
//#endregion
}, 'json');
}
//#endregion
//#region 預先載入運維人員下拉式選單select_option
var url_user_select_option = "/PowerStation/GetUserSelectOptionList";
$.get(url_user_select_option, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#power_station_operation_personnel").empty();
$.each(rel.data, function (index, val) {
$("#power_station_operation_personnel").append($("<option />").val(val.value).text(val.text));
});
//預設查詢第一個
$("#power_station_operation_personnel").val($("#power_station_operation_personnel option:first").val());
});
$('.js-example-basic-multiple').select2();
//#endregion
//#region 預先載入縣市下拉式選單select_option
var url_city_select_option = "/PowerStation/GetCitySelectOptionList";
$.get(url_city_select_option, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#select_city").empty();
$.each(rel.data, function (index, val) {
$("#select_city").append($("<option />").val(val.value).text(val.text));
});
if (powerStationData == undefined || powerStationData == null) {
//預設查詢第一個
$("#select_city").val($("#select_city option:first").val()).trigger("change");
}
else {
$("#select_city").val(powerStationData.cityId).trigger("change");
}
});
//#endregion
//#region 縣市選擇後取得地區下拉式選單select_option
$("#select_city").change(function () {
var url_area_select_option = "/PowerStation/GetAreaSelectOptionList";
var send_data = {
cityId: $(this).val()
}
$.post(url_area_select_option, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#select_area").empty();
$.each(rel.data, function (index, val) {
$("#select_area").append($("<option />").val(val.value).text(val.text));
});
if (powerStationData == undefined || powerStationData == null) {
//預設查詢第一個
$("#select_area").val($("#select_area option:first").val());
}
else {
$("#select_area").val(powerStationData.areaId);
}
});
});
//#endregion
//#region 預先載入設備類型下拉式選單select_option
var url_DeviceType = "/PowerStation/GetDeviceTypeSelectOptionList";
$.get(url_DeviceType, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("Device_Type_modal").empty();
$.each(rel.data, function (index, val) {
$("#Device_Type_modal").append($("<option />").val(val.value).text(val.text));
});
})
//#endregion
});
//#region 代管切換
$("#check_escrow").click(function () {
if ($(this).prop("checked")) {
$('#check_escrow_label').html("Yes");
$("#escrow_name").attr('disabled', false)
} else {
$('#check_escrow_label').html("No");
$("#escrow_name").attr('disabled', true)
}
});
//#endregion
//#region 儲存電站基本資料資訊
function SaveStationInfo() {
var url = "/PowerStation/SavePowerStationInfo";
var send_data = {
Id: stationId,
CityId: $("#select_city").val(),
AreaId: $("#select_area").val(),
Address: $("#address_detail").val(),
Name: $("#power_station_name").val(),
IsEscrow: $('#check_escrow').is(':checked') ? 1 : 0,
ElectricityMeterAt: $("#electricity_meter_at").val(),
EstimatedRecoveryTime: $("#estimated_recovery_time").val(),
GeneratingCapacity: $("#generating_capacity").val(),
EscrowName: $('#check_escrow').is(':checked') ? $("#escrow_name").val() : "",
PowerRate: $("#power_rate").val(),
Coordinate: $("#coordinate").val(),
InverterBrand: $("#inverter_brand").val(),
InverterProductModel: $("#inverter_product_model").val(),
InverterAmount: $("#inverter_amount").val(),
PhotovoltaicPanelBrand: $("#photovoltaic_panel_brand").val(),
PhotovoltaicPanelSpecification: $("#photovoltaic_panel_specification").val(),
PhotovoltaicPanelAmount: $("#photovoltaic_panel_amount").val(),
PhotovoltaicPanelProductModel: $("#photovoltaic_panel_product_model").val()
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
if (stationId == "new") {
window.location = "/PowerStation/Edit?stationId=" + rel.data.id
} else {
//回填資料
powerStationData = rel.data;
SetStationInfo();
ChangeMode("station_info", "view");
}
}, 'json');
}
//#endregion
//#region 儲存能源局台電資料資訊
function SaveBoETPCInfo() {
var url = "/PowerStation/SaveBoETPCInfo";
var formData = new FormData();
var BoEFile = $('#BoE_file')[0].files;
formData.append("Id", stationId);
if (BoEFile.length > 0) {
formData.append("BoEFile", BoEFile[0]);
}
formData.append("BoEDiscountRate", $("#BoE_discount_rate").val());
formData.append("BoEDeviceRegisterNumber", $("#BoE_device_register_number").val());
formData.append("BoERentRatio", $("#BoE_discount_rate").val());
formData.append("TPCContractNumber", $("#TPC_contract_number").val());
formData.append("TPCContractAt", $("#TPC_contract_at").val());
formData.append("TPCSellDeadline", $("#TPC_sell_deadline").val());
formData.append("TPCMeterReading", $("#TPC_meter_reading").val());
formData.append("TPCPurchaseElectricityAt", $("#TPC_purchase_electricity_at").val());
formData.append("TPCSellElectricityAt", $("#TPC_sell_electricity_at").val());
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
powerStationData = rel.data;
//回填資料
SetBoETPCInfo();
ChangeMode("BOE_TPC", "view");
}
});
}
//#endregion
//#region 儲存土地房屋資訊
function SaveLandBuildingInfo() {
var url = "/PowerStation/SaveLandBuildingInfo";
var send_data = {
Id: selectedLandBuildingId,
PowerStationId: stationId,
Address: $("#land_building_address_" + selectedLandBuildingId).val(),
LeaseNotarizationAt: $("#lease_notarization_at_" + selectedLandBuildingId).val(),
Landowner: $("#land_building_landowner_" + selectedLandBuildingId).val(),
Purpose: $("#land_building_purpose_" + selectedLandBuildingId).val(),
LeaseRate: $("#land_building_lease_Rate_" + selectedLandBuildingId).val(),
Coordinate: $("#land_building_coordinate_" + selectedLandBuildingId).val(),
Phone: $("#land_building_phone_" + selectedLandBuildingId).val(),
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
powerStationData = rel.data;
SetLandBuildingInfo();
}, 'json');
}
//#endregion
//#region 切換【電站基本資料】、【能源局與台電】等檢視或修改模式
function ChangeMode(type, mode) {
switch (type) {
case "station_info": //【電站基本資料】
if (mode === "view") {
//觀看
//#region 電站基本資料 文字
$("#address_detail_text").show();
$("#power_station_code_text").show();
$("#power_station_name_text").show();
$("#electricity_meter_at_text").show();
$("#estimated_recovery_time_text").show();
$("#created_by_text").show();
$("#generating_capacity_text").show();
$("#escrow_name_text").show();
$("#power_rate_text").show();
$("#coordinate_text").show();
$("#created_at_text").show();
//逆變器
$("#inverter_brand_text").show();
$("#inverter_product_model_text").show();
$("#inverter_amount_text").show();
//光電板
$("#photovoltaic_panel_brand_text").show();
$("#photovoltaic_panel_specification_text").show();
$("#photovoltaic_panel_amount_text").show();
$("#photovoltaic_panel_product_model_text").show();
//#endregion
//#region 電站基本資料 input
$("#select_city").attr("disabled", true);
$("#select_area").attr("disabled", true);
$("#address_detail").hide();
$("#power_station_name").hide();
$("#check_escrow").attr("disabled", true);
$("#electricity_meter_at").hide();
$("#estimated_recovery_time").hide();
$("#generating_capacity").hide();
$("#escrow_name").hide();
$("#power_rate").hide();
$("#coordinate").hide();
//逆變器
$("#inverter_brand").hide();
$("#inverter_product_model").hide();
$("#inverter_amount").hide();
//光電板
$("#photovoltaic_panel_brand").hide();
$("#photovoltaic_panel_specification").hide();
$("#photovoltaic_panel_amount").hide();
$("#photovoltaic_panel_product_model").hide();
//#endregion
//#region 電站基本資料 btn
$("#add-station-info-btn").hide();
$("#edit-station-info-btn").show();
$("#canecl-station-info-btn").hide();
//#endregion
} else {
//修改
//#region 電站基本資料 文字
$("#address_detail_text").hide();
$("#power_station_name_text").hide();
$("#electricity_meter_at_text").hide();
$("#estimated_recovery_time_text").hide();
$("#created_by_text").hide();
$("#generating_capacity_text").hide();
$("#escrow_name_text").hide();
$("#power_rate_text").hide();
$("#coordinate_text").hide();
$("#created_at_text").hide();
//逆變器
$("#inverter_brand_text").hide();
$("#inverter_product_model_text").hide();
$("#inverter_amount_text").hide();
//光電板
$("#photovoltaic_panel_brand_text").hide();
$("#photovoltaic_panel_specification_text").hide();
$("#photovoltaic_panel_amount_text").hide();
$("#photovoltaic_panel_product_model_text").hide();
//#endregion
//#region 電站基本資料 input
$("#select_city").attr("disabled", false);
$("#select_area").attr("disabled", false);
$("#address_detail").show();
$("#power_station_name").show();
$("#check_escrow").attr("disabled", false);
$("#electricity_meter_at").show();
$("#estimated_recovery_time").show();
$("#generating_capacity").show();
$("#escrow_name").show();
$("#power_rate").show();
$("#coordinate").show();
//逆變器
$("#inverter_brand").show();
$("#inverter_product_model").show();
$("#inverter_amount").show();
//光電板
$("#photovoltaic_panel_brand").show();
$("#photovoltaic_panel_specification").show();
$("#photovoltaic_panel_amount").show();
$("#photovoltaic_panel_product_model").show();
//#endregion
//#region 電站基本資料 btn
$("#add-station-info-btn").show();
$("#edit-station-info-btn").hide();
$("#canecl-station-info-btn").show();
//#endregion
}
break;
case "BOE_TPC": //【能源局與台電】
if (mode === "view") {
//觀看
//#region 能源局與台電資料 文字
$("#link-boe-file").show();
$("#BoE_discount_rate_text").show();
$("#BoE_device_register_number_text").show();
$("#BoE_rent_ratio_text").show();
$("#TPC_contract_number_text").show();
$("#TPC_contract_at_text").show();
$("#TPC_sell_deadline_text").show();
$("#TPC_meter_reading_text").show();
$("#TPC_purchase_electricity_at_text").show();
$("#TPC_sell_electricity_at_text").show();
$("#BOE_TPC_created_by_text").show();
$("#BOE_TPC_created_at_text").show();
//#endregion
//#region 能源局與台電資料 input
$("#BoE_file").hide();
$("#BoE_discount_rate").hide();
$("#BoE_device_register_number").hide();
$("#BoE_rent_ratio").hide();
$("#TPC_contract_number").hide();
$("#TPC_contract_at").hide();
$("#TPC_sell_deadline").hide();
$("#TPC_meter_reading").hide();
$("#TPC_purchase_electricity_at").hide();
$("#TPC_sell_electricity_at").hide();
//#endregion
//#region 能源局與台電btn
$("#add-boe-tpc-btn").hide();
$("#edit-boe-tpc-btn").show();
$("#canecl-boe-tpc-btn").hide();
//#endregion
} else {
//修改
//#region 能源局與台電資料 文字
$("#link-boe-file").hide();
$("#BoE_discount_rate_text").hide();
$("#BoE_device_register_number_text").hide();
$("#BoE_rent_ratio_text").hide();
$("#TPC_contract_number_text").hide();
$("#TPC_contract_at_text").hide();
$("#TPC_sell_deadline_text").hide();
$("#TPC_meter_reading_text").hide();
$("#TPC_purchase_electricity_at_text").hide();
$("#TPC_sell_electricity_at_text").hide();
@*$("#BOE_TPC_created_by_text").hide();
$("#BOE_TPC_created_at_text").hide();*@
//#endregion
//#region 能源局與台電資料 input
$("#BoE_file").show();
$("#BoE_discount_rate").show();
$("#BoE_device_register_number").show();
$("#BoE_rent_ratio").show();
$("#TPC_contract_number").show();
$("#TPC_contract_at").show();
$("#TPC_sell_deadline").show();
$("#TPC_meter_reading").show();
$("#TPC_purchase_electricity_at").show();
$("#TPC_sell_electricity_at").show();
//#endregion
//#region 能源局與台電btn
$("#add-boe-tpc-btn").show();
$("#edit-boe-tpc-btn").hide();
$("#canecl-boe-tpc-btn").show();
//#endregion
}
break;
case "land_building_info": //【土地房屋資料】
if (mode === "view") {
//觀看
//#region 土地房屋資料 文字
$("#land_building_address_text_" + selectedLandBuildingId).show();
$("#land_building_coordinate_text_" + selectedLandBuildingId).show();
$("#lease_notarization_at_text_" + selectedLandBuildingId).show();
$("#land_building_lease_Rate_text_" + selectedLandBuildingId).show();
$("#land_building_landowner_text_" + selectedLandBuildingId).show();
$("#land_building_phone_text_" + selectedLandBuildingId).show();
$("#land_building_purpose_text_" + selectedLandBuildingId).show();
$("#land_building_created_by_text_" + selectedLandBuildingId).show();
$("#land_building_created_at_text_" + selectedLandBuildingId).show();
//#endregion
//#region 土地房屋資料 input
$("#land_building_address_" + selectedLandBuildingId).hide();
$("#land_building_coordinate_" + selectedLandBuildingId).hide();
$("#lease_notarization_at_" + selectedLandBuildingId).hide();
$("#land_building_lease_Rate_" + selectedLandBuildingId).hide();
$("#land_building_landowner_" + selectedLandBuildingId).hide();
$("#land_building_phone_" + selectedLandBuildingId).hide();
$("#land_building_purpose_" + selectedLandBuildingId).hide();
//#endregion
//#region 土地房屋資料 btn
$("#save-land-building-info-btn-" + selectedLandBuildingId).hide();
$("#edit-land-building-info-btn-" + selectedLandBuildingId).show();
$("#canecl-land-building-info-btn-" + selectedLandBuildingId).hide();
$("#del-land-building-info-btn-" + selectedLandBuildingId).show();
//#endregion
} else {
//修改
//#region 土地房屋資料 文字
$("#land_building_address_text_" + selectedLandBuildingId).hide();
$("#land_building_coordinate_text_" + selectedLandBuildingId).hide();
$("#lease_notarization_at_text_" + selectedLandBuildingId).hide();
$("#land_building_lease_Rate_text_" + selectedLandBuildingId).hide();
$("#land_building_landowner_text_" + selectedLandBuildingId).hide();
$("#land_building_phone_text_" + selectedLandBuildingId).hide();
$("#land_building_purpose_text_" + selectedLandBuildingId).hide();
$("#land_building_created_by_text_" + selectedLandBuildingId).hide();
$("#land_building_created_at_text_" + selectedLandBuildingId).hide();
//#endregion
//#region 土地房屋資料 input
$("#land_building_address_" + selectedLandBuildingId).show();
$("#land_building_coordinate_" + selectedLandBuildingId).show();
$("#lease_notarization_at_" + selectedLandBuildingId).show();
$("#land_building_lease_Rate_" + selectedLandBuildingId).show();
$("#land_building_landowner_" + selectedLandBuildingId).show();
$("#land_building_phone_" + selectedLandBuildingId).show();
$("#land_building_purpose_" + selectedLandBuildingId).show();
//#endregion
//#region 土地房屋資料 btn
$("#save-land-building-info-btn-" + selectedLandBuildingId).show();
$("#edit-land-building-info-btn-" + selectedLandBuildingId).hide();
$("#canecl-land-building-info-btn-" + selectedLandBuildingId).show();
$("#del-land-building-info-btn-" + selectedLandBuildingId).hide();
//#endregion
}
break;
}
}
//#endregion
//#region 設定電站基本資料
function SetStationInfo() {
$("#power-station-title").html(powerStationData.name);
$("#select_city").val(powerStationData.cityId).trigger("change");
$("#select_area").val(powerStationData.areaId);
//#region 電站基本資料 文字
$("#address_detail_text").html(powerStationData.address);
$("#power_station_code_text").html(powerStationData.code);
$("#power_station_name_text").html(powerStationData.name);
$("#electricity_meter_at_text").html(powerStationData.electricityMeterAt);
$("#estimated_recovery_time_text").html(powerStationData.estimatedRecoveryTime);
$("#created_by_text").html(powerStationData.CreatorName);
$("#generating_capacity_text").html(powerStationData.generatingCapacity);
$("#escrow_name_text").html(powerStationData.escrowName);
$("#power_rate_text").html(powerStationData.powerRate);
$("#coordinate_text").html(powerStationData.coordinate);
$("#created_at_text").html(powerStationData.createdAt);
//逆變器
$("#inverter_brand_text").html(powerStationData.inverterBrand);
$("#inverter_product_model_text").html(powerStationData.inverterProductModel);
$("#inverter_amount_text").html(powerStationData.inverterAmount);
//光電板
$("#photovoltaic_panel_brand_text").html(powerStationData.photovoltaicPanelBrand);
$("#photovoltaic_panel_product_model_text").html(powerStationData.photovoltaicPanelProductModel);
$("#photovoltaic_panel_specification_text").html(powerStationData.photovoltaicPanelSpecification);
$("#photovoltaic_panel_amount_text").html(powerStationData.photovoltaicPanelAmount);
//#endregion
//#region 電站基本資料 input
$("#address_detail").val(powerStationData.address);
$("#power_station_name").val(powerStationData.name);
$("#check_escrow").attr("checked", powerStationData.isEscrow == 1 ? true : false);
$("#check_escrow_label").html(powerStationData.isEscrow == 1 ? "Yes" : "No");
$("#electricity_meter_at").val(powerStationData.electricityMeterAt);
$("#estimated_recovery_time").val(powerStationData.estimatedRecoveryTime);
$("#generating_capacity").val(powerStationData.generatingCapacity);
$("#escrow_name").val(powerStationData.escrowName);
$("#power_rate").val(powerStationData.powerRate);
$("#coordinate").val(powerStationData.coordinate);
//逆變器
$("#inverter_brand").val(powerStationData.inverterBrand);
$("#inverter_product_model").val(powerStationData.inverterProductModel);
$("#inverter_amount").val(powerStationData.inverterAmount);
//光電板
$("#photovoltaic_panel_brand").val(powerStationData.photovoltaicPanelBrand);
$("#photovoltaic_panel_product_model").val(powerStationData.photovoltaicPanelProductModel);
$("#photovoltaic_panel_specification").val(powerStationData.photovoltaicPanelSpecification);
$("#photovoltaic_panel_amount").val(powerStationData.photovoltaicPanelAmount);
//#endregion
}
//#endregion
//#region 設定能源局與台電資料
function SetBoETPCInfo() {
//#region 能源局與台電資料 文字
$("#link-boe-file").html(powerStationData.boEFileName).attr("href", powerStationData.boEFile);
$("#BoE_discount_rate_text").html(powerStationData.boEDiscountRate);
$("#BoE_device_register_number_text").html(powerStationData.boEDeviceRegisterNumber);
$("#BoE_rent_ratio_text").html(powerStationData.boERentRatio);
$("#TPC_contract_number_text").html(powerStationData.tpcContractNumber);
$("#TPC_contract_at_text").html(powerStationData.tpcContractAt);
$("#TPC_sell_deadline_text").html(powerStationData.tpcSellDeadline);
$("#TPC_meter_reading_text").html(powerStationData.tpcMeterReading);
$("#TPC_purchase_electricity_at_text").html(powerStationData.tpcPurchaseElectricityAt);
$("#TPC_sell_electricity_at_text").html(powerStationData.tpcSellElectricityAt);
$("#BOE_TPC_created_by_text").html(powerStationData.creatorName);
$("#BOE_TPC_created_at_text").html(powerStationData.createdAt);
//#endregion
//#region 能源局與台電資料 input
$("#BoE_discount_rate").val(powerStationData.boeEiscountRate);
$("#BoE_device_register_number").val(powerStationData.boEDeviceRegisterNumber);
$("#BoE_discount_rate").val(powerStationData.boERentRatio);
$("#TPC_contract_number").val(powerStationData.tpcContractNumber);
$("#TPC_contract_at").val(powerStationData.tpcContractAt);
$("#TPC_sell_deadline").val(powerStationData.tpcSellDeadline);
$("#TPC_meter_reading").val(powerStationData.tpcMeterReading);
$("#TPC_purchase_electricity_at").val(powerStationData.tpcPurchaseElectricityAt);
$("#TPC_sell_electricity_at").val(powerStationData.tpcSellElectricityAt);
//#endregion
}
//#endregion
//#region 設定土地與房屋資料
function SetLandBuildingInfo() {
var landBuildingCard = $("#land_buildingPart");
landBuildingCard.empty();
powerStationData.landBuildings.forEach(function (value, index) {
CreateLandBuildingCard(landBuildingCard, value);
});
// 找出第一個移除"刪除"按鈕
var firstCardId = landBuildingCard.find(".card").first().attr("data-land-building-id");
$("#del-land-building-info-btn-" + firstCardId).remove();
//加入新增土地房屋卡片
CreateAddLandBuildingCard(landBuildingCard);
}
//#endregion
//#region 創建每份土地房屋資訊卡片
function CreateLandBuildingCard(dom, value) {
var appendStr = "";
appendStr += '<div class="card border mb-g w-100" data-land-building-id="' + value.id + '">' +
'<div class="card-header bg-fusion-50 pr-3 d-flex align-items-center flex-wrap justify-content-between">' +
'<div class="card-title font-weight-bold">土地房屋資料</div>' +
'<div class="text-right">' +
'<button class="btn btn-sm btn-success ml-auto waves-effect waves-themed save-land-building-info-btn" style="display:none" data-land-building-id="' + value.id + '" id="save-land-building-info-btn-' + value.id + '">' +
'<span class="fal fa-cog mr-1"></span> 儲存' +
'</button>' +
'<button class="btn btn-sm btn-info ml-auto waves-effect waves-themed edit-land-building-info-btn" data-land-building-id="' + value.id + '" id="edit-land-building-info-btn-' + value.id + '">' +
'<span class="fal fa-cog mr-1"></span> 修改' +
'</button>' +
'<button class="btn btn-sm btn-primary ml-auto waves-effect waves-themed canecl-land-building-info-btn" style="display:none" data-land-building-id="' + value.id + '" id="canecl-land-building-info-btn-' + value.id + '">' +
'<span class="fal fa-cog mr-1"></span> 取消' +
'</button>' +
'<button class="btn btn-sm btn-danger ml-auto waves-effect waves-themed del-land-building-info-btn" data-land-building-id="' + value.id + '" id="del-land-building-info-btn-' + value.id + '">' +
'<span class="fal fa-cog mr-1"></span> 刪除' +
'</button>' +
'</div>' +
'</div>';
appendStr += '<div class="card-body">' +
'<div class="row d-flex justify-content-between card-land-building" data-id="' + value.id + '">' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">地址</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_address_text_' + value.id + '" class="color-info-600">' + value.address + '</label>' +
'<input type="text" style="display:none" id="land_building_address_' + value.id + '" name="land_building_address_' + value.id + '" class="form-control" value="' + value.address + '">' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">經緯度</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_coordinate_text_' + value.id + '" class="color-info-600">' + value.coordinate + '</label>' +
'<input type="text" style="display:none" id="land_building_coordinate_' + value.id + '" name="land_building_coordinate_' + value.id + '" class="form-control" value="' + value.coordinate + '">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">租約公證日期</label>' +
'<div class="col-xl-8">' +
'<label id="lease_notarization_at_text_' + value.id + '" class="color-info-600">' + value.leaseNotarizationAt + '</label>' +
'<input type="date" style="display:none" id="lease_notarization_at_' + value.id + '" name="lease_notarization_at_' + value.id + '" class="form-control" value="' + value.leaseNotarizationAt + '">' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">租金比例 (%)</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_lease_Rate_text_' + value.id + '" class="color-info-600">' + value.leaseRate + '</label>' +
'<input type="text" style="display:none" id="land_building_lease_Rate_' + value.id + '" name="land_building_lease_Rate_' + value.id + '" class="form-control" value="' + value.leaseRate + '">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">地主姓名</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_landowner_text_' + value.id + '" class="color-info-600">' + value.landowner + '</label>' +
'<input type="text" style="display:none" id="land_building_landowner_' + value.id + '" name="land_building_landowner_' + value.id + '" class="form-control" value="' + value.landowner + '">' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">電話</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_phone_text_' + value.id + '" class="color-info-600">' + value.phone + '</label>' +
'<input type="text" style="display:none" id="land_building_phone_' + value.id + '" name="land_building_phone_' + value.id + '" class="form-control" value="' + value.phone + '">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">房屋用途</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_purpose_text_' + value.id + '" class="color-info-600">' + value.purpose + '</label>' +
'<input type="text" style="display:none" id="land_building_purpose_' + value.id + '" name="land_building_purpose_' + value.id + '" class="form-control" value="' + value.purpose + '">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">資料建立</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_created_by_text_' + value.id + '" class="color-info-600">' + value.creatorName + '</label>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">建立時間</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_created_at_text_' + value.id + '" class="color-info-600">' + value.createdAt + '</label>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
dom.append(appendStr);
}
//#endregion
//#region 創建新增土地房屋資訊卡片
function CreateAddLandBuildingCard(dom) {
var appendStr = "";
appendStr += '<div class="card border mb-g w-100" id="add-land-building-card">' +
'<div class="card-header bg-fusion-50 pr-3 d-flex align-items-center flex-wrap justify-content-between">' +
'<div class="card-title font-weight-bold">土地房屋資料</div>' +
'<div class="text-right">' +
'<button class="btn btn-sm btn-info ml-auto waves-effect waves-themed" id="add-land-building-info-btn">' +
'<span class="fal fa-cog mr-1"></span> 新增' +
'</button>' +
'<div aria-expanded="true">' +
'<button class="btn btn-sm btn-success ml-auto waves-effect waves-themed save-land-building-info-btn" style="display:none" data-land-building-id="0" id="save-land-building-info-btn-0">' +
'<span class="fal fa-cog mr-1"></span> 儲存' +
'</button>' +
'<button class="btn btn-sm btn-primary ml-auto waves-effect waves-themed" style="display:none" id="cancel-add-land-building-info-btn">' +
'<span class="fal fa-cog mr-1"></span> 取消' +
'</button>' +
'</div>' +
'</div>' +
'</div>';
appendStr += '<div class="card-body collapse">' +
'<div class="row d-flex justify-content-between card-land-building">' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">地址</label>' +
'<div class="col-xl-8">' +
'<input type="text" id="land_building_address_0" name="land_building_address_0" class="form-control">' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">經緯度</label>' +
'<div class="col-xl-8">' +
'<input type="text" id="land_building_coordinate_0" name="land_building_coordinate_0" class="form-control">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">租約公證日期</label>' +
'<div class="col-xl-8">' +
'<input type="date" id="lease_notarization_at_0" name="lease_notarization_at_0" class="form-control">' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">租金比例 (%)</label>' +
'<div class="col-xl-8">' +
'<input type="text" id="land_building_lease_Rate_0" name="land_building_lease_Rate_0" class="form-control">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">地主姓名</label>' +
'<div class="col-xl-8">' +
'<input type="text" id="land_building_landowner_0" name="land_building_landowner_0" class="form-control">' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">電話</label>' +
'<div class="col-xl-8">' +
'<input type="text" id="land_building_phone_0" name="land_building_phone_0" class="form-control">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">房屋用途</label>' +
'<div class="col-xl-8">' +
'<input type="text" id="land_building_purpose_0" name="land_building_purpose_0" class="form-control">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="col-xl">' +
'<div class="row mb-3">' +
'<label class="col-xl-4 form-label">資料建立</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_created_by_text_0" class="color-info-600"></label>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<label class="col-xl-4 form-label">建立時間</label>' +
'<div class="col-xl-8">' +
'<label id="land_building_created_at_text_0" class="color-info-600"></label>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
dom.append(appendStr);
}
//#endregion
//#region 土地與房屋按鈕控制
//儲存
$('#land_buildingPart').on("click", "button.save-land-building-info-btn", function () {
selectedLandBuildingId = $(this).attr("data-land-building-id");
SaveLandBuildingInfo();
isLandBuildingLock = false;
});
//編輯
$('#land_buildingPart').on("click", "button.edit-land-building-info-btn", function () {
if (isLandBuildingLock) {
toast_error("當前已有其他【土地方屋資訊】正在編輯中。")
}
selectedLandBuildingId = $(this).attr("data-land-building-id");
ChangeMode("land_building_info", "edit");
isLandBuildingLock = true;
});
//取消
$('#land_buildingPart').on("click", "button.canecl-land-building-info-btn", function () {
selectedLandBuildingId = $(this).attr("data-land-building-id");
ChangeMode("land_building_info", "view");
isLandBuildingLock = false;
});
//刪除
$('#land_buildingPart').on("click", "button.del-land-building-info-btn", function () {
selectedLandBuildingId = $(this).attr("data-land-building-id");
var url = "/PowerStation/DeleteLandBuildingInfo";
var send_data = {
Id: selectedLandBuildingId
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
powerStationData = rel.data;
SetLandBuildingInfo();
}, 'json');
});
//新增土地房屋卡片
//新增
$('#land_buildingPart').on("click", "#add-land-building-card button#add-land-building-info-btn", function () {
$("#add-land-building-card > .card-body").collapse('show');
$("#add-land-building-card button#add-land-building-info-btn").hide();
$("#add-land-building-card button#save-land-building-info-btn-0").show();
$("#add-land-building-card button#cancel-add-land-building-info-btn").show();
});
//取消
$('#land_buildingPart').on("click", "#add-land-building-card button#cancel-add-land-building-info-btn", function () {
alert("bbb");
$("#add-land-building-card > .card-body").collapse('hide');
$("#add-land-building-card button#add-land-building-info-btn").show();
$("#add-land-building-card button#save-land-building-info-btn-0").hide();
$("#add-land-building-card button#cancel-add-land-building-info-btn").hide();
});
//#endregion
//#region 新增維運資料
function AddOperation()
{
selected_id = 0;
$("#Operation-modal .modal-title").html("運維廠商資料 - 新增");
$("#Operation-form").trigger("reset");
$("#Operation-modal").modal();
}
//#endregion
//#region 儲存運維資料
function SaveOperation() {
if ($("#Operation-form").valid()) {
var url = "/PowerStation/SaveOperation";
var send_data = {
Id: selected_id,
PowerStationId: stationId,
Type: $("#Operation_role_modal").val(),
Name: $("#Operation_factory_modal").val(),
ContactPerson: $("#Operation_name_modal").val(),
Phone: $("#Operation_phone_modal").val(),
Email: $("#Operation_email_modal").val(),
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else
{
toast_ok(rel.msg);
$('#Operation-modal').modal('hide');
OperationTable.ajax.reload();
return;
}
}, 'json');
}
}
//#endregion
//#region 取一筆運維
$('#Operation_table').on("click", "button.edit-btn", function () {
$("#Operation-modal .modal-title").html("運維廠商資料 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
//取得單一運維基本資料
var url = "/PowerStation/GetOneOperation/";
var send_data = {
id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#Operation_role_modal").val(rel.data.type);
$("#Operation_factory_modal").val(rel.data.name);
$("#Operation_name_modal").val(rel.data.contactPerson);
$("#Operation_phone_modal").val(rel.data.phone);
$("#Operation_email_modal").val(rel.data.email);
$("#Operation-modal").modal();
}, 'json');
});
//#endregion
//#region 刪除運維資料
$('#Operation_table').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
var url = "/PowerStation/DeleteOneOperation/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
OperationTable.ajax.reload();
}, 'json');
});
//#endregion
//#region 新增裝置資料
function AddDevice() {
selected_id = 0;
$("#Device-modal .modal-title").html("裝置資料 - 新增");
$("#Device-form").trigger("reset");
$("#Device-modal").modal();
}
//#endregion
//#region 儲存裝置資料
function SaveDevice() {
if ($("#Device-form").valid()) {
var url = "/PowerStation/SaveDevice";
var send_data = {
Id: selected_id,
PowerStationId: stationId,
Name: $("#Device_Name_modal").val(),
Type: $("#Device_Type_modal").val(),
TypeName: $("#Device_Type_modal :selected").text(),
Brand: $("#Device_Brand_modal").val(),
ProductModel: $("#Device_ProductModel_modal").val(),
DBName: $("#Device_DBName_modal").val(),
TableName: $("#Device_TableName_modal").val(),
ColName: $("#Device_ColName_modal").val(),
Remark: $("#Device_Remark_modal").val()
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
toast_ok(rel.msg);
$('#Device-modal').modal('hide');
DeviceTable.ajax.reload();
return;
}
}, 'json');
}
}
//#endregion
//#region 取一筆設備
$('#Device_table').on("click", "button.edit-btn", function () {
$("#Device-modal .modal-title").html("設備資料 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
//取得單一運維基本資料
var url = "/PowerStation/GetOneDevice/";
var send_data = {
id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
document.getElementById('Device_Type_modal').disabled = true;
$("#Device_Name_modal").val(rel.data.name);
$("#Device_Type_modal").val(rel.data.type);
$("#Device_Brand_modal").val(rel.data.brand);
$("#Device_ProductModel_modal").val(rel.data.productModel);
$("#Device_DBName_modal").val(rel.data.dbName);
$("#Device_TableName_modal").val(rel.data.tableName);
$("#Device_ColName_modal").val(rel.data.colName);
$("#Device_Remark_modal").val(rel.data.remark);
$("#Device-modal").modal();
}, 'json');
});
//#endregion
//#region 刪除裝置
$('#Device_table').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
var url = "/PowerStation/DeleteOneDevice/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
DeviceTable.ajax.reload();
}, 'json');
});
//#endregion
//#region 新增異常設定資料
function AddException() {
selected_id = 0;
$("#Exception-modal .modal-title").html("異常設定資料 - 新增");
$("#Exception-form").trigger("reset");
$("#Exception-modal").modal();
}
//#endregion
//#region 儲存異常設定資料
function SaveException() {
if ($("#Exception-form").valid()) {
var url = "/PowerStation/SaveException";
var send_data = {
Id: selected_id,
PowerStationId: stationId,
Type: $("#Exception_Type_modal").val(),
UpperLimit: $("#Exception_UpperLimit_modal").val(),
LowerLimit: $("#Exception_LowerLimit_modal").val(),
Alarm: $("#Exception_Alarm_modal").val()
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
else {
toast_ok(rel.msg);
$('#Exception-modal').modal('hide');
ExceptionTable.ajax.reload();
return;
}
}, 'json');
}
}
//#endregion
//#region 取一筆異常設定
$('#Exception_table').on("click", "button.edit-btn", function () {
$("#Exception-modal .modal-title").html("異常設定資料 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
//取得單一異常設定資料
var url = "/PowerStation/GetOneException/";
var send_data = {
id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#Exception_Type_modal").val(rel.data.type);
$("#Exception_Alarm_modal").val(rel.data.alarm);
$("#Exception_UpperLimit_modal").val(rel.data.upperLimit);
$("#Exception_LowerLimit_modal").val(rel.data.lowerLimit);
$("#Exception-modal").modal();
}, 'json');
});
//#endregion
//#region 刪除異常
$('#Exception_table').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
var url = "/PowerStation/DeleteOneException/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
ExceptionTable.ajax.reload();
}, 'json');
});
//#endregion
</script>
}