dialogtree.blade.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <a href="javascript:void(0)" class="grid-dialog-tree"
  2. data-url="{{ $url }}"
  3. data-title="{{ $title }}"
  4. data-checked="{{ $checkAll }}"
  5. data-val="{{ $value }}">
  6. <i class='feather icon-align-right'></i> {{ trans('admin.view') }}
  7. </a>
  8. <template>
  9. <template id="dialog-tree-tpl">
  10. <div class="jstree-wrapper p-1" style="border:0"><div class="da-tree" style="margin-top:10px"></div></div>
  11. </template>
  12. </template>
  13. <script require="@jstree" once>
  14. window.resolveDialogTree = function (options) {
  15. var tpl = $('#dialog-tree-tpl').html(),
  16. t = $(this),
  17. val = t.data('val'),
  18. url = t.data('url'),
  19. title = t.data('title'),
  20. ckall = t.data('checked'),
  21. idx,
  22. loading;
  23. val = val ? String(val).split(',') : [];
  24. if (url) {
  25. if (loading) return;
  26. loading = 1;
  27. t.buttonLoading();
  28. $.ajax(url, {data: {value: val}}).then(function (resp) {
  29. loading = 0;
  30. t.buttonLoading(false);
  31. if (!resp.status) {
  32. return Dcat.error(resp.message || '系统繁忙,请稍后再试');
  33. }
  34. open(resp.value);
  35. });
  36. } else {
  37. open(val);
  38. }
  39. function open(val) {
  40. options.config.core.data = formatNodes(val, options.nodes);
  41. idx = layer.open({
  42. type: 1,
  43. area: options.area,
  44. content: tpl,
  45. title: title,
  46. success: function (a, idx) {
  47. var tree = $('#layui-layer'+idx).find('.da-tree');
  48. tree.on("loaded.jstree", function () {
  49. tree.jstree('open_all');
  50. }).jstree(options.config);
  51. }
  52. });
  53. $(document).one('pjax:complete', function () {
  54. layer.close(idx);
  55. });
  56. }
  57. function formatNodes(value, all) {
  58. var idColumn = options.columns.id,
  59. textColumn = options.columns.text,
  60. parentColumn = options.columns.parent,
  61. nodes = [], i, v, parentId;
  62. for (i in all) {
  63. v = all[i];
  64. if (!v[idColumn]) continue;
  65. parentId = v[parentColumn] || '#';
  66. if (!parentId || parentId == options.rootParentId || parentId == '0') {
  67. parentId = '#';
  68. }
  69. v['state'] = {'disabled': true};
  70. if (ckall || (value && Dcat.helpers.inObject(value, v[idColumn]))) {
  71. v['state']['selected'] = true;
  72. }
  73. nodes.push({
  74. 'id' : v[idColumn],
  75. 'text' : v[textColumn] || null,
  76. 'parent' : parentId,
  77. 'state' : v['state'],
  78. });
  79. }
  80. return nodes;
  81. }
  82. }
  83. </script>
  84. <script require="@jstree">
  85. var nodes = {!! json_encode($nodes) !!};
  86. var options = {!! admin_javascript_json($options) !!};
  87. var area = {!! json_encode($area) !!};
  88. $('.grid-dialog-tree').off('click').on('click', function () {
  89. resolveDialogTree.call(this, {config: options, nodes: nodes, area: area, rootParentId: '{!! $rootParentId !!}', columns: {!! json_encode($columnNames) !!}});
  90. });
  91. </script>