dialogtable.blade.php 2.5 KB

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