dialogtable.blade.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <span>
  2. <span style="cursor: pointer" id="button-{{ $id }}">{!! $button !!}</span>
  3. <template id="temp-{{ $id }}">
  4. <div {!! $attributes !!}>
  5. <div class="p-2 dialog-body">{!! $table !!}</div>
  6. @if($footer)
  7. <div class="dialog-footer layui-layer-btn">{!! $footer !!}</div>
  8. @endif
  9. </div>
  10. </template>
  11. </span>
  12. <script>
  13. var id = replaceNestedFormIndex('{{ $id }}'),
  14. area = screen.width <= 850 ? ['100%', '100%',] : '{{ $width }}',
  15. offset = screen.width <= 850 ? 0 : '70px',
  16. _id, _tempId, _btnId, _tb;
  17. setId(id);
  18. function hidden(index) {
  19. {!! $events['hidden'] !!}
  20. $(_id).trigger('dialog:hidden');
  21. }
  22. function open(btn) {
  23. var index = layer.open({
  24. type: 1,
  25. title: '{!! $title !!}',
  26. area: area,
  27. offset: offset,
  28. maxmin: false,
  29. resize: false,
  30. content: $(_tempId).html(),
  31. success: function(layero, index) {
  32. $(_id).attr('layer', index);
  33. setDataId($(_id));
  34. {!! $events['shown'] !!}
  35. @if(!empty($events['load']))
  36. $(_tb).on('table:loaded', function (event) { {!! $events['load'] !!} });
  37. @endif
  38. setTimeout(function () {
  39. Dcat.grid.AsyncTable({container: _tb});
  40. $(_tb).trigger('table:load');
  41. }, 100);
  42. $(_id).trigger('dialog:shown');
  43. $(_id).on('dialog:open', openDialog);
  44. $(_id).on('dialog:close', closeDialog)
  45. },
  46. cancel: function (index) {
  47. btn && btn.removeAttr('layer');
  48. hidden(index)
  49. }
  50. });
  51. btn && btn.attr('layer', index);
  52. }
  53. function setDataId(obj) {
  54. if (! obj.attr('data-id')) {
  55. obj.attr('data-id', id);
  56. }
  57. }
  58. function setId(val) {
  59. if (! val) return;
  60. id = val;
  61. _id = '#'+id;
  62. _tempId = '#temp-'+id;
  63. _btnId = '#button-'+id;
  64. _tb = _id+' .async-table';
  65. }
  66. function openDialog () {
  67. setId($(this).attr('data-id'));
  68. setDataId($(this));
  69. if (! $(this).attr('layer')) {
  70. open($(this));
  71. }
  72. }
  73. function closeDialog() {
  74. var index = $(this).attr('layer');
  75. $(_id).removeAttr('layer');
  76. $(_btnId).removeAttr('layer');
  77. if (index) {
  78. layer.close(index);
  79. hidden(index);
  80. }
  81. }
  82. $(_btnId).on('click', openDialog);
  83. </script>