apply.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {extend name='main'}
  2. {block name="content"}
  3. <div class="think-box-shadow">
  4. <ul id="zTree" class="ztree notselect"></ul>
  5. <div class="hr-line-dashed"></div>
  6. <div class="layui-form-item text-center">
  7. <button class="layui-btn" data-submit-role type='button'>保存数据</button>
  8. <button class="layui-btn layui-btn-danger" type='button' onclick="window.history.back()">取消编辑</button>
  9. </div>
  10. </div>
  11. {/block}
  12. {block name="script"}
  13. <script>
  14. window.RoleAction = new function () {
  15. this.data = {}, this.ztree = null;
  16. this.setting = {
  17. view: {showLine: false, showIcon: false, dblClickExpand: false},
  18. check: {enable: true, nocheck: false, chkboxType: {"Y": "ps", "N": "ps"}},
  19. callback: {
  20. beforeClick: function (id, node) {
  21. node.children.length < 1 ? RoleAction.ztree.checkNode(node, !node.checked, null, true) : RoleAction.ztree.expandNode(node);
  22. return false;
  23. }
  24. }
  25. };
  26. this.renderChildren = function (list, level) {
  27. var childrens = [];
  28. for (var i in list) childrens.push({
  29. open: true, node: list[i].node, name: list[i].title || list[i].node,
  30. checked: list[i].checked || false, children: this.renderChildren(list[i]._sub_, level + 1)
  31. });
  32. return childrens;
  33. };
  34. this.getData = function (that) {
  35. $.form.load('{:url("apply")}', {id: '{$vo.id}', action: 'get'}, 'post', function (ret) {
  36. return (that.data = that.renderChildren(ret.data, 1)), that.showTree(), false;
  37. });
  38. };
  39. this.showTree = function () {
  40. this.ztree = $.fn.zTree.init($("#zTree"), this.setting, this.data);
  41. while (true) {
  42. var nodes = this.ztree.getNodesByFilter(function (node) {
  43. return (!node.node && node.children.length < 1);
  44. });
  45. if (nodes.length < 1) break;
  46. for (var i in nodes) this.ztree.removeNode(nodes[i]);
  47. }
  48. };
  49. this.submit = function () {
  50. var nodes = [], data = this.ztree.getCheckedNodes(true);
  51. for (var i in data) if (data[i].node) nodes.push(data[i].node);
  52. $.form.load('{:url("apply")}', {id: '{$vo.id}', action: 'save', nodes: nodes}, 'post');
  53. };
  54. // 刷新数据
  55. this.getData(this);
  56. // 提交表单
  57. $('[data-submit-role]').on('click', function () {
  58. RoleAction.submit();
  59. });
  60. };
  61. </script>
  62. {/block}
  63. {block name="style"}
  64. <link href="__ROOT__/static/plugs/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet">
  65. <script src="__ROOT__/static/plugs/ztree/ztree.all.min.js"></script>
  66. <style>
  67. ul.ztree li {
  68. white-space: normal !important;
  69. }
  70. ul.ztree li span.button.switch {
  71. margin-right: 5px;
  72. }
  73. ul.ztree ul ul li {
  74. display: inline-block;
  75. white-space: normal;
  76. }
  77. ul.ztree > li {
  78. padding: 15px 25px 15px 15px;
  79. }
  80. ul.ztree > li > ul {
  81. margin-top: 12px;
  82. border-top: 1px solid rgba(0, 0, 0, .1);
  83. }
  84. ul.ztree > li > ul > li {
  85. padding: 5px;
  86. }
  87. ul.ztree > li > a > span {
  88. font-weight: 700;
  89. font-size: 15px;
  90. }
  91. ul.ztree .level2 .button.level2 {
  92. background: 0 0;
  93. }
  94. </style>
  95. {/block}