apply.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. require(['jquery.ztree'], function () {
  15. new function () {
  16. var that = this;
  17. this.data = {}, this.ztree = null, this.setting = {
  18. view: {showLine: false, showIcon: false, dblClickExpand: false},
  19. check: {enable: true, nocheck: false, chkboxType: {"Y": "ps", "N": "ps"}}, callback: {
  20. beforeClick: function (id, node) {
  21. node.children.length < 1 ? that.ztree.checkNode(node, !node.checked, null, true) : that.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 () {
  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();
  56. // 提交表单
  57. $('[data-submit-role]').on('click', function () {
  58. that.submit();
  59. });
  60. };
  61. });
  62. </script>
  63. {/block}
  64. {block name="style"}
  65. <style>
  66. ul.ztree li {
  67. white-space: normal !important;
  68. }
  69. ul.ztree li span.button.switch {
  70. margin-right: 5px;
  71. }
  72. ul.ztree ul ul li {
  73. display: inline-block;
  74. white-space: normal;
  75. }
  76. ul.ztree > li {
  77. padding: 15px 25px 15px 15px;
  78. }
  79. ul.ztree > li > ul {
  80. margin-top: 12px;
  81. border-top: 1px solid rgba(0, 0, 0, .1);
  82. }
  83. ul.ztree > li > ul > li {
  84. padding: 5px;
  85. }
  86. ul.ztree > li > a > span {
  87. font-weight: 700;
  88. font-size: 15px;
  89. }
  90. ul.ztree .level2 .button.level2 {
  91. background: 0 0;
  92. }
  93. </style>
  94. {/block}