PerAllocation.cshtml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. @{
  2. ViewBag.Title = "分配权限";
  3. Layout = "~/Views/Shared/_Layout.cshtml";
  4. }
  5. @using MES.Production.Service;
  6. @using Central.Control.Domain;
  7. @using Ant.Service.Common;
  8. @using Ant.Service.Common.Enums;
  9. <style type="text/css">
  10. body {
  11. background-color: #fff;
  12. }
  13. .tn {
  14. text-align: center !important;
  15. }
  16. .ckcenter {
  17. margin: 6px auto !important;
  18. }
  19. .table tbody tr td {
  20. padding: 5px 3px !important;
  21. vertical-align: middle;
  22. text-align: left;
  23. }
  24. .table tbody tr td a {
  25. margin-left: 10px;
  26. }
  27. .permissionlist span {
  28. margin-right: 5px;
  29. margin-bottom: 2px;
  30. color: #1ab394;
  31. vertical-align: middle;
  32. text-align: center;
  33. line-height: 25px;
  34. cursor: pointer;
  35. }
  36. .permissionlist span input[type=checkbox] {
  37. margin-top: -4px;
  38. }
  39. </style>
  40. <!-- table star -->
  41. <div class="row col-lg-12" style="height:420px; overflow-y:scroll;">
  42. <!-- search star -->
  43. @using (Ajax.BeginForm("PerAllocation", null, new AjaxOptions() { }, new { @id = "form1", @class = "form-horizontal", @method = "post" }))
  44. {
  45. @Html.Hidden("tp", ViewData["PermissionType"])
  46. @Html.Hidden("id", ViewData["objId"])
  47. <div class="form-horizontal clearfix">
  48. <div class="col-lg-4 col-sm-3 pl0" style="width:50%;">
  49. <div class="form-group">
  50. <label class="control-label" style="width:70px; float:left;">系统:</label>
  51. <div class="col-lg-8 col-sm-7" style="width:300px !important;">
  52. <select id="System" name="System" class="form-control" onchange="submit()">
  53. @{
  54. foreach (var item in ViewData["Systemlist"] as dynamic)
  55. {
  56. <option value="@item.ID" @(ViewData["System"] != null && ViewData["System"].ToString() != "" && ViewData["System"].ToString() == item.ID ? "selected=\"selected\"" : "")>@item.NAME</option>
  57. }
  58. }
  59. </select>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="col-lg-4 col-sm-4">
  64. <div class="form-group">
  65. <div class="col-lg-12 col-sm-12 input-group">
  66. @Html.TextBox("Search", ViewData["Search"], new { @class = "input-sm form-control", @placeholder = "请输入查询模块关键词" })
  67. <span class="input-group-btn">
  68. <button type="button" onclick="submit()" class="btn btn-sm btn-primary"> 搜索</button>
  69. </span>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. }
  75. <!-- search end -->
  76. <div id="example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
  77. <table class="table table-striped table-bordered table-hover dataTables-example dataTable" cellspacing="0" width="100%">
  78. <thead>
  79. <tr>
  80. <th class="tn">@*<input id="checkall" class="ckcenter" type="checkbox" value="">*@</th>
  81. <th style="width:150px !important;">模块名称</th>
  82. <th>权限</th>
  83. </tr>
  84. </thead>
  85. <tbody>
  86. @{
  87. var module = ViewData["ModuleList"] as dynamic;
  88. var permission = ViewData["PermissionList"] as List<SYS_PERMISSION>;
  89. var selectper = ViewData["selectper"] as List<string>;
  90. if (module != null)
  91. {
  92. foreach (var item in module)
  93. {
  94. <tr>
  95. <td class="tn">
  96. <input name="ckb_module" class="ckcenter" type="checkbox" value="@item.ID" data-parent="@item.PARENTID" data-level="@item.LEVELS">
  97. </td>
  98. <td><a href="javascript:void(0)"><i class="@item.ICON"></i>@item.ID@Html.Raw(item.MODULENAME)</a></td>
  99. <td>
  100. <div class="permissionlist">
  101. @{
  102. if (permission != null && permission.Count > 0 && permission.FindAll(p => p.MODULEID == item.ID).Count > 0)
  103. {
  104. foreach (var per in permission.FindAll(p => p.MODULEID == item.ID))
  105. {
  106. var sel = selectper.Find(p => p == per.ID.ToString());
  107. <span>
  108. <input name="ckb_per" type="checkbox" value="@per.ID" @(sel != null ? "checked" : "") />
  109. <i class="@per.ICON"></i>@per.NAME
  110. </span>
  111. }
  112. }
  113. }
  114. </div>
  115. </td>
  116. </tr>
  117. }
  118. }
  119. }
  120. </tbody>
  121. </table>
  122. </div>
  123. </div>
  124. <div class="hr-line-dashed">
  125. <div class="form-group" style="margin-top:10px !important;">
  126. <div class="col-sm-2 col-sm-offset-2">
  127. <button class="btn btn-primary btn-save" type="submit"><i class="fa fa-check"></i> <span>确定保存</span></button>
  128. <button class="btn btn-warning" id="btn-dig-close" type="button"><i class="im-undo2"></i> 取消返回</button>
  129. </div>
  130. </div>
  131. </div>
  132. <!-- table end -->
  133. @section scripts{
  134. <script type="text/javascript">
  135. $('#btn-dig-close').click(function () {
  136. dig.remove();
  137. });
  138. $(function () {
  139. //全选 反选
  140. $('input[id="checkall"]').change(function () {
  141. if ($(this).prop("checked")) {
  142. $("input[name='ckb_module']:checkbox,input[id='checkall']:checkbox").each(function () {
  143. if ($(this).prop("checked") == false) {
  144. $(this).prop("checked", true);
  145. $('.ckcenter').each(function () {
  146. $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]:checkbox').prop('checked', true);
  147. });
  148. }
  149. });
  150. }
  151. else {
  152. $("input[name='ckb_module']:checkbox,input[id='checkall']:checkbox").each(function () {
  153. if ($(this).prop("checked") == true) {
  154. $(this).prop("checked", false);
  155. $('.ckcenter').each(function () {
  156. $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]:checkbox').prop('checked', false);
  157. });
  158. }
  159. });
  160. }
  161. });
  162. //权限 选中 反选
  163. $('.permissionlist span').click(function () {
  164. var ckb = $(this).find('input[name="ckb_per"]');
  165. if (ckb.prop('checked') == true) {
  166. ckb.prop('checked', false);
  167. } else {
  168. ckb.prop('checked', true);
  169. }
  170. });
  171. //递归子节点的ParentId
  172. function GetParentModuleId(t, s) {
  173. $('input[name="ckb_module"]').each(function () {
  174. if ($(this).attr('data-parent') == t) {
  175. s += $(this).attr('value') + ',';
  176. GetParentModuleId($(this).attr('value'), s);
  177. }
  178. });
  179. //alert(s);
  180. return s;
  181. }
  182. //选择模块 选中权限
  183. $('.ckcenter').bind('change', function () {
  184. //选中
  185. if ($(this).prop('checked') == true) {
  186. //选中当前模块下的权限
  187. $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]').prop('checked', true);
  188. //选中当前模块下级模块的权限
  189. var moduleId = $(this).attr('value') + ',';
  190. moduleId = GetParentModuleId($(this).attr('value'), moduleId);
  191. //alert(moduleId);
  192. $('input[name="ckb_module"]').each(function () {
  193. var parentId = $(this).attr('data-parent');
  194. if (parentId != '') {
  195. var arr = moduleId.split(',');
  196. for (var i = 0; i < arr.length; i++) {
  197. if (arr[i] == parentId) {
  198. $(this).prop('checked', true);
  199. $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]').prop('checked', true);
  200. }
  201. }
  202. }
  203. });
  204. } else {
  205. //取消选中当前模块下的权限
  206. $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]').prop('checked', false);
  207. //取消选中当前模块下级模块的权限
  208. var moduleId = $(this).attr('value') + ',';
  209. moduleId = GetParentModuleId($(this).attr('value'), moduleId);
  210. $('input[name="ckb_module"]').each(function () {
  211. var parentId = $(this).attr('data-parent');
  212. if (parentId != '') {
  213. var arr = moduleId.split(',');
  214. for (var i = 0; i < arr.length; i++) {
  215. if (arr[i] == parentId) {
  216. $(this).prop('checked', false);
  217. $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]').prop('checked', false);
  218. }
  219. }
  220. }
  221. //上面更改,下面原来的有Bug,自增长id会存在23,和3,判断会进去,改进之后就不存在
  222. //if (parentId != '' && moduleId.indexOf(parentId) > -1) {
  223. // $(this).prop('checked', false);
  224. // $(this).parent().next().next().find('.permissionlist').find('input[name="ckb_per"]').prop('checked', false);
  225. //}
  226. });
  227. }
  228. });
  229. //提交保存
  230. $('.btn-save').click(function () {
  231. var perid = '';
  232. $('input[name="ckb_per"]:checked').each(function () {
  233. perid += $(this).attr('value') + ',';
  234. });
  235. $.post('/Sys/Permission/SaveAllocation', {
  236. tp: $('#tp').val(),
  237. id: $('#id').val(),
  238. system: $('#System').val(),
  239. perid: perid
  240. }, function (result) {
  241. if (result.Status == 'y') {
  242. dig.alertSuccess("提示", result.Msg, function () {
  243. var dialog = top.dialog.get(window);
  244. dialog.close('yes').remove();
  245. });
  246. } else {
  247. dig.alertError("提示:", result.Msg);
  248. }
  249. }, 'json');
  250. });
  251. });
  252. </script>
  253. }