organization.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <!--
  2. * guoj
  3. * 2018.11.01
  4. * 组织管理
  5. -->
  6. <style>
  7. .btn-group {
  8. width: 100%;
  9. padding-right: 10px;
  10. padding-top: 10px;
  11. text-align: right;
  12. }
  13. #org_ref,
  14. #org_save {
  15. background-color: #1E90FF;
  16. }
  17. #organ_Tree {
  18. width: 25%;
  19. height: 500px;
  20. border: 1px solid #ccc;
  21. float: left;
  22. overflow: hidden;
  23. margin-top: 10px;
  24. padding: 10px;
  25. }
  26. #organ_Form {
  27. width: 72%;
  28. height: 500px;
  29. margin-left: 10px;
  30. margin-top: 10px;
  31. border: 1px solid #ccc;
  32. float: left;
  33. padding: 10px;
  34. font-size: 16px;
  35. }
  36. </style>
  37. <div id="systemUserList" class="plg-tab-container">
  38. <div class="grid-container-full">
  39. <div class="plg-grid-panel">
  40. <div class="btn-group">
  41. <button class="layui-btn layui-btn-sm" id="org_ref"><i class=" layui-icon ">&#xe669;</i> 刷新</button>
  42. <button class="layui-btn layui-btn-sm " id="org_save"><i class="layui-icon">&#xe605;</i> 保存</button>
  43. </div>
  44. <div id="organ_Tree"></div>
  45. <div id="organ_Form"></div>
  46. </div>
  47. </div>
  48. </div>
  49. <script type="text/javascript">
  50. /**
  51. * guoj
  52. * 2018.11.01
  53. * 组织管理
  54. */
  55. (function () {
  56. var tree2;
  57. //数据
  58. var datas;
  59. var updata_tree;
  60. //新增节点
  61. var add_newTreeNode = "";
  62. var confing2 = {
  63. isExpand: true, //是否初始化时展开第一个父节点的所有内容
  64. renderer: "organ_Tree",
  65. skin: "menu-tree",
  66. initAjax: {
  67. url: "/api/service-users/organization/getOrganization/v1.0",
  68. type: "post"
  69. },
  70. toolBar: true,
  71. setting: {
  72. async: {
  73. enable: true,
  74. url: "/api/service-users/organization/getOrganizationByFatherid/v1.0",
  75. type: "post",
  76. contentType: "application/x-www-form-urlencoded",
  77. autoParam: ["p_id=p_fatherid"],
  78. dataFilter: function (reeId, parentNode, responseData) {
  79. responseData.data.forEach(function (item) {
  80. item.isParent = !item.p_leaf
  81. });
  82. return responseData.data
  83. },
  84. headers: {
  85. "Authorization": token
  86. }
  87. },
  88. check: {
  89. enable: true
  90. },
  91. data: {
  92. key: {
  93. name: "p_name",
  94. },
  95. simpleData: {
  96. enable: true,
  97. idKey: "p_id",
  98. pIdKey: "p_fatherid",
  99. rootPId: "0",
  100. id: 'p_id',
  101. }
  102. },
  103. callback: {
  104. //单击事件的回调
  105. onClick: function (event, treeId, treeNode) {
  106. getData(treeNode.p_id, treeNode);
  107. },
  108. //复选框的回调
  109. onCheck: function (e, treeId, treeNode) {
  110. // var zTree = this.getZTreeObj(treeId);
  111. //var nodes = zTree.getSelectedNodes();
  112. //console.log('treeNode :', treeNode);
  113. //console.log(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
  114. },
  115. }
  116. }
  117. };
  118. var tree2 = new PlgZtree(confing2);
  119. var orgForm_opt = {
  120. renderer: 'organ_Form',
  121. items: [
  122. { type: "settings", position: "label-left", labelWidth: 80, inputWidth: 270 },
  123. { type: "input", name: "p_id", label: "组织id:", editable: false, validate: "NotEmpty", required: true },
  124. { type: "input", name: "p_name", label: "名称:" },
  125. { type: "input", name: "p_fatherid", label: "父级组织:", editable: false, validate: "NotEmpty", required: true },
  126. { type: 'newcolumn', offset: 10 },
  127. { type: "input", name: "p_enterpriseid", label: "企业id:" },
  128. { type: "input", name: "p_lelve", label: "层级:", editable: false, validate: "NotEmpty", required: true },
  129. { type: "checkbox", name: "p_status", label: "是否启用:" }
  130. ]
  131. };
  132. var orgForm = new PlgForm(orgForm_opt);
  133. orgForm.disableItem("p_fatherid");
  134. orgForm.disableItem("p_lelve");
  135. orgForm.disableItem("p_createtime");
  136. orgForm.disableItem("p_lastmodifytime");
  137. orgForm.disableItem("p_creatorid");
  138. orgForm.disableItem("p_creatorname");
  139. //添加菜单事件
  140. tree2.on("addTreeNodeClick", function (event, zTree, treeNode) {
  141. if (add_newTreeNode != "") {
  142. layer.msg("请保存后新增")
  143. return;
  144. }
  145. nodeObj.isParent = false;
  146. if (!treeNode) {
  147. nodeObj.isParent = true;
  148. nodeObj.parentMenuId = 0;
  149. nodeObj.p_lelve = 1;
  150. } else {
  151. nodeObj.parentMenuId = treeNode.p_id;
  152. nodeObj.p_fatherid = treeNode.p_id;
  153. nodeObj.id = new Date();
  154. nodeObj.p_lelve = parseInt(treeNode.p_lelve) + 1;
  155. }
  156. add_newTreeNode = zTree.addNodes(treeNode, nodeObj);
  157. zTree.selectNode(add_newTreeNode[0]);
  158. orgForm.clear();
  159. orgForm.setFormData(nodeObj);
  160. })
  161. //删除菜单事件
  162. tree2.on("delTreeNodeClick", function (event, zTree, treeNode) {
  163. if (treeNode.length > 0) {
  164. layer.confirm(`确认删除"${treeNode[0].p_name}"吗?`, function (index) {
  165. if (treeNode[0].p_createtime != null || treeNode[0].p_createtime != "") {
  166. var data = treeNode[0].p_id;
  167. data = { "p_id": data };
  168. utilAjaxGJ("/api/service-users/organization/deleteOrganization/v1.0", "put", data, function (data) {
  169. layer.msg(data.message);
  170. orgForm.clear();
  171. });
  172. }
  173. layer.close(index)
  174. zTree.removeNode(treeNode[0]);
  175. });
  176. } else {
  177. layer.alert("请选择删除项")
  178. }
  179. })
  180. var nodeObj = {
  181. //id
  182. id: Prolog.createRandomId(),
  183. name: "新菜单",
  184. systemId: null,
  185. //菜单id
  186. menuId: "m00" + Prolog.createRandomId(),
  187. parentMenuId: null,
  188. operateType: 0,
  189. level: 1,
  190. enable: true,
  191. leaf: false,
  192. path: "cyhx",
  193. sort: 0,
  194. //父级id
  195. p_fatherid: Prolog.createRandomId(),
  196. // p_id: Prolog.createRandomId(),
  197. p_name: "新菜单",
  198. };
  199. //保存
  200. document.querySelector("#org_save").onclick = function () {
  201. //如果设定了yes回调,需进行手工关闭
  202. var datas = orgForm.getFormData();
  203. var feik = orgForm.validate();
  204. if (!feik) {
  205. return;
  206. }
  207. if (datas.path == "cyhx") {
  208. utilAjaxGJ("/api/service-users/organization/insertOrganization/v1.0", "post", datas, function (data) {
  209. layer.msg(data.message);
  210. getData(data.data.p_id, "treeNode", 1);
  211. });
  212. return;
  213. } else {
  214. utilAjaxGJ("/api/service-users/organization/updateOrganization/v1.0", "put", datas, function (data) {
  215. layer.msg(data.message);
  216. getData(datas.p_id, "treeNode", 2);
  217. });
  218. }
  219. }
  220. //刷新
  221. document.querySelector("#org_ref").onclick = function () {
  222. layer.msg("刷新成功");
  223. }
  224. //根据id查询数据
  225. function getData(id, treeNode, type) {
  226. orgForm.clear();
  227. if (treeNode.path == "cyhx") {
  228. orgForm.setFormData(nodeObj);
  229. }
  230. utilSyncAjaxGJ("/api/service-users/organization/getPlgFxOrganizationById/v1.0", "get", { p_id: id }, function (data) {
  231. var datass = data.data;
  232. orgForm.setFormData(datass);
  233. if (type == 1) {
  234. for (var key in datass) {
  235. add_newTreeNode[0][key] = datass[key];
  236. }
  237. tree2.treeObj.updateNode(add_newTreeNode[0]);
  238. add_newTreeNode = "";
  239. }
  240. if (type == 2) {
  241. var nodes = tree2.treeObj.getSelectedNodes();
  242. for (var key in datass) {
  243. nodes[0][key] = datass[key];
  244. }
  245. tree2.treeObj.updateNode(nodes[0]);
  246. }
  247. });
  248. }
  249. })()
  250. </script>