_Organization.cshtml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. @using ContractService.Configuration
  2. @using ContractService.Helpers
  3. @using ContractService.Views.Shared.Modals
  4. @using ContractService.Views.Shared.Table
  5. @{
  6. string companyNo = ViewBag.CompanyNo ?? "", lawFirmNo = ViewBag.LawFirmNo ?? "";
  7. var table = new TableViewModel(IwbConsts.ApiAppUrl + "Organization/GetAll", ViewBag.ActiveMenu)
  8. .SetFields(new List<FieldItem>()
  9. {
  10. new FieldItem("name", "部门名称", align: "left"),
  11. new FieldItem("description", "部门描述"),
  12. new FieldItem("", "操作", "ActionsFormatter"),
  13. }).SetPageArray(10000).SetOther(" data-row-attributes=\"RowAttributes\" "
  14. );
  15. var inputs = new List<Input>()
  16. {
  17. new InputHide("id"),
  18. new InputHide("companyNo"),
  19. new InputHide("lawFirmNo"),
  20. new InputHide("parentNo"),
  21. new Input("parentName", "父部门").SetDisabled(),
  22. new Input("name", "部门名称"),
  23. new InputNumber("sort", "排序序号").SetMin(1),
  24. new InputTextarea("description", "部门描述").SetNotRequired(),
  25. };
  26. var modalBody = new ModalBodyViewModel().AddInputs(inputs);
  27. var modal = new ModalViewModel("部门").SetBody(modalBody);
  28. }
  29. @section css{
  30. }
  31. <link href="~/Content/Libs/jstree/themes/default/style.min.css" rel="stylesheet" />
  32. @Html.Partial("Table/_Table", table)
  33. <!--Modal Start-->
  34. @Html.Partial("Modals/_Modal", modal)
  35. <section>
  36. <!--Auth Modal -->
  37. <div class="modal fade" id="auth_Modal" role="dialog" aria-labelledby="ModalLabel_AUTH" aria-hidden="true">
  38. <div class="modal-dialog" role="document" style="min-height: 700px; width: 500px;">
  39. <div class="modal-content" style="">
  40. @Html.Partial("Modals/_ModalHeader", new ModalHeaderViewModel("部门授权", ""))
  41. <form>
  42. <div class="modal-body" style=" padding: 10px 30px;">
  43. <div class="" id="auth-tree"></div>
  44. </div>
  45. </form>
  46. @Html.Partial("Modals/_ModalFooter", "0")
  47. </div>
  48. </div>
  49. </div>
  50. </section>
  51. <!--Modal End-->
  52. @using (Html.BeginScripts())
  53. {
  54. <script src="~/Content/Libs/jstree/jstree.min.js"></script>
  55. <script type="text/javascript">
  56. var $table = $('#table');
  57. var actions = [], funs = [];
  58. $(function () {
  59. @if (!string.IsNullOrEmpty(companyNo))
  60. {
  61. <text>
  62. funs = LoadTreeTable({
  63. searchList: [{ "KeyField": "companyNo", "KeyWords": '@(companyNo)', "FieldType": 0, "ExpType": 0 }],
  64. idField: 'id',
  65. treeShowField: 'name',
  66. parentIdField: 'parentNo',
  67. customDataField: ['path']
  68. }) ||
  69. { none: function() { console.log("No type"); } };
  70. </text>
  71. }
  72. else if(!string.IsNullOrEmpty(lawFirmNo))
  73. {
  74. <text>
  75. funs = LoadTreeTable({
  76. searchList: [{ "KeyField": "lawFirmNo", "KeyWords": '@(lawFirmNo)', "FieldType": 0, "ExpType": 0 }],
  77. idField: 'id',
  78. treeShowField: 'name',
  79. parentIdField: 'parentNo',
  80. customDataField: ['path']
  81. }) ||
  82. { none: function() { console.log("No type"); } };
  83. </text>
  84. }
  85. var btnCreate = funs['btnCreate'];
  86. funs['btnCreate'] = function(url, id) {
  87. console.log("Add", id);
  88. var row;
  89. if (typeof id === "string" && id !== "") {
  90. row = $table.bootstrapTable("getRowByUniqueId", id);
  91. }
  92. if (row) {
  93. var data = $.extend({}, { parentName: row.name, parentNo: row.id, companyNo: '@(companyNo)', lawFirmNo: '@(lawFirmNo)', sort: 1});
  94. btnCreate(url, data);
  95. } else {
  96. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  97. }
  98. }
  99. var btnUpdate = funs['btnUpdate'];
  100. funs['btnUpdate'] = function(url, id) {
  101. console.log("Edit", id);
  102. var row;
  103. if (typeof id === "string" && id !== "") {
  104. row = $table.bootstrapTable("getRowByUniqueId", id);
  105. }
  106. if (row) {
  107. var data = $.extend({}, row, { parentName: row.parentName ? row.parentName : "根节点", companyNo: '@(companyNo)', lawFirmNo: '@(lawFirmNo)', sort: row.sort});
  108. btnUpdate(url, data);
  109. } else {
  110. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  111. }
  112. }
  113. //var btnOrgAuth = funs['btnUpdate'];
  114. funs['btnOrgAuth'] = function(url, id) {
  115. console.log("Auth", id);
  116. var row;
  117. if (typeof id === "string" && id !== "") {
  118. row = $table.bootstrapTable("getRowByUniqueId", id);
  119. }
  120. if (row) {
  121. var orgId = row.id;
  122. $.iwbAjax4({
  123. url: abp.appUrl + 'Organization/GetPermissions?orgId=' + orgId,
  124. success: function(res) {
  125. $("#auth_Modal").on('show.bs.modal',
  126. function() {
  127. AuthFormatter(res);
  128. $("#auth_Modal").find("button.save-btn").off("click").on("click",
  129. function() {
  130. var authData = GetAuthData(orgId);
  131. $.iwbAjax1({
  132. url: url,
  133. success: function() { $("#auth_Modal").modal("hide"); },
  134. data: authData
  135. });
  136. });
  137. });
  138. $("#auth_Modal").modal("show");
  139. }
  140. });
  141. } else {
  142. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  143. }
  144. }
  145. });
  146. //自定义属性
  147. function RowAttributes(r) {
  148. return {
  149. "data-no": r.id,
  150. "data-parent": r.parentNo
  151. };
  152. }
  153. </script>
  154. <script>
  155. function AuthFormatter(data) {
  156. var authData = [];
  157. authData.push(data);
  158. authData = AuthDataConvert(authData).authData;
  159. console.log(authData);
  160. $("#auth-tree").jstree("destroy");
  161. $("#auth-tree").jstree({
  162. plugins: ["wholerow", "checkbox", "types"],
  163. core: {
  164. themes: {
  165. responsive: false
  166. },
  167. data: authData
  168. },
  169. types: {
  170. default:
  171. {
  172. icon: "fa fa-folder m--font-warning"
  173. },
  174. file: {
  175. icon: "fa fa-file m--font-warning"
  176. }
  177. }
  178. });
  179. //[{
  180. // text: "Same but with checkboxes",
  181. // children: [{
  182. // id:"",
  183. // text: "initially selected",
  184. // state: {
  185. // selected: !0
  186. // opened: !0
  187. // disabled: !0
  188. // }
  189. // }]
  190. // }]
  191. }
  192. function AuthDataConvert(data) {
  193. //console.log(data);
  194. var authData = [], j = 0;
  195. for (var i = 0; i < data.length; i++) {
  196. var item = data[i], newItem = {};
  197. newItem["id"] = item.name;
  198. newItem["text"] = item.permDisplayName;
  199. newItem["icon"] = item.icon + " m--font-warning ";
  200. newItem["state"] = {};
  201. newItem["state"].opened = item.isOpen;
  202. var childResult = { "authData": [], "isAuth": true };
  203. if (item.children && item.children.length > 0) {
  204. childResult = AuthDataConvert(item.children);
  205. newItem["children"] = childResult.authData;
  206. }
  207. if (!(item.isAuth && childResult.isAuth)) {
  208. j++;
  209. }
  210. newItem["state"].selected = item.isAuth && childResult.isAuth;
  211. authData.push(newItem);
  212. }
  213. var result = { "authData": authData, "isAuth": j === 0 };
  214. return result;
  215. }
  216. function GetAuthData(roleId) {
  217. var authData = { Id: roleId, PermissionNames: [] };
  218. var permissionNames = $('#auth-tree').jstree(true).get_selected(false); //获得所有选中节点,返回值为数组
  219. //console.log(1,permissionNames);
  220. //加上灰色的节点
  221. $(".jstree-undetermined").each(function () {
  222. permissionNames.push($(this).parent().parent().attr('id'));
  223. });
  224. //console.log(2,permissionNames);
  225. authData.PermissionNames = permissionNames;
  226. return authData;
  227. }
  228. </script>
  229. <script>
  230. function FunctionCall(type, url, id, that) {
  231. funs[type] ? funs[type].call(this, url, id, that) : funs["none"].call(this);
  232. }
  233. </script>
  234. <script>
  235. //操作按钮
  236. function ActionsFormatter(v, r) {
  237. var str = '<div class="btn-tool">';
  238. for (var i = 0; i < actions.length; i++) {
  239. str += '<span class="table-action" onclick="FunctionCall(\'' +
  240. actions[i]["type"] +
  241. '\',\'' +
  242. actions[i]["url"] +
  243. '\',\'' +
  244. r.id +
  245. '\',this)"><i class="' +
  246. actions[i]["icon"] +
  247. '"></i>' +
  248. actions[i]["name"] +
  249. ' </span>';
  250. }
  251. str += '</div>';
  252. return str;
  253. }
  254. // 格式化类型
  255. function TypeFormatter(v) {
  256. var functionTypeName = $('#hid-functionType option[value="' + v + '"]').text();
  257. switch (v) {
  258. case 9:
  259. return '<span class="label sm label-warning">' + functionTypeName + '</span>';
  260. case 1:
  261. return '<span class="label sm label-danger">' + functionTypeName + '</span>';
  262. case 2:
  263. return '<span class="label sm label-info">' + functionTypeName + '</span>';
  264. case 3:
  265. return '<span class="label sm label-success">' + functionTypeName + '</span>';
  266. default:
  267. return v;
  268. }
  269. }
  270. </script>
  271. }
  272. <section style="display: none">
  273. <select id="hid-type">
  274. <option value=""></option>
  275. </select>
  276. @*@Html.DropDownList("hid-type", type)*@
  277. </section>