FIC_Solar/SolarPower/Views/User/Index.cshtml
Kai 7480fee9df 1. 修改myUser 資料
2. 公司管理上傳圖片
3. 加入電站資訊頁面
2021-06-13 18:46:10 +08:00

1081 lines
42 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

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.

@{
ViewData["MainNum"] = "6";
ViewData["SubNum"] = "3";
ViewData["Title"] = "帳號管理";
}
<ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">系統管理</a></li>
<li class="breadcrumb-item">FIC</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>
<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">
<img src="img/asus.png" id="company-logo"><span id="company-name">華碩電腦</span>
</h1>
</div>
<ul class="nav nav-tabs nav-tabs-clean" id="tabs" role="tablist">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#tab-user-manager" role="tab">帳號管理</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-manager" role="tab">角色管理</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab-role-auth" role="tab">角色權限</a></li>
</ul>
<div class="tab-content p-3">
<div class="tab-pane fade show active" id="tab-user-manager" role="tabpanel" aria-labelledby="tab-user-manager">
@Html.Partial("_UserManager")
</div>
<div class="tab-pane fade" id="tab-role-manager" role="tabpanel" aria-labelledby="tab-role-manager">
@Html.Partial("_RoleManager")
</div>
<div class="tab-pane fade" id="tab-role-auth" role="tabpanel" aria-labelledby="tab-role-auth">
@Html.Partial("_RoleAuth")
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@*
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">搜尋條件</h3>
</div>
<div class="card-body">
<form id="system-admin-filter-form">
<div class="form-row">
<div class="form-group col-md-6">
<label>帳號:</label>
<input type="text" class="form-control" id="system_admin_account" name="system_admin_account">
</div>
<div class="form-group col-md-6">
<label>姓名:</label>
<input type="text" class="form-control" id="system_admin_name" name="system_admin_name">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>電子信箱:</label>
<input type="text" class="form-control" id="system_admin_email" name="system_admin_email">
</div>
<div class="form-group col-md-6">
<label>手機號碼:</label>
<input type="text" class="form-control" id="system_admin_phone" name="system_admin_phone">
</div>
</div>
</form>
</div>
<div class="card-footer text-right">
<button type="button" class="btn btn-default" onclick="ResetForm()">清除</button>
<button type="button" class="btn btn-primary" onclick="SearchSystemAdmin()">查詢</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">人員列表</h3>
<div class="card-tools">
<button class="btn btn-success" onclick="AddSystemAdmin()"><i class="fa fa-plus"></i>&nbsp;新增</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="system_admin_table" class="table table-bordered table-hover">
<thead>
<tr>
<th>帳號</th>
<th>姓名</th>
<th>電子信箱</th>
<th>手機號碼</th>
<th>狀態</th>
<th>建立時間</th>
<th>功能</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
<!-- 個人資料 -->
<div class="modal" tabindex="-1" id="system-admin-modal" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">系統管理員</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<form class="system-admin-form" id="system-admin-form">
<div class="form-row">
<div class="form-group col-md-12">
<label for="system_admin_name_modal">
<font class="text-danger">*</font>姓名:
</label>
<input type="text" class="form-control" id="system_admin_name_modal" name="system_admin_name_modal" autocomplete="off" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="system_admin_account_modal">
帳號:
</label>
<input type="text" class="form-control" id="system_admin_account_modal" name="system_admin_account_modal" disabled>
</div>
</div>
<div class="form-row system_admin_password_form_row">
<div class="form-group col-md-12">
<label>
密碼:等同帳號
</label>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label>狀態:</label>
<div class="custom-control custom-radio d-inline">
<input class="custom-control-input" type="radio" id="system_admin_status_normal_modal" name="system_admin_status_modal" value="0">
<label for="system_admin_status_normal_modal" class="custom-control-label">正常</label>
</div>
<div class="custom-control custom-radio d-inline">
<input class="custom-control-input" type="radio" id="system_admin_status_suspend_modal" name="system_admin_status_modal" value="1">
<label for="system_admin_status_suspend_modal" class="custom-control-label">停權</label>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="system_admin_email_modal">
電子信箱:
</label>
<input type="email" class="form-control" id="system_admin_email_modal" name="system_admin_email_modal" autocomplete="off">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="system_admin_phone_modal">
電話:
</label>
<input type="text" class="form-control" id="system_admin_phone_modal" name="system_admin_phone_modal" autocomplete="off">
</div>
</div>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-save" onclick="SaveSystemAdmin()">儲存</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
</div>
</div>
</div>
</div>
<!-- /.個人資料 -->
*@
@section Scripts {
<script>
var userTable; var roleTable; var roleAuthTable; var roleAuthNotJoinTable;
var selected_id = 0, selected_role_id = 0, selected_company_id = 0;
var selected_tab = "";
$(function () {
selected_tab = $('#tabs').find("li a.active").attr("href"); // 當前tab
//#region 預先載入公司下拉式選單select_option
var url_company_select_option = "/Company/GetCompanySelectOptionList";
$.get(url_company_select_option, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$(".select_user_company").empty();
$.each(rel.data, function (index, val) {
$(".select_user_company").append($("<option />").val(val.value).text(val.text));
});
//預設查詢第一個
$(".select_user_company").val($(".select_user_company option:first").val()).trigger('change');
});
//#endregion
//#region 選擇公司後角色下拉式選單select_option
$(".select_user_company").change(function () {
var select_option_with_tab = $(this).attr('data-tab');
if (selected_tab != select_option_with_tab) {
//判斷是否為當前tab的 公司選單傳值被修改
return;
}
//變更其他tab裡面select_user_company的值
switch (selected_tab) {
case "#tab-user-manager":
$("#select_company_role_roleManager_tab").val($(this).val()).trigger('change');
$("#select_companyId_roleAuth_tab").val($(this).val()).trigger('change');
break;
case "#tab-role-manager":
$("#select_user_company_userManager_tab").val($(this).val()).trigger('change');
$("#select_companyId_roleAuth_tab").val($(this).val()).trigger('change');
break;
case "#tab-role-auth":
$("#select_user_company_userManager_tab").val($(this).val()).trigger('change');
$("#select_company_role_roleManager_tab").val($(this).val()).trigger('change');
break;
}
//查詢該公司的基本資料
var url_company_info = "/Company/GetOneCompany"
var send_data = {
Id: $(this).val()
}
$.post(url_company_info, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#company-logo").attr("src", rel.data.logo);
$("#company-name").html(rel.data.name);
$("#company-modal").modal();
}, 'json');
//更新當前剩餘可註冊使用者人數
UpdateRegisterNumber($(this).val());
//查詢該公司的角色
var url_company_role_select_option = "/Role/GetRoleSelectOptionList";
send_data = {
CompanyId: $(this).val()
}
$.get(url_company_role_select_option, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
//#region 帳號管理Tab - 角色下拉式選單(搜尋)
if (rel.data.length > 0) {
$("#select_company_role_userManager_tab").empty();
$("#select_company_role_userManager_tab").append($("<option />").val(0).text("全部"));
$.each(rel.data, function (index, val) {
$("#select_company_role_userManager_tab").append($("<option />").val(val.value).text(val.text));
});
//預設查詢第一個
$("#select_company_role_userManager_tab").val($("#select_company_role_userManager_tab option:first").val()).trigger('change');
} else {
$("#select_company_role_userManager_tab").empty();
$("#select_company_role_userManager_tab").append('<option value="0" disabled>請先新增角色</option>');
$("#select_company_role_userManager_tab").val($("#select_company_role_userManager_tab option:first").val()).trigger('change');
}
//#endregion
//#region 帳號管理Tab - 人員基本資料新增/修改 modal
if (rel.data.length > 0) {
$('#user_role_modal').empty();
$.each(rel.data, function (index, val) {
$("#user_role_modal").append($("<option />").val(val.value).text(val.text));
});
//預設查詢第一個
$("#user_role_modal").val($("#user_role_modal option:first").val()).trigger('change');
} else {
$("#user_role_modal").empty();
$("#user_role_modal").append('<option value="0" disabled>請先新增角色</option>');
$("#user_role_modal").val($("#user_role_modal option:first").val()).trigger('change');
}
//#endregion
//#region 角色權限Tab - 角色下拉是選單(搜尋)
if (rel.data.length > 0) {
$("#select_roleId_roleAuth_tab").empty();
$.each(rel.data, function (index, val) {
$("#select_roleId_roleAuth_tab").append($("<option />").val(val.value).text(val.text));
});
//預設查詢第一個
$("#select_roleId_roleAuth_tab").val($("#select_roleId_roleAuth_tab option:first").val()).trigger('change');
} else {
$("#select_roleId_roleAuth_tab").empty();
$("#select_roleId_roleAuth_tab").append('<option value="0" disabled>請先新增角色</option>');
$("#select_roleId_roleAuth_tab").val($("#select_roleId_roleAuth_tab option:first").val()).trigger('change');
}
//#endregion
});
});
//#endregion
//#region 切換頁簽判斷被選中的tab
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
selected_tab = $(e.target).attr("href")
switch (selected_tab) {
case "#tab-user-manager":
userTable.ajax.reload();
break;
case "#tab-role-manager":
roleTable.ajax.reload();
break;
case "#tab-role-auth":
roleAuthTable.ajax.reload();
break;
}
});
//#endregion
//#region 使用者列表 DataTable
userTable = $("#user_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": false,
"deferLoading": 0,
"order": [[7, "desc"]],
"columns": [{
"data": "id"
}, {
"data": "companyName"
}, {
"data": "name"
}, {
"data": "roleName"
}, {
"data": "email"
}, {
"data": "phone"
}, {
"data": "spStationAmount"
}, {
"data": "createdAt"
}, {
"data": null,
"defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
}
],
"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": "/User/UserList",
"type": "POST",
"data": function (d) {
d.SelectedCompanyId = $('#select_user_company_userManager_tab').val();
d.Name = $('#user_name').val();
d.SelectedRoleId = $('#select_company_role_userManager_tab').val();
},
"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
roleTable = $("#role_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": false,
"deferLoading": 0,
"order": [[4, "desc"]],
"columns": [{
"data": "id"
}, {
"data": "companyName"
}, {
"data": "name"
}, {
"data": "creatorName"
}, {
"data": "createdAt"
}, {
"data": null,
"defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
}
],
"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": "/Role/RoleList",
"type": "POST",
"data": function (d) {
d.SelectedCompanyId = $('#select_company_role_roleManager_tab').val();
d.Name = $('#role_name').val();
},
"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
roleAuthTable = $("#roleAuth_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": false,
"deferLoading": 0,
"order": [[5, "desc"]],
"columns": [{
"data": "id"
}, {
"data": "companyName"
}, {
"data": "roleName"
}, {
"data": "authPageSubName"
}, {
"data": "creatorName"
}, {
"data": "createdAt"
}, {
"data": null,
"defaultContent": '<button class="btn btn-danger del-btn">刪除</button>'
}
],
"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-authCode', data.id + "_" + data.authCode);
},
"ajax": {
"url": "/Role/RoleAuthList",
"type": "POST",
"data": function (d) {
d.SelectedCompanyId = $('#select_companyId_roleAuth_tab').val();
d.SelectedRoleId = $('#select_roleId_roleAuth_tab').val();
},
"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
roleAuthNotJoinTable = $("#roleAuth_NotJoin_table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": false,
"deferLoading": 0,
"order": [[1, "desc"]],
"columns": [{
"data": "authCode"
}, {
"data": "mainName"
}, {
"data": "subName"
}],
"columnDefs": [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'dt-body-center',
'render': function (data, type, full, meta) {
var check_html = "";
check_html += '<div class="custom-control custom-checkbox">';
check_html += '<input type="checkbox" class="custom-control-input" name="selectedAuthPage[]" id="auth-page-' + data + '" value="' + data + '" /> ';
check_html += '<label class="custom-control-label" for="auth-page-' + data + '" />';
check_html += '</div>';
return check_html;
}
}],
"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-authCode', data.id + "_" + data.authCode);
},
"ajax": {
"url": "/Role/GetRoleNotAuthPageList",
"type": "POST",
"data": function (d) {
d.SelectedCompanyId = $('#select_companyId_roleAuth_tab').val();
d.SelectedRoleId = $('#select_roleId_roleAuth_tab').val();
},
"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 帳號管理Tab
//#region 搜尋使用者列表
function SearchUser() {
userTable.ajax.reload();
}
//#endregion
//#region 新增使用者
function AddUser() {
selected_id = 0;
$("#user-modal .modal-title").html("人員基本資料 - 新增");
$("#user-form").trigger("reset");
$("#user_companyId_modal").val($("#select_user_company_userManager_tab").val());
$("#user_account_modal").prop("disabled", false);
$(".user_account_same_email_div").show();
$("#user_account_same_email").prop("disabled", false);
$(".user_password_form_row").show();
$("#user-modal").modal();
}
//#endregion
//#region 帳號是否等同Email
$('#user_account_same_email').change(function () {
var email = $("#user_email_modal").val();
if (email == undefined || email == null || email == "") {
toast_warning("請先填寫email");
$(this).prop("checked", false);
return;
}
if (this.checked && selected_id == 0) {
//只提供新增時可透過email填入帳號欄位
$("#user_account_modal").val(email);
$("#user_account_modal").prop("disabled", true);
}
else {
$("#user_account_modal").prop("disabled", false);
}
});
//#endregion
//#region 編輯系統管理員
$('#user_table').on("click", "button.edit-btn", function () {
$("#user-modal .modal-title").html("人員基本資料 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
//取得單一系統管理員
var url = "/User/GetOneUser/";
var send_data = {
id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else if (rel.code == "9998") {
toast_error(rel.msg);
return;
}
$("#user_companyId_modal").val(rel.data.companyId);
$("#user_companyId_modal").prop("disabled", true);
$("#user_name_modal").val(rel.data.name);
$("#user_email_modal").val(rel.data.email);
$("#user_account_modal").val(rel.data.account);
$("#user_account_modal").prop("disabled", true);
$(".user_account_same_email_div").hide();
$("#user_account_same_email").prop("disabled", true);
$(".system_admin_password_form_row").hide();
$("#user_phone_modal").val(rel.data.phone);
$("#user_role_modal").val(rel.data.roleId);
$("#user-modal").modal();
}, 'json');
});
//#endregion
//#region 使用者表單驗證
$("#user-form").validate({
rules: {
user_name_modal: {
required: true,
},
user_email_modal: {
required: true,
email: true,
},
user_account_modal: {
required: true,
},
},
});
//#endregion
//#region 儲存使用者
function SaveUser() {
if ($("#user-form").valid()) {
var url = "/User/SaveUser";
var send_data = {
Id: selected_id,
CompanyId: $("#user_companyId_modal").val(),
Name: $("#user_name_modal").val(),
Email: $("#user_email_modal").val(),
Account: $("#user_account_modal").val(),
Phone: $("#user_phone_modal").val(),
RoleId: $("#user_role_modal").val()
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else if (rel.code == "9998") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
$('#user-modal').modal('hide');
//更新當前剩餘可註冊使用者人數
UpdateRegisterNumber($("#user_companyId_modal").val());
userTable.ajax.reload();
}, 'json');
}
}
//#endregion
//#region 刪除使用者
$('#user_table').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
//取得單一系統管理員
var url = "/User/DeleteOneUser/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
//更新當前剩餘可註冊使用者人數
UpdateRegisterNumber($("#select_user_company_userManager_tab").val());
userTable.ajax.reload();
}, 'json');
});
//#endregion
//#region 更新公司當前剩餘註冊數量
function UpdateRegisterNumber(companyId) {
var url = "/Company/GetRemainingRegisterNumber"
var send_data = {
Id: companyId
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#remaining-number").html(rel.data);
if (rel.data <= 0) {
$("#addUser-btn").hide();
} else {
$("#addUser-btn").show();
}
}, 'json');
}
//#endregion
//#endregion
//#region 角色管理Tab
//#region 搜尋角色列表
function SearchRole() {
roleTable.ajax.reload();
}
//#endregion
//#region 新增公司角色
function AddRole() {
selected_role_id = 0;
$("#role-modal .modal-title").html("人員基本資料 - 新增");
$("#role-form").trigger("reset");
$("#role_companyId_modal").val($("#select_company_role_roleManager_tab").val());
$("#role-modal").modal();
}
//#endregion
//#region 編輯公司角色
$('#role_table').on("click", "button.edit-btn", function () {
$("#role-modal .modal-title").html("角色資料 - 編輯");
selected_role_id = $(this).parents('tr').attr('data-id');
//取得單一公司角色資料
var url = "/Role/GetOneRole/";
var send_data = {
id: selected_role_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else if (rel.code == "9998") {
toast_error(rel.msg);
return;
}
$("#role_companyId_modal").val(rel.data.companyId);
$("#role_companyId_modal").prop("disabled", true);
$("#role_name_modal").val(rel.data.name);
$("#role-modal").modal();
}, 'json');
});
//#endregion
//#region 公司角色表單驗證
$("#role-form").validate({
rules: {
role_name_modal: {
role_companyId_modal: true,
},
role_name_modal: {
required: true,
},
},
});
//#endregion
//#region 儲存公司角色
function SaveRole() {
if ($("#role-form").valid()) {
var url = "/Role/SaveRole";
var send_data = {
Id: selected_role_id,
CompanyId: $("#role_companyId_modal").val(),
Name: $("#role_name_modal").val(),
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
$('#role-modal').modal('hide');
roleTable.ajax.reload();
}, 'json');
}
}
//#endregion
//#region 刪除公司角色
$('#role_table').on("click", "button.del-btn", function () {
selected_role_id = $(this).parents('tr').attr('data-id');
//取得單一系統管理員
var url = "/Role/DeleteOneRole/";
var send_data = {
Id: selected_role_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
roleTable.ajax.reload();
}, 'json');
});
//#endregion
//#endregion
//#region 角色權限Tab
//#region 搜尋角色權限列表
function SearchRoleAuth() {
roleAuthTable.ajax.reload();
}
//#endregion
//#region 新增角色權限
function AddRoleAuth() {
roleAuthNotJoinTable.ajax.reload();
$("#role-auth-modal").modal();
}
//#endregion
//#region 儲存角色權限
function SaveRoleAuth() {
//取得被選擇的角色權限
var checkAuths = $("input[name='selectedAuthPage[]']:checked").map(function () {
return $(this).val();
}).get();
var url = "/Role/SaveRoleAuth";
var send_data = {
SelectedRoleId: $("#select_roleId_roleAuth_tab").val(),
CheckAuths: checkAuths
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
$("#role-auth-modal").modal('hide');
roleAuthTable.ajax.reload();
}, 'json');
}
//#endregion
//#region 刪除公司角色權限
$('#roleAuth_table').on("click", "button.del-btn", function () {
var row_id_authCode = $(this).parents('tr').attr('data-id-authCode');
var split_arr = row_id_authCode.split("_");
//取得單一系統管理員
var url = "/Role/DeleteOneRoleAuth/";
var send_data = {
RoleId: split_arr[0],
AuthCode: split_arr[1]
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
roleAuthTable.ajax.reload();
}, 'json');
});
//#endregion
//#endregion
</script>
}