hasmanytable.blade.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <style>
  2. .table-has-many .input-group{flex-wrap: nowrap!important}
  3. .table-has-many th{vertical-align: middle!important;}
  4. .table-has-many td{vertical-align: middle!important;height: 102px;}
  5. .table-has-many .remove{margin-bottom: 1.5rem}
  6. </style>
  7. <div class="row form-group">
  8. <div class="{{$viewClass['label']}} "><label class="control-label pull-right">{!! $label !!}</label></div>
  9. <div class="{{$viewClass['field']}}">
  10. @include('admin::form.error')
  11. <span name="{{$column}}"></span> {{-- 用于显示错误信息 --}}
  12. <div class="has-many-table-{{$columnClass}}" >
  13. <table class="table table-has-many has-many-table-{{$columnClass}}">
  14. <thead>
  15. <tr>
  16. @foreach($headers as $header)
  17. <th>{{ $header }}</th>
  18. @endforeach
  19. <th class="hidden"></th>
  20. @if($options['allowDelete'])
  21. <th></th>
  22. @endif
  23. </tr>
  24. </thead>
  25. <tbody class="has-many-table-{{$columnClass}}-forms">
  26. @foreach($forms as $pk => $form)
  27. <tr class="has-many-table-{{$columnClass}}-form fields-group">
  28. <?php $hidden = ''; ?>
  29. @foreach($form->fields() as $field)
  30. @if (is_a($field, Dcat\Admin\Form\Field\Hidden::class))
  31. <?php $hidden .= $field->render(); ?>
  32. @continue
  33. @endif
  34. <td>{!! $field->setLabelClass(['hidden'])->width(12, 0)->render() !!}</td>
  35. @endforeach
  36. <td class="hidden">{!! $hidden !!}</td>
  37. @if($options['allowDelete'])
  38. <td class="form-group">
  39. <div>
  40. <div class="remove btn btn-white btn-sm pull-right"><i class="feather icon-trash"></i></div>
  41. </div>
  42. </td>
  43. @endif
  44. </tr>
  45. @endforeach
  46. </tbody>
  47. </table>
  48. <template class="{{$columnClass}}-tpl">
  49. <tr class="has-many-table-{{$columnClass}}-form fields-group">
  50. {!! $template !!}
  51. <td class="form-group">
  52. <div>
  53. <div class="remove btn btn-white btn-sm pull-right"><i class="feather icon-trash"></i></div>
  54. </div>
  55. </td>
  56. </tr>
  57. </template>
  58. @if($options['allowCreate'])
  59. <div class="form-group row m-t-10">
  60. <div class="{{$viewClass['field']}}" style="margin-top: 8px">
  61. <div class="add btn btn-primary btn-outline btn-sm"><i class="feather icon-plus"></i>&nbsp;{{ trans('admin.new') }}</div>
  62. </div>
  63. </div>
  64. @endif
  65. </div>
  66. </div>
  67. </div>
  68. {{--<hr style="margin-top: 0px;">--}}
  69. <script>
  70. (function () {
  71. var nestedIndex = {!! $count !!},
  72. container = '.has-many-table-{{ $columnClass }}';
  73. function replaceNestedFormIndex(value) {
  74. return String(value).replace(/{{ $parentKey ?: Dcat\Admin\Form\NestedForm::DEFAULT_KEY_NAME }}/g, nestedIndex);
  75. }
  76. $(document).off('click', container+' .add').on('click', container+' .add', function (e) {
  77. var $con = $(this).closest(container);
  78. var tpl = $con.find('template.{{ $columnClass }}-tpl');
  79. nestedIndex++;
  80. $con.find('.has-many-table-{{ $columnClass }}-forms').append(replaceNestedFormIndex(tpl.html()));
  81. e.preventDefault();
  82. return false
  83. });
  84. $(document).off('click', container+' .remove').on('click', container+' .remove', function () {
  85. var $form = $(this).closest('.has-many-table-{{ $columnClass }}-form');
  86. $form.hide();
  87. $form.find('[required]').prop('required', false);
  88. $form.find('.{{ Dcat\Admin\Form\NestedForm::REMOVE_FLAG_CLASS }}').val(1);
  89. });
  90. })();
  91. </script>